Skip to content

Commit 562e16c

Browse files
fix: run the app-ci path filter on pull requests only (#1)
dorny/paths-filter uses the GitHub API on a pull_request event, but on a push it has to diff against github.event.before with git. That commit is not in the changes job's default depth-1 checkout, so it fetches it — and the checkout persists no credential (zizmor requires that), so on a private repository the fetch dies with "could not read Username for 'https://github.com'". Every push to main after the first one therefore failed the changes job, which skipped ci and commitlint: the merge gate existed on pull requests only. The first push to a branch survived just because github.event.before is the all-zero sha there. Gate build-filters and the filter on github.event_name == 'pull_request' and fall the job's roots output back to inputs.roots otherwise. The filter is a pull-request time saver — most roots are untouched there — while on the default branch every root should be verified anyway, so the non-pull-request branch wants the full list regardless. Both branches emit a JSON array string, so fromJSON and the ci job's != '[]' guard keep working, no fetch-depth change is needed, and persist-credentials: false stays. Claude-Session: https://claude.ai/code/session_01J4HB8qJjdZwaAv42k6HMpv Co-authored-by: iam-truongtrungnghia <nghia.truong@tpssoft.com>
1 parent 3e2874f commit 562e16c

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎.github/workflows/app-ci.yml‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ jobs:
1616
contents: read
1717
pull-requests: read
1818
outputs:
19-
roots: ${{ steps.filter.outputs.changes }}
19+
# the filter only runs on a pull request, so on every other event this
20+
# falls back to the full input: a push to the default branch is exactly
21+
# where every root should be verified, not a subset. that also keeps
22+
# paths-filter away from `git`, which it needs on a push (it diffs
23+
# against github.event.before, a commit a depth-1 checkout does not
24+
# have) and cannot use, because the checkout persists no credential
25+
# for it to fetch that commit with on a private repository.
26+
roots: ${{ steps.filter.outputs.changes || inputs.roots }}
2027
steps:
2128
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2229
with:
2330
persist-credentials: false
24-
- id: build-filters
31+
# the filter is a pull-request time saver: most roots are untouched
32+
# there. on any other event the job outputs inputs.roots unchanged.
33+
- if: github.event_name == 'pull_request'
34+
id: build-filters
2535
env:
2636
ROOTS: ${{ inputs.roots }}
2737
# a root is dirty when its own directory, a lockfile, or the root
@@ -30,7 +40,8 @@ jobs:
3040
echo "$ROOTS" \
3141
| jq -r '.[] | "\(.):\n - \(.)/**\n - mise.toml\n - \"*.lock*\""' \
3242
> "${RUNNER_TEMP}/filters.yml"
33-
- id: filter
43+
- if: github.event_name == 'pull_request'
44+
id: filter
3445
uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
3546
with:
3647
filters: ${{ runner.temp }}/filters.yml

0 commit comments

Comments
 (0)