Skip to content

Commit 3571f63

Browse files
paulinebmPauline
andauthored
feat: add github app authentication instead of comment_bot_token (#643)
Co-authored-by: Pauline <[email protected]>
1 parent 93cf9d0 commit 3571f63

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

.github/workflows/upload_pr_documentation.yml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ on:
1515
secrets:
1616
hf_token:
1717
required: true
18-
comment_bot_token:
19-
required: true
18+
comment_bot_token: #legacy, will be removed in the future
19+
required: false
20+
comment_bot_app_id:
21+
required: false
22+
comment_bot_secret_pem:
23+
required: false
2024

2125
jobs:
2226
upload_pr_documentation:
@@ -101,21 +105,41 @@ jobs:
101105
issue-number: ${{ steps.github-context.outputs.pr_number }}
102106
body-includes: docs for this PR
103107

108+
- name: Determine authentication method
109+
id: auth
110+
run: |
111+
if [[ -n "${{ secrets.comment_bot_token }}" ]]; then
112+
echo "method=comment_bot_token" >> $GITHUB_OUTPUT
113+
elif [[ -n "${{ secrets.comment_bot_app_id }}" ]]; then
114+
echo "method=github_app" >> $GITHUB_OUTPUT
115+
else
116+
echo "No authentication method provided"
117+
exit 1
118+
fi
119+
120+
- name: Create comment_bot token
121+
id: comment_bot_token
122+
if: steps.auth.outputs.method == 'github_app'
123+
uses: actions/create-github-app-token@v2
124+
with:
125+
app-id: ${{ secrets.comment_bot_app_id }}
126+
private-key: ${{ secrets.comment_bot_secret_pem }}
127+
repositories: ${{ github.event.repository.name }}
128+
104129
- name: Add doc comment if not present
105130
uses: thollander/actions-comment-pull-request@v2
106131
if: steps.find_comment.outputs.comment-id == ''
107-
108132
with:
109133
message: 'The docs for this PR live [here](${{ steps.hfhub-context.outputs.hub_docs_url }}). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.'
110134
pr_number: ${{ steps.github-context.outputs.pr_number }}
111-
GITHUB_TOKEN: ${{ secrets.comment_bot_token }}
135+
GITHUB_TOKEN: ${{ steps.auth.outputs.method == 'comment_bot_token' && secrets.comment_bot_token || steps.comment_bot_token.outputs.token }}
112136

113137
- name: Update doc comment if necessary
114138
if: github.event.action == 'reopened' && steps.find_comment.outputs.comment-id != ''
115139
uses: peter-evans/create-or-update-comment@v1
116140
with:
117141
comment-id: ${{ steps.find_comment.outputs.comment-id }}
118-
token: ${{ secrets.comment_bot_token }}
142+
token: ${{ steps.auth.outputs.method == 'comment_bot_token' && secrets.comment_bot_token || steps.comment_bot_token.outputs.token }}
119143
edit-mode: replace
120144
body: |
121145
The docs for this PR live [here](${{ steps.hfhub-context.outputs.hub_docs_url }}). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

0 commit comments

Comments
 (0)