|
| 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