Skip to content

Commit b00cbbf

Browse files
committed
ci: Fix pull request checkout
The commit 2fc95f5 modified the CI workflow to use the `pull_request_target` trigger for the pull request runs. The `pull_request_target` action runs in the context of the target branch and the GitHub `checkout` action will check out the target branch commit by default, thereby not building the actual changes in the pull request branch. This commit updates the `checkout` action to check out the pull request head commit when running in the context of `pull_request_target`. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 6eb1080 commit b00cbbf

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,20 @@ jobs:
7777

7878
steps:
7979
- name: Check out source code
80+
if: ${{ github.event_name != 'pull_request_target' }}
8081
uses: actions/checkout@v2
8182
with:
8283
fetch-depth: 0
8384
persist-credentials: false
8485

86+
- name: Check out source code (pull request)
87+
if: ${{ github.event_name == 'pull_request_target' }}
88+
uses: actions/checkout@v2
89+
with:
90+
ref: ${{ github.event.pull_request.head.sha }}
91+
fetch-depth: 0
92+
persist-credentials: false
93+
8594
- name: Generate version file
8695
run: |
8796
VERSION=$(git describe --tags --match 'v*')
@@ -484,8 +493,17 @@ jobs:
484493
echo "WORKSPACE=${WORKSPACE}" >> $GITHUB_ENV
485494
486495
- name: Check out source code
496+
if: ${{ github.event_name != 'pull_request_target' }}
497+
uses: actions/checkout@v2
498+
with:
499+
submodules: recursive
500+
persist-credentials: false
501+
502+
- name: Check out source code (pull request)
503+
if: ${{ github.event_name == 'pull_request_target' }}
487504
uses: actions/checkout@v2
488505
with:
506+
ref: ${{ github.event.pull_request.head.sha }}
489507
submodules: recursive
490508
persist-credentials: false
491509

@@ -791,8 +809,17 @@ jobs:
791809
echo "TAR=gtar" >> $GITHUB_ENV
792810
793811
- name: Check out source code
812+
if: ${{ github.event_name != 'pull_request_target' }}
813+
uses: actions/checkout@v2
814+
with:
815+
submodules: recursive
816+
persist-credentials: false
817+
818+
- name: Check out source code (pull request)
819+
if: ${{ github.event_name == 'pull_request_target' }}
794820
uses: actions/checkout@v2
795821
with:
822+
ref: ${{ github.event.pull_request.head.sha }}
796823
submodules: recursive
797824
persist-credentials: false
798825

@@ -931,8 +958,16 @@ jobs:
931958
echo "TAR=gtar" >> $GITHUB_ENV
932959
933960
- name: Check out source code
961+
if: ${{ github.event_name != 'pull_request_target' }}
962+
uses: actions/checkout@v2
963+
with:
964+
persist-credentials: false
965+
966+
- name: Check out source code (pull request)
967+
if: ${{ github.event_name == 'pull_request_target' }}
934968
uses: actions/checkout@v2
935969
with:
970+
ref: ${{ github.event.pull_request.head.sha }}
936971
persist-credentials: false
937972

938973
- name: Build CMake package
@@ -1012,8 +1047,17 @@ jobs:
10121047
echo "TAR=gtar" >> $GITHUB_ENV
10131048
10141049
- name: Check out source code
1050+
if: ${{ github.event_name != 'pull_request_target' }}
1051+
uses: actions/checkout@v2
1052+
with:
1053+
path: repository
1054+
persist-credentials: false
1055+
1056+
- name: Check out source code (pull request)
1057+
if: ${{ github.event_name == 'pull_request_target' }}
10151058
uses: actions/checkout@v2
10161059
with:
1060+
ref: ${{ github.event.pull_request.head.sha }}
10171061
path: repository
10181062
persist-credentials: false
10191063

0 commit comments

Comments
 (0)