Skip to content

Commit fefc69a

Browse files
committed
feat(tailwindcss-patch): add affected-shards validate workflow template
1 parent 4070450 commit fefc69a

5 files changed

Lines changed: 187 additions & 0 deletions

File tree

.changeset/few-cooks-admire.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"tailwindcss-patch": patch
3+
---
4+
5+
Add a PR diff-aware GitHub Actions template for migration report validation in monorepos.
6+
7+
- add `packages/tailwindcss-patch/examples/github-actions/validate-migration-report-affected.yml`
8+
- detect affected shards from pull request file changes and only run required shards
9+
- add docs links in README/README-cn and migration notes

packages/tailwindcss-patch/MIGRATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Migration mapping:
9797
- `tw-patch validate --json` now emits a stable discriminated payload (`ok: true` success / `ok: false` failure with `reason` + `exitCode`), covered by `tailwindcss-patch/validate-result.schema.json`.
9898
- A ready-to-use GitHub Actions example is available at `packages/tailwindcss-patch/examples/github-actions/validate-migration-report.yml`.
9999
- A matrix-based monorepo GitHub Actions example is available at `packages/tailwindcss-patch/examples/github-actions/validate-migration-report-matrix.yml`.
100+
- An affected-shards monorepo GitHub Actions example (PR diff aware) is available at `packages/tailwindcss-patch/examples/github-actions/validate-migration-report-affected.yml`.
100101
- Migration report tooling now has public exports from package entry (`migrateConfigFiles`, `restoreConfigFiles`, report constants/types) and published JSON schema subpaths: `tailwindcss-patch/migration-report.schema.json`, `tailwindcss-patch/restore-result.schema.json`, `tailwindcss-patch/validate-result.schema.json`.
101102
- Commands resolve configuration from `tailwindcss-patch.config.ts` via `@tailwindcss-mangle/config`. Existing configuration files continue to work without changes.
102103

packages/tailwindcss-patch/README-cn.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ esac
141141
GitHub Actions 模板:
142142
- 单任务版本:`packages/tailwindcss-patch/examples/github-actions/validate-migration-report.yml`
143143
- monorepo 矩阵分片(`root/apps/packages`):`packages/tailwindcss-patch/examples/github-actions/validate-migration-report-matrix.yml`
144+
- monorepo 按变更分片(基于 PR diff):`packages/tailwindcss-patch/examples/github-actions/validate-migration-report-affected.yml`
144145

145146
### `tokens` 常用参数
146147

packages/tailwindcss-patch/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ esac
198198
GitHub Actions templates:
199199
- single job: `packages/tailwindcss-patch/examples/github-actions/validate-migration-report.yml`
200200
- monorepo matrix shards (`root/apps/packages`): `packages/tailwindcss-patch/examples/github-actions/validate-migration-report-matrix.yml`
201+
- monorepo affected shards (PR diff-aware): `packages/tailwindcss-patch/examples/github-actions/validate-migration-report-affected.yml`
201202

202203
### Token report options
203204

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
name: Validate Tailwind Patch Migration Report (Affected Shards)
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
detect-shards:
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 5
14+
outputs:
15+
has_changes: ${{ steps.resolve.outputs.has_changes }}
16+
matrix: ${{ steps.resolve.outputs.matrix }}
17+
shards: ${{ steps.resolve.outputs.shards }}
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v6
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Resolve affected shards
26+
id: resolve
27+
shell: bash
28+
run: |
29+
set -euo pipefail
30+
31+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
32+
shards=(root apps packages)
33+
else
34+
base_sha="${{ github.event.pull_request.base.sha }}"
35+
head_sha="${{ github.sha }}"
36+
mapfile -t changed_files < <(git diff --name-only "$base_sha" "$head_sha")
37+
38+
run_all=false
39+
root=false
40+
apps=false
41+
packages=false
42+
43+
for file in "${changed_files[@]}"; do
44+
[ -z "$file" ] && continue
45+
46+
case "$file" in
47+
apps/*) apps=true ;;
48+
packages/*) packages=true ;;
49+
tailwindcss-patch.config.*|tailwindcss-mangle.config.*) root=true ;;
50+
esac
51+
52+
case "$file" in
53+
packages/tailwindcss-patch/*|pnpm-lock.yaml|pnpm-workspace.yaml)
54+
run_all=true
55+
;;
56+
esac
57+
done
58+
59+
if [ "$run_all" = true ]; then
60+
shards=(root apps packages)
61+
else
62+
shards=()
63+
[ "$root" = true ] && shards+=(root)
64+
[ "$apps" = true ] && shards+=(apps)
65+
[ "$packages" = true ] && shards+=(packages)
66+
fi
67+
fi
68+
69+
if [ "${#shards[@]}" -eq 0 ]; then
70+
echo "has_changes=false" >> "$GITHUB_OUTPUT"
71+
echo "shards=none" >> "$GITHUB_OUTPUT"
72+
echo 'matrix={"shard":[]}' >> "$GITHUB_OUTPUT"
73+
exit 0
74+
fi
75+
76+
shard_csv="$(IFS=,; echo "${shards[*]}")"
77+
matrix_json="$(SHARDS="$shard_csv" node -e '
78+
const names = (process.env.SHARDS || "").split(",").filter(Boolean)
79+
const reportMap = {
80+
root: ".tw-patch/migrate-report-root.json",
81+
apps: ".tw-patch/migrate-report-apps.json",
82+
packages: ".tw-patch/migrate-report-packages.json",
83+
}
84+
const shard = names.map(name => ({ name, report_file: reportMap[name] }))
85+
process.stdout.write(JSON.stringify({ shard }))
86+
')"
87+
88+
echo "has_changes=true" >> "$GITHUB_OUTPUT"
89+
echo "shards=$shard_csv" >> "$GITHUB_OUTPUT"
90+
echo "matrix=$matrix_json" >> "$GITHUB_OUTPUT"
91+
92+
validate-migration-report:
93+
needs: detect-shards
94+
if: needs.detect-shards.outputs.has_changes == 'true'
95+
runs-on: ubuntu-latest
96+
timeout-minutes: 10
97+
strategy:
98+
fail-fast: false
99+
matrix: ${{ fromJson(needs.detect-shards.outputs.matrix) }}
100+
101+
steps:
102+
- name: Checkout
103+
uses: actions/checkout@v6
104+
105+
- name: Setup pnpm
106+
uses: pnpm/action-setup@v4
107+
108+
- name: Setup Node.js
109+
uses: actions/setup-node@v6
110+
with:
111+
node-version: 20
112+
cache: pnpm
113+
cache-dependency-path: pnpm-lock.yaml
114+
115+
- name: Install dependencies
116+
run: pnpm install --frozen-lockfile
117+
118+
- name: Ensure migration report is up-to-date (${{ matrix.shard.name }})
119+
shell: bash
120+
run: |
121+
include_args=()
122+
case "${{ matrix.shard.name }}" in
123+
root)
124+
include_args+=(--include "tailwindcss-patch.config.*")
125+
include_args+=(--include "tailwindcss-mangle.config.*")
126+
;;
127+
apps)
128+
include_args+=(--include "apps/**")
129+
;;
130+
packages)
131+
include_args+=(--include "packages/**")
132+
;;
133+
*)
134+
echo "::error::Unknown shard: ${{ matrix.shard.name }}"
135+
exit 1
136+
;;
137+
esac
138+
139+
pnpm dlx tw-patch migrate --workspace --check "${include_args[@]}" --report-file "${{ matrix.shard.report_file }}"
140+
141+
- name: Validate migration report (${{ matrix.shard.name }})
142+
shell: bash
143+
run: |
144+
mkdir -p .tw-patch
145+
set +e
146+
pnpm dlx tw-patch validate --report-file "${{ matrix.shard.report_file }}" --strict --json > ".tw-patch/validate-result-${{ matrix.shard.name }}.json"
147+
status=$?
148+
set -e
149+
150+
if [ "$status" -ne 0 ]; then
151+
cat ".tw-patch/validate-result-${{ matrix.shard.name }}.json"
152+
fi
153+
154+
case "$status" in
155+
0) echo "validate ok (${{ matrix.shard.name }})" ;;
156+
21) echo "::error::Migration report schema/kind incompatible (${{ matrix.shard.name }})"; exit 1 ;;
157+
22) echo "::error::Missing backups under --strict (${{ matrix.shard.name }})"; exit 1 ;;
158+
23) echo "::error::I/O failure while reading report/backups (${{ matrix.shard.name }})"; exit 1 ;;
159+
*) echo "::error::Unknown validate failure (exit $status, shard=${{ matrix.shard.name }})"; exit "$status" ;;
160+
esac
161+
162+
- name: Upload validate result (${{ matrix.shard.name }})
163+
if: always()
164+
uses: actions/upload-artifact@v4
165+
with:
166+
name: tw-patch-validate-result-${{ matrix.shard.name }}
167+
path: .tw-patch/validate-result-${{ matrix.shard.name }}.json
168+
169+
no-affected-shards:
170+
needs: detect-shards
171+
if: needs.detect-shards.outputs.has_changes != 'true'
172+
runs-on: ubuntu-latest
173+
steps:
174+
- name: Skip
175+
run: echo "No affected shards for migration report validation."

0 commit comments

Comments
 (0)