From 801e869b6768a43cb72872974d8aa6a630761652 Mon Sep 17 00:00:00 2001 From: Yih-Dar <2521628+ydshieh@users.noreply.github.com> Date: Mon, 4 Aug 2025 20:20:48 +0200 Subject: [PATCH] send some feedback when manually building doc via comment (#39889) * fix * fix * fix * Update .github/workflows/pr_build_doc_with_comment.yml Co-authored-by: Joao Gante --------- Co-authored-by: ydshieh Co-authored-by: Joao Gante --- .../workflows/pr_build_doc_with_comment.yml | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/.github/workflows/pr_build_doc_with_comment.yml b/.github/workflows/pr_build_doc_with_comment.yml index e3baca7c45..ec43c5b2cf 100644 --- a/.github/workflows/pr_build_doc_with_comment.yml +++ b/.github/workflows/pr_build_doc_with_comment.yml @@ -46,6 +46,49 @@ jobs: exit -1; fi + create_run: + name: Create run + needs: [get-pr-number, get-pr-info] + if: ${{ needs.get-pr-number.outputs.PR_NUMBER != '' }} + permissions: + statuses: write + runs-on: ubuntu-22.04 + steps: + - name: Create Run + id: create_run + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Create a commit status (pending) for a run of this workflow. The status has to be updated later in `update_run_status`. + # See https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#create-a-commit-status + GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + repos/${{ github.repository }}/statuses/${{ needs.get-pr-info.outputs.PR_HEAD_SHA }} \ + -f "target_url=$GITHUB_RUN_URL" -f "state=pending" -f "description=Custom doc building job" -f "context=custom-doc-build" + + reply_to_comment: + name: Reply to the comment + if: ${{ needs.create_run.result == 'success' }} + needs: [get-pr-number, create_run] + permissions: + pull-requests: write + runs-on: ubuntu-22.04 + steps: + - name: Reply to the comment + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + repos/${{ github.repository }}/issues/${{ needs.get-pr-number.outputs.PR_NUMBER }}/comments \ + -f "body=[Building docs for all languages...](${{ env.GITHUB_RUN_URL }})" + build-doc: name: Build doc needs: [get-pr-number, get-pr-info] @@ -56,3 +99,36 @@ jobs: pr_number: ${{ needs.get-pr-number.outputs.PR_NUMBER }} package: transformers languages: ar de en es fr hi it ko pt tr zh ja te + + update_run_status: + name: Update Check Run Status + needs: [ get-pr-info, create_run, build-doc ] + permissions: + statuses: write + if: ${{ always() && needs.create_run.result == 'success' }} + runs-on: ubuntu-22.04 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + STATUS_OK: ${{ contains(fromJSON('["skipped", "success"]'), needs.create_run.result) }} + steps: + - name: Get `build-doc` job status + run: | + echo "${{ needs.build-doc.result }}" + echo $STATUS_OK + if [ "$STATUS_OK" = "true" ]; then + echo "STATUS=success" >> $GITHUB_ENV + else + echo "STATUS=failure" >> $GITHUB_ENV + fi + + - name: Update PR commit statuses + run: | + echo "${{ needs.build-doc.result }}" + echo "${{ env.STATUS }}" + gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + repos/${{ github.repository }}/statuses/${{ needs.get-pr-info.outputs.PR_HEAD_SHA }} \ + -f "target_url=$GITHUB_RUN_URL" -f "state=${{ env.STATUS }}" -f "description=Custom doc building job" -f "context=custom-doc-build"