|
1 | | -name: PR - build doc via comment |
2 | | -on: |
3 | | - issue_comment: |
4 | | - types: |
5 | | - - created |
6 | | - branches-ignore: |
7 | | - - main |
8 | | -concurrency: |
9 | | - group: ${{ github.workflow }}-${{ github.event.issue.number }}-${{ startsWith(github.event.comment.body, 'build-doc') }} |
10 | | - cancel-in-progress: true |
11 | | -permissions: {} |
12 | 1 |
|
13 | | - |
14 | | -jobs: |
15 | | - get-pr-number: |
16 | | - name: Get PR number |
17 | | - if: ${{ github.event.issue.state == 'open' && contains(fromJSON('["ydshieh", "ArthurZucker", "zucchini-nlp", "qubvel", "molbap", "gante", "LysandreJik", "Cyrilvallez", "Rocketknight1", "SunMarc", "muellerzr", "eustlb", "MekkCyber", "manueldeprada", "vasqu", "ivarflakstad", "stevhliu", "ebezzam"]'), github.actor) && (startsWith(github.event.comment.body, 'build-doc')) }} |
18 | | - uses: ./.github/workflows/get-pr-number.yml |
19 | | - |
20 | | - get-pr-info: |
21 | | - name: Get PR commit SHA |
22 | | - needs: get-pr-number |
23 | | - if: ${{ needs.get-pr-number.outputs.PR_NUMBER != ''}} |
24 | | - uses: ./.github/workflows/get-pr-info.yml |
25 | | - with: |
26 | | - pr_number: ${{ needs.get-pr-number.outputs.PR_NUMBER }} |
27 | | - |
28 | | - verity_pr_commit: |
29 | | - name: Verity PR commit corresponds to a specific event by comparing timestamps |
30 | | - if: ${{ needs.get-pr-number.outputs.PR_NUMBER != ''}} |
31 | | - runs-on: ubuntu-22.04 |
32 | | - needs: get-pr-info |
33 | | - env: |
34 | | - COMMENT_DATE: ${{ github.event.comment.created_at }} |
35 | | - PR_MERGE_COMMIT_DATE: ${{ needs.get-pr-info.outputs.PR_MERGE_COMMIT_DATE }} |
36 | | - PR_MERGE_COMMIT_TIMESTAMP: ${{ needs.get-pr-info.outputs.PR_MERGE_COMMIT_TIMESTAMP }} |
37 | | - steps: |
38 | | - - run: | |
39 | | - COMMENT_TIMESTAMP=$(date -d "${COMMENT_DATE}" +"%s") |
40 | | - echo "COMMENT_DATE: $COMMENT_DATE" |
41 | | - echo "PR_MERGE_COMMIT_DATE: $PR_MERGE_COMMIT_DATE" |
42 | | - echo "COMMENT_TIMESTAMP: $COMMENT_TIMESTAMP" |
43 | | - echo "PR_MERGE_COMMIT_TIMESTAMP: $PR_MERGE_COMMIT_TIMESTAMP" |
44 | | - if [ $COMMENT_TIMESTAMP -le $PR_MERGE_COMMIT_TIMESTAMP ]; then |
45 | | - echo "Last commit on the pull request is newer than the issue comment triggering this run! Abort!"; |
46 | | - exit -1; |
47 | | - fi |
48 | | -
|
49 | | - create_run: |
50 | | - name: Create run |
51 | | - needs: [get-pr-number, get-pr-info] |
52 | | - if: ${{ needs.get-pr-number.outputs.PR_NUMBER != '' }} |
53 | | - permissions: |
54 | | - statuses: write |
55 | | - runs-on: ubuntu-22.04 |
56 | | - steps: |
57 | | - - name: Create Run |
58 | | - id: create_run |
59 | | - env: |
60 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
61 | | - # Create a commit status (pending) for a run of this workflow. The status has to be updated later in `update_run_status`. |
62 | | - # See https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#create-a-commit-status |
63 | | - GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
64 | | - run: | |
65 | | - gh api \ |
66 | | - --method POST \ |
67 | | - -H "Accept: application/vnd.github+json" \ |
68 | | - -H "X-GitHub-Api-Version: 2022-11-28" \ |
69 | | - repos/${{ github.repository }}/statuses/${{ needs.get-pr-info.outputs.PR_HEAD_SHA }} \ |
70 | | - -f "target_url=$GITHUB_RUN_URL" -f "state=pending" -f "description=Custom doc building job" -f "context=custom-doc-build" |
71 | | -
|
72 | | - reply_to_comment: |
73 | | - name: Reply to the comment |
74 | | - if: ${{ needs.create_run.result == 'success' }} |
75 | | - needs: [get-pr-number, create_run] |
76 | | - permissions: |
77 | | - pull-requests: write |
78 | | - runs-on: ubuntu-22.04 |
79 | | - steps: |
80 | | - - name: Reply to the comment |
81 | | - env: |
82 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
83 | | - GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
84 | | - run: | |
85 | | - gh api \ |
86 | | - --method POST \ |
87 | | - -H "Accept: application/vnd.github+json" \ |
88 | | - -H "X-GitHub-Api-Version: 2022-11-28" \ |
89 | | - repos/${{ github.repository }}/issues/${{ needs.get-pr-number.outputs.PR_NUMBER }}/comments \ |
90 | | - -f "body=[Building doc for all language ...](${{ env.GITHUB_RUN_URL }})" |
91 | | -
|
92 | | - build-doc: |
93 | | - name: Build doc |
94 | | - needs: [get-pr-number, get-pr-info] |
95 | | - if: ${{ needs.get-pr-number.outputs.PR_NUMBER != '' }} |
96 | | - uses: huggingface/doc-builder/.github/workflows/build_pr_documentation.yml@main |
97 | | - with: |
98 | | - commit_sha: ${{ needs.get-pr-info.outputs.PR_HEAD_SHA }} |
99 | | - pr_number: ${{ needs.get-pr-number.outputs.PR_NUMBER }} |
100 | | - package: transformers |
101 | | - languages: fr |
102 | | - |
103 | | - update_run_status: |
104 | | - name: Update Check Run Status |
105 | | - needs: [ get-pr-info, create_run, build-doc ] |
106 | | - permissions: |
107 | | - statuses: write |
108 | | - if: ${{ always() && needs.create_run.result == 'success' }} |
109 | | - runs-on: ubuntu-22.04 |
110 | | - env: |
111 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
112 | | - GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
113 | | - STATUS_OK: ${{ contains(fromJSON('["skipped", "success"]'), needs.create_run.result) }} |
114 | | - steps: |
115 | | - - name: Get `build-doc` job status |
116 | | - run: | |
117 | | - echo "${{ needs.build-doc.result }}" |
118 | | - echo $STATUS_OK |
119 | | - if [ "$STATUS_OK" = "true" ]; then |
120 | | - echo "STATUS=success" >> $GITHUB_ENV |
121 | | - else |
122 | | - echo "STATUS=failure" >> $GITHUB_ENV |
123 | | - fi |
124 | | -
|
125 | | - - name: Update PR commit statuses |
126 | | - run: | |
127 | | - echo "${{ needs.build-doc.result }}" |
128 | | - echo "${{ env.STATUS }}" |
129 | | - gh api \ |
130 | | - --method POST \ |
131 | | - -H "Accept: application/vnd.github+json" \ |
132 | | - -H "X-GitHub-Api-Version: 2022-11-28" \ |
133 | | - repos/${{ github.repository }}/statuses/${{ needs.get-pr-info.outputs.PR_HEAD_SHA }} \ |
134 | | - -f "target_url=$GITHUB_RUN_URL" -f "state=${{ env.STATUS }}" -f "description=Custom doc building job" -f "context=custom-doc-build" |
0 commit comments