diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 676672c1..7dbca144 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,10 @@ on: pull_request: workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: bootstrap: runs-on: ubuntu-latest diff --git a/{{ cookiecutter.name }}/.github/workflows/ci.yml b/{{ cookiecutter.name }}/.github/workflows/ci.yml index e93e12a9..ba04a51a 100644 --- a/{{ cookiecutter.name }}/.github/workflows/ci.yml +++ b/{{ cookiecutter.name }}/.github/workflows/ci.yml @@ -7,14 +7,39 @@ on: - main pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: lint: runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + outputs: + image-build-affected: ${{ steps.image-build-affected.outputs.result }} steps: - name: checkout uses: actions/checkout@v4 + - name: Check whether the pull request can affect the image build + id: image-build-affected + if: github.event_name == 'pull_request' + env: + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ github.event.pull_request.number }} + REPO: ${{ github.repository }} + run: | + set -euo pipefail + changed=$(gh api --paginate "/repos/$REPO/pulls/$PR_NUMBER/files" --jq '.[].filename') + if grep -qxE 'Dockerfile|uv\.lock|pyproject\.toml|\.dockerignore' <<< "$changed"; then + echo "result=true" >> "$GITHUB_OUTPUT" + else + echo "result=false" >> "$GITHUB_OUTPUT" + fi + - name: setup project id: setup-project uses: ./.github/actions/setup-project @@ -67,7 +92,8 @@ jobs: run: make test build-docker-image: - needs: test + needs: [lint, test] + if: github.event_name != 'pull_request' || needs.lint.outputs.image-build-affected == 'true' runs-on: ubuntu-latest steps: