Skip to content

Commit 138f5bf

Browse files
ci: Add workflow to regenerate static assets (#1457)
* feat(ci): Add workflow to regenerate static assets * feat(ci): Use command action handle command triger * fix(ci): Only give success response after commiting * fix(ci): Only run for pr comments * refactor: Update command trigger text * refactor: Explicitly list permission levels allowed * chore(ci): Allow regenerate command on draft prs
1 parent 15a8055 commit 138f5bf

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: regenerate-static-assets
2+
on:
3+
issue_comment:
4+
types: [created]
5+
6+
jobs:
7+
check-command:
8+
runs-on: ubuntu-latest
9+
if: ${{ github.event.issue.pull_request }}
10+
permissions:
11+
pull-requests: write # required for adding reactions to command comments on PRs
12+
checks: read # required to check if all ci checks have passed
13+
outputs:
14+
continue: ${{ steps.command.outputs.continue }}
15+
steps:
16+
- name: Check command trigger
17+
id: command
18+
uses: github/command@v2
19+
with:
20+
command: "/regenerate-static-assets"
21+
permissions: "write,admin" # The allowed permission levels to invoke this command
22+
allow_forks: true
23+
allow_drafts: true
24+
skip_ci: true
25+
skip_completing: true
26+
27+
regenerate-static-assets:
28+
runs-on: ubuntu-latest
29+
needs: check-command
30+
if: ${{ needs.check-command.outputs.continue == 'true' }}
31+
permissions:
32+
contents: write
33+
outputs:
34+
status: ${{ steps.commit.outputs.status }}
35+
steps:
36+
- name: Get PR branch
37+
id: pr
38+
uses: actions/github-script@v8
39+
with:
40+
script: |
41+
const pr = await github.rest.pulls.get({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
pull_number: context.issue.number
45+
});
46+
core.setOutput('ref', pr.data.head.ref);
47+
core.setOutput('repo', pr.data.head.repo.full_name);
48+
- name: Checkout PR branch
49+
uses: actions/checkout@v6
50+
with:
51+
repository: ${{ steps.pr.outputs.repo }}
52+
ref: ${{ steps.pr.outputs.ref }}
53+
- name: Regenerate static assets
54+
run: |
55+
make frontend-install-dependencies
56+
make frontend-build
57+
- name: Commit and push changes
58+
id: commit
59+
run: |
60+
echo "Checking for changes..."
61+
if git diff --quiet; then
62+
echo "No changes detected."
63+
echo "status=no_changes" >> $GITHUB_OUTPUT
64+
exit 0
65+
fi
66+
git config --global user.name "github-actions[bot]"
67+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
68+
echo "Changes detected. Committing and pushing..."
69+
git add .
70+
git commit -m "chore(ui): Regenerate static assets"
71+
git push origin ${{ steps.pr.outputs.ref }}
72+
echo "status=success" >> $GITHUB_OUTPUT
73+
74+
create-response-comment:
75+
runs-on: ubuntu-latest
76+
needs: [check-command, regenerate-static-assets]
77+
if: ${{ !cancelled() && needs.check-command.outputs.continue == 'true' }}
78+
permissions:
79+
pull-requests: write
80+
steps:
81+
- name: Create response comment
82+
uses: actions/github-script@v8
83+
with:
84+
script: |
85+
const status = '${{ needs.regenerate-static-assets.outputs.status }}';
86+
let reaction = '';
87+
if (status === 'success') {
88+
reaction = 'hooray';
89+
} else if (status === 'no_changes') {
90+
reaction = '+1';
91+
} else {
92+
reaction = '-1';
93+
var workflowUrl = `${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`;
94+
var body = '⚠️ There was an issue regenerating static assets. Please check the [workflow run logs](' + workflowUrl + ') for more details.';
95+
await github.rest.issues.createComment({
96+
owner: context.repo.owner,
97+
repo: context.repo.repo,
98+
issue_number: context.issue.number,
99+
body: body
100+
});
101+
}
102+
await github.rest.reactions.createForIssueComment({
103+
owner: context.repo.owner,
104+
repo: context.repo.repo,
105+
comment_id: context.payload.comment.id,
106+
content: reaction
107+
});

0 commit comments

Comments
 (0)