Skip to content

Commit 355c0da

Browse files
committed
chore: Fallback to manually dispatching jobs
1 parent a714040 commit 355c0da

1 file changed

Lines changed: 3 additions & 87 deletions

File tree

.github/workflows/pr-comment.yaml

Lines changed: 3 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,22 @@
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
32

43
name: PR comment handling
54
on:
6-
issue_comment:
7-
types:
8-
- created
5+
workflow_dispatch:
96

107
jobs:
118
regenerate:
129
name: Regenerate sample data
1310
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'
1512
permissions:
1613
contents: read
17-
pull-requests: write
1814
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-
5615
- name: Checkout source code from Github
5716
uses: actions/checkout@v4
5817
with:
5918
fetch-depth: 0
60-
repository: '${{ steps.getRepository.outputs.owner }}/${{ steps.getRepository.outputs.repository }}'
61-
ref: ${{ steps.getRepository.outputs.pr_branch }}
6219
token: ${{ secrets.PAT }}
6320

6421
- name: Run the regeneration
6522
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

Comments
 (0)