|
16 | 16 | jobs: |
17 | 17 | require-frontend-export: |
18 | 18 | runs-on: ubuntu-latest |
| 19 | + # Skip if the push was made by github-actions to avoid loops |
19 | 20 | if: github.actor != 'github-actions[bot]' |
20 | 21 | permissions: |
21 | 22 | contents: write |
|
42 | 43 | # Handle initial push (no previous commit) |
43 | 44 | if [[ "$base_sha" == "0000000000000000000000000000000000000000" ]]; then |
44 | 45 | echo "Initial push - skipping check" |
| 46 | + echo "needs_export=false" >> "$GITHUB_OUTPUT" |
45 | 47 | exit 0 |
46 | 48 | fi |
47 | 49 | fi |
@@ -74,47 +76,31 @@ jobs: |
74 | 76 | } >> "$GITHUB_OUTPUT" |
75 | 77 |
|
76 | 78 | - name: Set up Node |
77 | | - if: ${{ github.event_name == 'push' && steps.changes.outputs.needs_export == 'true' }} |
| 79 | + if: github.event_name == 'push' && steps.changes.outputs.needs_export == 'true' |
78 | 80 | uses: actions/setup-node@v4 |
79 | 81 | with: |
80 | 82 | node-version: 20 |
81 | 83 |
|
82 | 84 | - 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 |
| 85 | + if: github.event_name == 'push' && steps.changes.outputs.needs_export == 'true' |
| 86 | + run: bash scripts/export_frontend.sh |
91 | 87 |
|
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 |
| 88 | + - name: Commit and push exported static assets |
| 89 | + if: github.event_name == 'push' && steps.changes.outputs.needs_export == 'true' |
| 90 | + uses: stefanzweifel/git-auto-commit-action@v7 |
| 91 | + with: |
| 92 | + commit_message: "chore: export frontend static assets [skip ci]" |
| 93 | + file_pattern: "src/hyperview/server/static/**" |
103 | 94 |
|
104 | | - - name: Verify static export updated when frontend changes |
105 | | - if: ${{ !(github.event_name == 'push' && steps.changes.outputs.needs_export == 'true') }} |
| 95 | + - name: Fail PR if frontend changed without static export |
| 96 | + if: github.event_name == 'pull_request' && steps.changes.outputs.needs_export == 'true' |
106 | 97 | run: | |
107 | | - set -euo pipefail |
108 | | -
|
109 | | - frontend_changed="${{ steps.changes.outputs.frontend_changed }}" |
110 | | - static_changed="${{ steps.changes.outputs.static_changed }}" |
111 | | -
|
112 | | - if [[ "$frontend_changed" == "true" && "$static_changed" != "true" ]]; then |
113 | | - echo "" |
114 | | - echo "ERROR: frontend/ changed but src/hyperview/server/static/ was not updated." |
115 | | - echo "Run: bash scripts/export_frontend.sh" |
116 | | - echo "Then commit the updated src/hyperview/server/static/ output." |
117 | | - exit 1 |
118 | | - fi |
119 | | -
|
120 | | - echo "OK: export requirements satisfied." |
| 98 | + echo "" |
| 99 | + echo "ERROR: frontend/ changed but src/hyperview/server/static/ was not updated." |
| 100 | + echo "" |
| 101 | + echo "Run locally:" |
| 102 | + echo " bash scripts/export_frontend.sh" |
| 103 | + echo " git add src/hyperview/server/static" |
| 104 | + echo " git commit -m 'chore: export frontend static assets'" |
| 105 | + echo "" |
| 106 | + exit 1 |
0 commit comments