|
1 | | -# Run the regeneration when a comment is made on a PR that contains the text "/regenerate". |
2 | | -# Draws from a very useful blog article: https://grem1.in/post/gha-comment-trigger/ |
| 1 | +# Regenerate the sample data via a manual trigger |
3 | 2 |
|
4 | 3 | name: PR comment handling |
5 | 4 | on: |
6 | | - issue_comment: |
7 | | - types: |
8 | | - - created |
| 5 | + workflow_dispatch: |
9 | 6 |
|
10 | 7 | jobs: |
11 | 8 | regenerate: |
12 | 9 | name: Regenerate sample data |
13 | 10 | runs-on: self-hosted |
14 | | - if: ${{ github.event.issue.pull_request && github.event.comment.body == '/regenerate' }} |
| 11 | + if: github.repository == 'Climate-REF/ref-sample-data' |
15 | 12 | permissions: |
16 | 13 | contents: read |
17 | | - pull-requests: write |
18 | 14 | steps: |
19 | | - - name: Put a reaction to the comment |
20 | | - run: gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" |
21 | | - env: |
22 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
23 | | - NODE_ID: ${{ github.event.comment.node_id }} |
24 | | - |
25 | | - - name: Check if PR is open |
26 | | - run: | |
27 | | - STATE=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json state --jq .state) |
28 | | - if [ "$STATE" != "OPEN" ]; then |
29 | | - echo "Cannot build for closed PRs" |
30 | | - ( |
31 | | - echo "**${{ github.workflow }}**" |
32 | | - echo "Cannot build regenerate the smaple data for a closed PR." |
33 | | - ) | \ |
34 | | - gh pr comment "${PR_NUMBER}" --repo ${{ github.repository }} -F - |
35 | | - gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:THUMBS_DOWN}){reaction{content}subject{id}}}" |
36 | | - gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" |
37 | | - exit 1 |
38 | | - fi |
39 | | - env: |
40 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
41 | | - PR_NUMBER: ${{ github.event.issue.number }} |
42 | | - NODE_ID: ${{ github.event.comment.node_id }} |
43 | | - |
44 | | - - name: Get PR HEAD branch and repository |
45 | | - id: getRepository |
46 | | - # This gets the PR's head ref name (aka branch) |
47 | | - # We can't use the SHA or the default because of how this workflow is triggered |
48 | | - run: | |
49 | | - echo "pr_branch=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT |
50 | | - echo "owner=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRepositoryOwner | jq -r '.headRepositoryOwner.login')" >> $GITHUB_OUTPUT |
51 | | - echo "repository=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRepository | jq -r '.headRepository.name')" >> $GITHUB_OUTPUT |
52 | | - env: |
53 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
54 | | - PR_NUMBER: ${{ github.event.issue.number }} |
55 | | - |
56 | 15 | - name: Checkout source code from Github |
57 | 16 | uses: actions/checkout@v4 |
58 | 17 | with: |
59 | 18 | fetch-depth: 0 |
60 | | - repository: '${{ steps.getRepository.outputs.owner }}/${{ steps.getRepository.outputs.repository }}' |
61 | | - ref: ${{ steps.getRepository.outputs.pr_branch }} |
62 | 19 | token: ${{ secrets.PAT }} |
63 | 20 |
|
64 | 21 | - name: Run the regeneration |
65 | 22 | uses: ./.github/actions/regenerate |
66 | | - |
67 | | - - name: Final Comment |
68 | | - run: | |
69 | | - gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:THUMBS_UP}){reaction{content}subject{id}}}" |
70 | | - gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" |
71 | | - ( |
72 | | - echo "**${{ github.workflow }}**" |
73 | | - echo "The regenerate task is done!" |
74 | | - echo |
75 | | - echo "You can find the workflow here:" |
76 | | - echo "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
77 | | - ) | \ |
78 | | - gh pr comment "${PR_NUMBER}" --repo ${{ github.repository }} -F - |
79 | | - env: |
80 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
81 | | - PR_NUMBER: ${{ github.event.issue.number }} |
82 | | - NODE_ID: ${{ github.event.comment.node_id }} |
83 | | - |
84 | | - notify-job: |
85 | | - needs: [regenerate] |
86 | | - runs-on: ubuntu-latest |
87 | | - permissions: |
88 | | - contents: read |
89 | | - pull-requests: write |
90 | | - if: ${{ always() && contains(needs.*.result, 'failure') }} |
91 | | - steps: |
92 | | - - name: Notify on Failure |
93 | | - run: | |
94 | | - gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:THUMBS_DOWN}){reaction{content}subject{id}}}" |
95 | | - gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" |
96 | | - ( |
97 | | - echo "**${{ github.workflow }}**" |
98 | | - echo "**Something went wrong!**" |
99 | | - echo |
100 | | - echo "**Details:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
101 | | - ) | \ |
102 | | - gh pr comment "${PR_NUMBER}" --repo ${{ github.repository }} -F - |
103 | | - env: |
104 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
105 | | - PR_NUMBER: ${{ github.event.issue.number }} |
106 | | - NODE_ID: ${{ github.event.comment.node_id }} |
0 commit comments