Skip to content

Commit cbc4daa

Browse files
committed
Use a PAT for the github api calls
The action's token ${{ secrets.GITHUB_TOKEN }} is not allowed to write a comment on the PR or similar, if the PR's source branch is on a fork of the base branch's repo. So we need to use a personal access token instead.
1 parent a51ee27 commit cbc4daa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

.github/workflows/fuzzy-ci.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ env:
3333
GH_API_COMMENTS: ${{ github.event.pull_request.comments_url }}
3434
GH_API_LABELS: ${{ github.event.pull_request.issue_url }}/labels
3535
GH_API_ARTIFACTS: ${{ github.event.pull_request.base.repo.url }}/actions/artifacts
36-
TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
TOKEN: ${{ secrets.MERLINOIS_PAT }}
3737

3838
# URL short-hands
3939
ACTIONS_RUNS_ENDPOINT: ${{ github.event.repository.html_url }}/actions/runs
@@ -293,8 +293,6 @@ jobs:
293293
name: Evaluate diffs
294294
runs-on: ubuntu-22.04
295295
needs: diff
296-
permissions:
297-
pull-requests: write
298296
env:
299297
earlier_diff_was_approved: ${{ contains(github.event.pull_request.labels.*.name, 'fuzzy-diff-looks-good') }}
300298
current_diff_exists: ${{ needs.diff.outputs.diff_exits }}
@@ -345,6 +343,11 @@ jobs:
345343
Previous sha256: ${{ steps.approved_diff_info.outputs.hash }}\n\
346344
Current sha256: $current_diff_hash"
347345
status=$(curl -sL -w "%{http_code}" -o output.txt -X DELETE -H "Authorization: Bearer $TOKEN" "$GH_API_LABELS/$LABEL_NAME")
346+
if [ "$status" -ne 200 ]; then
347+
echo "Something went wrong trying to remove the $LABEL_NAME label. Please, remove it manually."
348+
cat output.txt
349+
fi
350+
exit 2
348351
fi
349352
else
350353
if $current_diff_exists; then
@@ -366,8 +369,6 @@ jobs:
366369
github.event.action == 'labeled' &&
367370
github.event.label.name == 'fuzzy-diff-looks-good'
368371
runs-on: ubuntu-22.04
369-
permissions:
370-
pull-requests: write
371372
steps:
372373
- name: Retreive diff artifact meta-data
373374
id: diff_metadata
@@ -383,10 +384,13 @@ jobs:
383384
env:
384385
id: ${{ steps.diff_metadata.outputs.id }}
385386
run: |
386-
# FIXME (?)
387387
if [ -z $id ]; then
388388
printf "You seem to have tried to approve a diff that doesn't exist yet.\nWait for the diff to have been generated and then try again."
389389
status=$(curl -sL -w "%{http_code}" -o output.txt -X DELETE -H "Authorization: Bearer $TOKEN" "$GH_API_LABELS/$LABEL_NAME")
390+
if [ "$status" -ne 200 ]; then
391+
echo "Something went wrong trying to remove the $LABEL_NAME label. Please, remove it manually."
392+
cat output.txt
393+
fi
390394
exit 1
391395
else
392396
echo "Diff has been approved."
@@ -397,7 +401,7 @@ jobs:
397401
id: ${{ steps.diff_metadata.outputs.id }}
398402
run: |
399403
# Doing this manually, since actions/download-artifact only works on the same workflow run on which the artifact was uploaded
400-
curl -sSLO -H "Authorization: Bearer $TOKEN" "$GH_API_ARTIFACTS/$id/zip" -D headers.txt
404+
curl -sSLO -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$GH_API_ARTIFACTS/$id/zip" -D headers.txt
401405
402406
- name: Unzip downloaded diff
403407
run: |

0 commit comments

Comments
 (0)