Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up migrations linting in CI #160

Open
0x962 opened this issue Aug 23, 2021 · 5 comments
Open

Speed up migrations linting in CI #160

0x962 opened this issue Aug 23, 2021 · 5 comments

Comments

@0x962
Copy link

0x962 commented Aug 23, 2021

We're running django-migrations-linter as part of our CI, it's a great tool, thank you!

Do you have any recommendations on speeding up this step when using Github actions?

I did notice the --git-commit-id parameter, but was unable to make it work using the github.event.pull_request.sha variable. (Raises a diff error)

@David-Wobrock
Copy link
Collaborator

Hi @0x962

Thanks for submitting an issue.

A good way to improve speed is indeed to only lint newly added migrations. This can be done in multiple ways:

  • --git-commit-id, if it doesn't work, maybe you can run the lintmigrations command with some verbosity options to debug a bit and submit another issue to see if the issue comes from the linter itself
  • --include-migrations-from FILE_PATH you can provider a file, that contains one migration per line. And the linter will only consider those migrations.

The linter also writes a little cache, which is mostly leveraged on your local environment. I don't think GitHub Actions has some persistence to keep the cache from one run to the next 🤔

@blueyed
Copy link
Contributor

blueyed commented Sep 8, 2021

@David-Wobrock

The linter also writes a little cache, which is mostly leveraged on your local environment. I don't think GitHub Actions has some persistence to keep the cache from one run to the next thinking

GitHub actions supports caching in general.

@0x962
The cache should be at ~/.cache/django-migration-linter.
But then it is also unclear how good cache invalidation works / if it might cause any problems, of course.

@David-Wobrock
Copy link
Collaborator

Hi @blueyed

Good to know for GH Actions, thanks!

The linter cache uses a hash of the file's content as key (see https://github.com/3YOURMIND/django-migration-linter/blob/main/django_migration_linter/migration_linter.py#L213) and stores the linting result as value for each file. Then, the cache is expectedly depend of the selected Django project, database and the linter's version.
The goal is to avoid generating the SQL statements and running the linting rules.

@0x962
Copy link
Author

0x962 commented Sep 13, 2021

Thank you for your comments, @blueyed and @David-Wobrock.

For other people who stumble upon this thread and use this amazing tool, this is my Github actions implementation. ( The relevant steps )

      - name: Caches django migrations linter
        uses: actions/cache@v2
        with:
          path: |
            $HOME/.cache/django-migration-linter
          key: ${{ runner.os }}-migrations-linter-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-migrations-linter-${{ github.sha }}
            ${{ runner.os }}-migrations-linter-
            ${{ runner.os }}-

      - name: Run Migrations Linter
        run: MIGRATE=True python manage.py lintmigrations

@David-Wobrock
Copy link
Collaborator

[...] and use this amazing tool [...]

🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants