From 4d8267afc2f45bbbf53e4c2f010ef128dfd765f0 Mon Sep 17 00:00:00 2001 From: Alec Scott Date: Wed, 8 Nov 2023 11:17:00 -0800 Subject: [PATCH] Update CI to limit runs to modified files (#51) * Add hard version limits to track in CI * Rename format.yml to style.yml * Use changes only build docs when they're changed * Add style checks to changes system * Fix typo with style checks * Add permissions scope to changes * Add debug job * Add debug to changes job * Check debug in change job * Remove debug statements --- .github/workflows/ci.yml | 53 ++++++++++++++++++++++++ .github/workflows/docs.yml | 13 ++---- .github/workflows/format.yml | 30 -------------- .github/workflows/requirements/style.txt | 2 + .github/workflows/style.yml | 27 ++++++++++++ 5 files changed, 85 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/format.yml create mode 100644 .github/workflows/requirements/style.txt create mode 100644 .github/workflows/style.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..a9b867ad0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,53 @@ +name: ci +on: + push: + branches: + - develop + pull_request: + branches: + - develop + +concurrency: + group: ci-${{github.ref}}-${{github.event.pull_request.number || github.run_number}} + cancel-in-progress: true + +jobs: + changes: + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + docs: ${{ steps.filter.outputs.docs }} + style: ${{ steps.filter.outputs.style }} + + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # @v2 + if: ${{ github.event_name == 'push' }} + with: + fetch-depth: 0 + + # For pull requests it's not necessary to checkout the code + - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 + id: filter + with: + filters: | + docs: + - '.github/**' + - 'docs/**' + style: + - '.github/**' + - 'bin/**' + - 'configs/**' + - 'docs/conf.py' + - 'experiments/**' + - 'repo/**' + + docs: + if: ${{ needs.changes.outputs.docs == 'true' }} + needs: changes + uses: ./.github/workflows/docs.yml + + style: + if: ${{ needs.changes.outputs.style == 'true' }} + needs: changes + uses: ./.github/workflows/style.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 25ddc417b..d3dce2913 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,15 +1,8 @@ name: Build & Deploy docs site to GitHub Pages on: - push: - branches: - - develop - pull_request: - branches: - - develop - -concurrency: - group: "pages" - cancel-in-progress: true + # This Workflow can be triggered manually + workflow_dispatch: + workflow_call: jobs: build: diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml deleted file mode 100644 index 4682b0a10..000000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Lint - -on: - push: - branches: [ develop ] - pull_request: - branches: [ develop ] - -jobs: - lint: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Set up Python 3.9 - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - - name: Install Python dependencies - run: | - python -m pip install --upgrade pip - pip install black - pip install flake8 - - - name: Lint and Format Check with Flake8 and Black - run: | - black --diff --check . - flake8 diff --git a/.github/workflows/requirements/style.txt b/.github/workflows/requirements/style.txt new file mode 100644 index 000000000..bf324b7a5 --- /dev/null +++ b/.github/workflows/requirements/style.txt @@ -0,0 +1,2 @@ +black==23.10.1 +flake8==6.1.0 diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml new file mode 100644 index 000000000..d00c7af1a --- /dev/null +++ b/.github/workflows/style.yml @@ -0,0 +1,27 @@ +name: Linting & Style Checks +on: + # This Workflow can be triggered manually + workflow_dispatch: + workflow_call: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + + - name: Set up Python 3.11 + uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 + with: + python-version: '3.11' + cache: 'pip' + cache-dependency-path: '.github/workflows/requirements/style.txt' + + - name: Install Python dependencies + run: | + pip install -r .github/workflows/requirements/style.txt + + - name: Lint and Format Check with Flake8 and Black + run: | + black --diff --check . + flake8