|
| 1 | +name: Sync app.css changes |
| 2 | + |
| 3 | +# When a PR adds a new src/app-css/app-x.y.z.css snapshot, diff it against |
| 4 | +# the previous snapshot and apply the same additions/removals/changes to |
| 5 | +# the flat src/css/*.css files. src/scss/*.scss is hand-nested and not |
| 6 | +# safe to auto-edit, so instead this appends a checklist to |
| 7 | +# src/app-css/scss-sync-report.md for a human to port by hand (see the |
| 8 | +# separate "Notify SCSS nesting sync" workflow). |
| 9 | + |
| 10 | +on: |
| 11 | + pull_request: |
| 12 | + branches: ['**'] |
| 13 | + paths: |
| 14 | + - 'src/app-css/app-*.css' |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + pull-requests: write |
| 19 | + |
| 20 | +jobs: |
| 21 | + sync: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + if: github.event.pull_request.head.repo.full_name == github.repository |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v7 |
| 26 | + with: |
| 27 | + ref: ${{ github.event.pull_request.head.ref }} |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + - uses: actions/setup-node@v7 |
| 31 | + with: |
| 32 | + node-version: '24.x' |
| 33 | + |
| 34 | + - name: Find newly added app-*.css snapshots |
| 35 | + id: added |
| 36 | + run: | |
| 37 | + FILES=$(git diff --name-only --diff-filter=A "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}" -- 'src/app-css/app-*.css') |
| 38 | + if [ -z "$FILES" ]; then |
| 39 | + echo "No new app-*.css snapshot added in this PR — nothing to sync." |
| 40 | + echo "found=false" >> "$GITHUB_OUTPUT" |
| 41 | + else |
| 42 | + echo "found=true" >> "$GITHUB_OUTPUT" |
| 43 | + echo "files<<EOF" >> "$GITHUB_OUTPUT" |
| 44 | + echo "$FILES" >> "$GITHUB_OUTPUT" |
| 45 | + echo "EOF" >> "$GITHUB_OUTPUT" |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Run sync for each new snapshot |
| 49 | + if: steps.added.outputs.found == 'true' |
| 50 | + run: | |
| 51 | + while IFS= read -r file; do |
| 52 | + [ -z "$file" ] && continue |
| 53 | + echo "::group::sync-app-css.mjs --new $file" |
| 54 | + node sync-app-css.mjs --new "$file" |
| 55 | + echo "::endgroup::" |
| 56 | + done <<< "${{ steps.added.outputs.files }}" |
| 57 | +
|
| 58 | + - name: Commit and push updates |
| 59 | + if: steps.added.outputs.found == 'true' |
| 60 | + id: commit |
| 61 | + run: | |
| 62 | + git config user.name "github-actions[bot]" |
| 63 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 64 | + if git status --porcelain -- src/css src/app-css | grep -q .; then |
| 65 | + git add src/css src/app-css |
| 66 | + git commit -m "Sync src/css with $(basename "$(echo "${{ steps.added.outputs.files }}" | head -n1)")" |
| 67 | + git push origin "HEAD:${{ github.event.pull_request.head.ref }}" |
| 68 | + echo "committed=true" >> "$GITHUB_OUTPUT" |
| 69 | + else |
| 70 | + echo "committed=false" >> "$GITHUB_OUTPUT" |
| 71 | + fi |
| 72 | +
|
| 73 | + - name: Comment on PR |
| 74 | + if: steps.added.outputs.found == 'true' |
| 75 | + uses: actions/github-script@v8 |
| 76 | + with: |
| 77 | + script: | |
| 78 | + const fs = require('fs'); |
| 79 | + let summary; |
| 80 | + try { |
| 81 | + summary = JSON.parse(fs.readFileSync('sync-summary.json', 'utf8')); |
| 82 | + } catch { |
| 83 | + return; |
| 84 | + } |
| 85 | + const lines = [ |
| 86 | + `**app.css sync**: \`${summary.oldVersion}\` → \`${summary.newVersion}\``, |
| 87 | + '', |
| 88 | + `- Changed selectors applied to \`src/css/*.css\`: ${summary.changed}`, |
| 89 | + `- Removed selectors applied to \`src/css/*.css\`: ${summary.removed}`, |
| 90 | + `- New selectors staged in \`src/app-css/_new-selectors.css\`: ${summary.added}`, |
| 91 | + ]; |
| 92 | + if (summary.notFoundLocally > 0) { |
| 93 | + lines.push(`- ${summary.notFoundLocally} changed/removed selector(s) from the old baseline were not found in any \`src/css/*.css\` file (already customized or removed by hand) — check the workflow log.`); |
| 94 | + } |
| 95 | + if (summary.scssReportUpdated) { |
| 96 | + lines.push('', '`src/app-css/scss-sync-report.md` was updated with a checklist for porting these changes into the hand-nested `src/scss/*.scss` partials.'); |
| 97 | + } |
| 98 | + if (summary.added > 0) { |
| 99 | + lines.push('', 'New selectors need a manual home in `src/css/` before they can be ported to SCSS — see `src/app-css/_new-selectors.css`.'); |
| 100 | + } |
| 101 | + await github.rest.issues.createComment({ |
| 102 | + owner: context.repo.owner, |
| 103 | + repo: context.repo.repo, |
| 104 | + issue_number: context.issue.number, |
| 105 | + body: lines.join('\n'), |
| 106 | + }); |
0 commit comments