Skip to content

Commit 3d13be4

Browse files
committed
github: fix self-hosted runner checkout issues
The unified workflow had two critical issues with repository checkout on self-hosted runners. For pull requests, it attempted to fetch non-existent merge refs like "35/merge". For push events, it used incomplete HTTPS URLs missing the .git suffix. This fixes both by using proper GitHub PR refs (refs/pull/N/head) and complete HTTPS clone URLs with .git suffix for the public repository. Fixes: 1b74004 ("github: unify self-hosted runner workflows") Generated-by: Claude AI Signed-off-by: Daniel Gomez <[email protected]>
1 parent 94c328d commit 3d13be4

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

.github/workflows/kdevops.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,23 +184,37 @@ jobs:
184184
# Repo exists - clean and update (like actions/checkout)
185185
git clean -ffdx
186186
git reset --hard HEAD
187-
# Ensure correct remote URL
188-
git remote set-url origin $GITHUB_SERVER_URL/$GITHUB_REPOSITORY
189-
git fetch --depth=1 origin ${{ github.ref_name }}
190-
git reset --hard FETCH_HEAD
187+
# Ensure correct remote URL for public repo
188+
git remote set-url origin ${{ github.server_url }}/${{ github.repository }}.git
189+
190+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
191+
# For PRs, fetch the specific PR ref that GitHub creates
192+
git fetch --depth=1 origin refs/pull/${{ github.event.number }}/head:pr-branch
193+
git checkout pr-branch
194+
else
195+
# For push/schedule/workflow_dispatch, use the commit SHA directly
196+
git fetch --depth=1 origin ${{ github.sha }}
197+
git checkout ${{ github.sha }}
198+
fi
191199
else
192200
# No repo - fresh clone with local mirror optimization
193201
if [[ -f "/mirror/kdevops.git/HEAD" ]]; then
194202
git clone --verbose --progress \
195203
--reference /mirror/kdevops.git \
196204
--depth=1 \
197-
--branch ${{ github.ref_name }} \
198-
$GITHUB_SERVER_URL/$GITHUB_REPOSITORY .
205+
${{ github.server_url }}/${{ github.repository }}.git .
199206
else
200207
git clone --verbose --progress \
201208
--depth=1 \
202-
--branch ${{ github.ref_name }} \
203-
$GITHUB_SERVER_URL/$GITHUB_REPOSITORY .
209+
${{ github.server_url }}/${{ github.repository }}.git .
210+
fi
211+
212+
# Checkout the specific commit
213+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
214+
git fetch --depth=1 origin refs/pull/${{ github.event.number }}/head:pr-branch
215+
git checkout pr-branch
216+
else
217+
git checkout ${{ github.sha }}
204218
fi
205219
fi
206220

0 commit comments

Comments
 (0)