|
15 | 15 | secrets: |
16 | 16 | hf_token: |
17 | 17 | 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 |
20 | 24 |
|
21 | 25 | jobs: |
22 | 26 | upload_pr_documentation: |
@@ -101,21 +105,41 @@ jobs: |
101 | 105 | issue-number: ${{ steps.github-context.outputs.pr_number }} |
102 | 106 | body-includes: docs for this PR |
103 | 107 |
|
| 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 | + |
104 | 129 | - name: Add doc comment if not present |
105 | 130 | uses: thollander/actions-comment-pull-request@v2 |
106 | 131 | if: steps.find_comment.outputs.comment-id == '' |
107 | | - |
108 | 132 | with: |
109 | 133 | 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.' |
110 | 134 | 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 }} |
112 | 136 |
|
113 | 137 | - name: Update doc comment if necessary |
114 | 138 | if: github.event.action == 'reopened' && steps.find_comment.outputs.comment-id != '' |
115 | 139 | uses: peter-evans/create-or-update-comment@v1 |
116 | 140 | with: |
117 | 141 | 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 }} |
119 | 143 | edit-mode: replace |
120 | 144 | body: | |
121 | 145 | 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