Skip to content

Commit 80db967

Browse files
authored
Fix CI checkout and coverage upload for fork PRs (#737)
1 parent 213e574 commit 80db967

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ jobs:
1818
- name: Checkout
1919
uses: actions/checkout@v4
2020
with:
21-
ref: ${{ github.head_ref || github.ref }}
21+
# PR builds (including forks) check out the PR head from its source repo;
22+
# push builds fall back to the pushed ref on this repo. Without the
23+
# repository override, fork-PR checkouts look for the head branch in the
24+
# base repo and fail with "a branch or tag ... could not be found".
25+
# Use the branch name (not the head SHA) so HEAD stays attached to a
26+
# branch — the KMMBridge plugin runs `git pull --tags`, which fails on a
27+
# detached HEAD with "you are not currently on a branch".
28+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
29+
ref: ${{ github.event.pull_request.head.ref || github.ref }}
2230
fetch-depth: 0
2331
persist-credentials: false
2432

@@ -38,6 +46,10 @@ jobs:
3846
run: ./gradlew clean build koverXmlReport --stacktrace
3947

4048
- name: Upload Coverage to Codecov
49+
# Secrets (including CODECOV_TOKEN) are not exposed to fork PRs, so the
50+
# upload would fail under fail_ci_if_error. Skip it for forks; coverage is
51+
# still uploaded and enforced for same-repo PRs and pushes to main.
52+
if: ${{ github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request' }}
4153
uses: codecov/codecov-action@v4
4254
with:
4355
token: ${{ secrets.CODECOV_TOKEN }}

0 commit comments

Comments
 (0)