Skip to content

Github Actions Run on Changed Files Only

Resources

${{github.sha}} is the SHA of the commit that triggered a workflow when the trigger type is push. (This is not the case when the trigger action is pull_request, more here.

git-diff-tree is used to find the changed files.

name: Code Style
on:
  push:
jobs:
  build:
    name: Code Style Checks
    runs-on: ubuntu-latest
    steps:
      - name: Checkout commit
        uses: actions/checkout@v2.3.4
        with:
          fetch-depth: 2
      - uses: actions/cache@v2
        with:
          path: ~/.cache/pip
    @@ -18,7 +20,13 @@ jobs:
          python-version: 3.8
      - name: Install pip requirements-dev
        run: pip install -r requirements-dev.txt
      - name: Imports
        run: python -m isort --check-only .
      - name: Formatting
        run: python -m black --check .
      - name: Linting
        id: changes
        run: |
          if [[ $(git diff-tree --no-commit-id --name-only --diff-filter=ACMRT -r ${{ github.sha }} -- '*.py' | xargs) ]]; then
          python -m flake8 $(git diff-tree --no-commit-id --name-only --diff-filter=ACMRT -r "$GITHUB_SHA" -- '*.py' | xargs)
          fi