Skip to content

Commit be64ffc

Browse files
committed
ci: auto-export frontend on push
1 parent e0d1836 commit be64ffc

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

.github/workflows/require_frontend_export.yml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ on:
1616
jobs:
1717
require-frontend-export:
1818
runs-on: ubuntu-latest
19+
if: github.actor != 'github-actions[bot]'
20+
permissions:
21+
contents: write
1922

2023
steps:
2124
- name: Checkout repository
2225
uses: actions/checkout@v4
2326
with:
2427
fetch-depth: 0
2528

26-
- name: Verify static export updated when frontend changes
29+
- name: Detect frontend and static changes
30+
id: changes
2731
run: |
2832
set -euo pipefail
2933
@@ -58,6 +62,53 @@ jobs:
5862
static_changed="true"
5963
fi
6064
65+
needs_export="false"
66+
if [[ "$frontend_changed" == "true" && "$static_changed" != "true" ]]; then
67+
needs_export="true"
68+
fi
69+
70+
{
71+
echo "frontend_changed=$frontend_changed"
72+
echo "static_changed=$static_changed"
73+
echo "needs_export=$needs_export"
74+
} >> "$GITHUB_OUTPUT"
75+
76+
- name: Set up Node
77+
if: ${{ github.event_name == 'push' && steps.changes.outputs.needs_export == 'true' }}
78+
uses: actions/setup-node@v4
79+
with:
80+
node-version: 20
81+
82+
- name: Export frontend
83+
if: ${{ github.event_name == 'push' && steps.changes.outputs.needs_export == 'true' }}
84+
run: |
85+
bash scripts/export_frontend.sh
86+
87+
- name: Commit exported static assets
88+
if: ${{ github.event_name == 'push' && steps.changes.outputs.needs_export == 'true' }}
89+
run: |
90+
set -euo pipefail
91+
92+
if [[ -z "$(git status --porcelain)" ]]; then
93+
echo "No export changes to commit."
94+
exit 0
95+
fi
96+
97+
git status --short
98+
git config user.name "github-actions[bot]"
99+
git config user.email "github-actions[bot]@users.noreply.github.com"
100+
git add src/hyperview/server/static
101+
git commit -m "chore: export frontend static assets"
102+
git push
103+
104+
- name: Verify static export updated when frontend changes
105+
if: ${{ !(github.event_name == 'push' && steps.changes.outputs.needs_export == 'true') }}
106+
run: |
107+
set -euo pipefail
108+
109+
frontend_changed="${{ steps.changes.outputs.frontend_changed }}"
110+
static_changed="${{ steps.changes.outputs.static_changed }}"
111+
61112
if [[ "$frontend_changed" == "true" && "$static_changed" != "true" ]]; then
62113
echo ""
63114
echo "ERROR: frontend/ changed but src/hyperview/server/static/ was not updated."

0 commit comments

Comments
 (0)