Skip to content

Commit 6bd0fa1

Browse files
committed
Fix uptest trigger workflow
1 parent e77d5c6 commit 6bd0fa1

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

.github/workflows/uptest-trigger.yaml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,35 @@ on:
99
types: [created]
1010

1111
env:
12-
GO_VERSION: "1.22.12"
12+
GO_VERSION: "1.23.6"
1313

1414
jobs:
15-
debug:
15+
check-permissions:
1616
runs-on: ubuntu-latest
17+
outputs:
18+
permission: ${{ steps.check-permissions.outputs.permission }}
1719
steps:
18-
- name: Debug
20+
- name: Get Commenter Permissions
21+
id: check-permissions
1922
run: |
2023
echo "Trigger keyword: '/test-examples'"
2124
echo "Go version: ${{ env.GO_VERSION }}"
22-
echo "github.event.comment.author_association: ${{ github.event.comment.author_association }}"
25+
26+
REPO=${{ github.repository }}
27+
COMMENTER=${{ github.event.comment.user.login }}
28+
29+
# Fetch the commenter's repo-level permission grant
30+
GRANTED=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
31+
-H "Accept: application/vnd.github.v3+json" \
32+
"https://api.github.com/repos/$REPO/collaborators/$COMMENTER/permission" | jq -r .permission)
33+
34+
# Make it accessible in the workflow via a job output -- cannot use env
35+
echo "User $COMMENTER has $GRANTED permissions"
36+
echo "permission=$GRANTED" >> "$GITHUB_OUTPUT"
2337
2438
get-example-list:
25-
if: ${{ (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' ) &&
26-
github.event.issue.pull_request &&
27-
contains(github.event.comment.body, '/test-examples' ) }}
39+
needs: check-permissions
40+
if: ${{ (needs.check-permissions.outputs.permission == 'admin' || needs.check-permissions.outputs.permission == 'write') && github.event.issue.pull_request != null && contains(github.event.comment.body, '/test-examples')}}
2841
runs-on: ubuntu-latest
2942
outputs:
3043
example_list: ${{ steps.get-example-list-name.outputs.example-list }}
@@ -79,12 +92,11 @@ jobs:
7992
-f context="Uptest-${{ steps.get-example-list-name.outputs.example-hash }}"
8093
8194
uptest:
82-
if: ${{ (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' ) &&
83-
github.event.issue.pull_request &&
84-
contains(github.event.comment.body, '/test-examples' ) }}
95+
needs:
96+
- check-permissions
97+
- get-example-list
98+
if: ${{ (needs.check-permissions.outputs.permission == 'admin' || needs.check-permissions.outputs.permission == 'write') && github.event.issue.pull_request != null && contains(github.event.comment.body, '/test-examples')}}
8599
runs-on: ubuntu-latest
86-
needs: get-example-list
87-
88100
steps:
89101
- name: Cleanup Disk
90102
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
@@ -177,4 +189,4 @@ jobs:
177189
-f state='failure' \
178190
-f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
179191
-f description='Failed' \
180-
-f context="Uptest-${EXAMPLE_HASH}"
192+
-f context="Uptest-${EXAMPLE_HASH}"

0 commit comments

Comments
 (0)