Skip to content

Commit 7eea99d

Browse files
committed
github actions: handle PRs from forked repos
Detect whether the PR is from a fork and clone from the appropriate source. Use env vars for GitHub context values to avoid script injection. Explicitly name the clone destination to avoid directory mismatch if a fork has a different repo name. Note: the standard checkout action is not used here because the git version in this container is too old.
1 parent b9c9e8c commit 7eea99d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

.github/workflows/build-check_x86_64.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,16 @@ jobs:
2727
yum install bc dwarves git glibc-devel hostname kernel-devel mpfr openssl openssl-devel elfutils-libelf-devel -y
2828
2929
- name: Checkout code
30+
env:
31+
HEAD_REF: ${{ github.head_ref }}
32+
PR_CLONE_URL: ${{ github.event.pull_request.head.repo.clone_url }}
33+
PR_REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }}
3034
run: |
31-
git clone --branch ${{ github.head_ref }} "https://oauth2:$GITHUB_TOKEN@github.com/ctrliq/kernel-src-tree"
35+
if [ "$PR_REPO_FULL_NAME" = "ctrliq/kernel-src-tree" ]; then
36+
git clone --branch "$HEAD_REF" "https://oauth2:${GITHUB_TOKEN}@github.com/ctrliq/kernel-src-tree" kernel-src-tree
37+
else
38+
git clone --branch "$HEAD_REF" "$PR_CLONE_URL" kernel-src-tree
39+
fi
3240
3341
- name: Build the Kernel
3442
working-directory: kernel-src-tree

0 commit comments

Comments
 (0)