From 3395eed72230b35bd4907c7ee8ea240682e2d8ed Mon Sep 17 00:00:00 2001 From: Aaron Sulwer Date: Wed, 21 Oct 2026 12:40:06 -0700 Subject: [PATCH] Skip the build and tests for PRs that don't change the app A first job lists the PR's changed files. When none of them is something the app or its tests are built from, the Tests and Android Release build jobs are skipped, which branch protection counts as passed. Closes #21 Co-Authored-By: Claude Opus 5.5 --- .github/workflows/build-test.yml | 37 +++++++++++++++++++++++++++++++- BUILD.md | 4 +++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 3056fe1..723bf58 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -1,4 +1,4 @@ -# Builds and tests every pull request to master, so a broken build, a failing test or a forgotten EF +# Builds and tests pull requests to master, so a broken build, a failing test or a forgotten EF # migration (CallGuard.Tests checks the model against the migrations) shows up before merging. Needs no # secrets and never publishes anything. (Pushes to master are tested by the release workflow.) # @@ -6,6 +6,11 @@ # tests runs CallGuard.Tests (about 1 minute) # android builds the app in Release, signed with the default debug key, so Release-only problems # such as trimming show up here rather than in the release workflow (about 6 minutes) +# +# Both are skipped when the PR changes nothing the app is built from (docs, README, LICENSE, the release +# workflow, Dependabot's settings...), so such a PR can be merged right away: master's branch protection +# requires these two checks, and GitHub counts a skipped job as passed. The workflow itself always runs, +# because a required check whose whole workflow is filtered out by path would wait forever. name: Build and test @@ -21,14 +26,42 @@ concurrency: permissions: contents: read + pull-requests: read # list the PR's changed files env: DOTNET_NOLOGO: true DOTNET_CLI_TELEMETRY_OPTOUT: true jobs: + changes: + name: Needs a build? + runs-on: ubuntu-26.04 + timeout-minutes: 5 + outputs: + build: ${{ steps.check.outputs.build }} + steps: + - id: check + env: + GH_TOKEN: ${{ github.token }} + PR: ${{ github.event.pull_request.number }} + shell: bash + run: | + # "Run workflow" by hand always builds. + if [ -z "$PR" ]; then echo "build=true" >> "$GITHUB_OUTPUT"; exit 0; fi + files=$(gh pr diff "$PR" --name-only --repo "$GITHUB_REPOSITORY") + echo "$files" + # What the app and its tests are built from, plus this workflow so changes to it get tried out. + if echo "$files" | grep -qE '^(CallGuard[^/]*/|[^/]*\.slnx$|Directory\.(Packages|Build)\.(props|targets)$|global\.json$|dotnet-tools\.json$|[Nn]u[Gg]et\.config$|\.github/workflows/build-test\.yml$)'; then + echo "build=true" >> "$GITHUB_OUTPUT" + else + echo "Nothing the app is built from changed; skipping the build and tests." + echo "build=false" >> "$GITHUB_OUTPUT" + fi + tests: name: Tests + needs: changes + if: needs.changes.outputs.build == 'true' runs-on: ubuntu-26.04 timeout-minutes: 20 @@ -54,6 +87,8 @@ jobs: android: name: Android Release build + needs: changes + if: needs.changes.outputs.build == 'true' runs-on: ubuntu-26.04 timeout-minutes: 45 diff --git a/BUILD.md b/BUILD.md index 6765e9e..125a45f 100644 --- a/BUILD.md +++ b/BUILD.md @@ -123,4 +123,6 @@ call — and remembers the schema version, so later starts skip the check. ## Continuous integration Every pull request to `master` runs **Build and test** (`.github/workflows/build-test.yml`): the unit tests -and a Release build of the app, signed with the debug key. +and a Release build of the app, signed with the debug key. Both are skipped (and count as passed) when the +pull request changes nothing the app is built from — only docs, the README, the license, the release +workflow or Dependabot's settings — so such a pull request can be merged straight away.