|
| 1 | +name: PR Validation |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +# Limit GITHUB_TOKEN permissions to read-only |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + lint: |
| 17 | + name: Lint (ESLint) |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Setup pnpm |
| 24 | + uses: pnpm/action-setup@v4 |
| 25 | + |
| 26 | + - name: Setup Node.js |
| 27 | + uses: actions/setup-node@v4 |
| 28 | + with: |
| 29 | + node-version: "20" |
| 30 | + cache: "pnpm" |
| 31 | + |
| 32 | + - name: Install dependencies |
| 33 | + run: pnpm install --frozen-lockfile |
| 34 | + |
| 35 | + - name: Run ESLint |
| 36 | + run: pnpm lint |
| 37 | + |
| 38 | + prettier: |
| 39 | + name: Format Check (Prettier) |
| 40 | + runs-on: ubuntu-latest |
| 41 | + steps: |
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Setup pnpm |
| 46 | + uses: pnpm/action-setup@v4 |
| 47 | + |
| 48 | + - name: Setup Node.js |
| 49 | + uses: actions/setup-node@v4 |
| 50 | + with: |
| 51 | + node-version: "20" |
| 52 | + cache: "pnpm" |
| 53 | + |
| 54 | + - name: Install dependencies |
| 55 | + run: pnpm install --frozen-lockfile |
| 56 | + |
| 57 | + - name: Check formatting |
| 58 | + run: pnpm format:check |
| 59 | + |
| 60 | + typecheck: |
| 61 | + name: Type Check |
| 62 | + runs-on: ubuntu-latest |
| 63 | + steps: |
| 64 | + - name: Checkout |
| 65 | + uses: actions/checkout@v4 |
| 66 | + |
| 67 | + - name: Setup pnpm |
| 68 | + uses: pnpm/action-setup@v4 |
| 69 | + |
| 70 | + - name: Setup Node.js |
| 71 | + uses: actions/setup-node@v4 |
| 72 | + with: |
| 73 | + node-version: "20" |
| 74 | + cache: "pnpm" |
| 75 | + |
| 76 | + - name: Install dependencies |
| 77 | + run: pnpm install --frozen-lockfile |
| 78 | + |
| 79 | + - name: Run TypeScript |
| 80 | + run: pnpm typecheck |
| 81 | + |
| 82 | + build: |
| 83 | + name: Build |
| 84 | + runs-on: ubuntu-latest |
| 85 | + steps: |
| 86 | + - name: Checkout |
| 87 | + uses: actions/checkout@v4 |
| 88 | + |
| 89 | + - name: Setup pnpm |
| 90 | + uses: pnpm/action-setup@v4 |
| 91 | + |
| 92 | + - name: Setup Node.js |
| 93 | + uses: actions/setup-node@v4 |
| 94 | + with: |
| 95 | + node-version: "20" |
| 96 | + cache: "pnpm" |
| 97 | + |
| 98 | + - name: Install dependencies |
| 99 | + run: pnpm install --frozen-lockfile |
| 100 | + |
| 101 | + - name: Build packages |
| 102 | + run: pnpm build |
| 103 | + |
| 104 | + - name: Upload build artifacts |
| 105 | + uses: actions/upload-artifact@v4 |
| 106 | + with: |
| 107 | + name: dist |
| 108 | + # Artifact paths match the monorepo structure: packages/*/dist and apps/docs/dist |
| 109 | + path: | |
| 110 | + packages/*/dist |
| 111 | + apps/docs/dist |
| 112 | + retention-days: 7 |
| 113 | + |
| 114 | + release-check: |
| 115 | + name: Release Check (Dry Run) |
| 116 | + runs-on: ubuntu-latest |
| 117 | + outputs: |
| 118 | + has-changeset: ${{ steps.check-changeset.outputs.has-changeset }} |
| 119 | + steps: |
| 120 | + - name: Checkout |
| 121 | + uses: actions/checkout@v4 |
| 122 | + with: |
| 123 | + fetch-depth: 0 |
| 124 | + |
| 125 | + - name: Setup pnpm |
| 126 | + uses: pnpm/action-setup@v4 |
| 127 | + |
| 128 | + - name: Setup Node.js |
| 129 | + uses: actions/setup-node@v4 |
| 130 | + with: |
| 131 | + node-version: "20" |
| 132 | + cache: "pnpm" |
| 133 | + |
| 134 | + - name: Install dependencies |
| 135 | + run: pnpm install --frozen-lockfile |
| 136 | + |
| 137 | + - name: Check for changeset files |
| 138 | + id: check-changeset |
| 139 | + run: | |
| 140 | + # Check if any changeset files were added or modified in this PR |
| 141 | + # Compare against the base branch to find changed files |
| 142 | + git fetch origin ${{ github.base_ref }} |
| 143 | + CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD) |
| 144 | + |
| 145 | + # Check if any .md files in .changeset directory (excluding README.md specifically) |
| 146 | + CHANGESET_FILES=$(echo "$CHANGED_FILES" | grep -E '^\.changeset/.*\.md$' | grep -v '^\.changeset/README\.md$' || true) |
| 147 | + |
| 148 | + if [ -n "$CHANGESET_FILES" ]; then |
| 149 | + echo "has-changeset=true" >> $GITHUB_OUTPUT |
| 150 | + echo "✅ Changeset file(s) found:" |
| 151 | + echo "$CHANGESET_FILES" |
| 152 | + else |
| 153 | + echo "has-changeset=false" >> $GITHUB_OUTPUT |
| 154 | + echo "ℹ️ No changeset files found in this PR" |
| 155 | + echo "If this PR includes changes that should be released, please add a changeset:" |
| 156 | + echo " pnpm changeset" |
| 157 | + fi |
| 158 | +
|
| 159 | + - name: Validate changeset format |
| 160 | + if: steps.check-changeset.outputs.has-changeset == 'true' |
| 161 | + run: | |
| 162 | + echo "Validating changeset format..." |
| 163 | + pnpm changeset status |
| 164 | + echo "✅ Changeset validation passed! This PR will trigger a release." |
| 165 | +
|
| 166 | + - name: Skip validation |
| 167 | + if: steps.check-changeset.outputs.has-changeset == 'false' |
| 168 | + run: | |
| 169 | + echo "ℹ️ Skipping changeset validation (no changesets in this PR)" |
| 170 | + echo "This PR will not trigger a release." |
| 171 | +
|
| 172 | + pr-validation-complete: |
| 173 | + name: PR Validation Complete |
| 174 | + runs-on: ubuntu-latest |
| 175 | + if: always() |
| 176 | + needs: [lint, prettier, typecheck, build, release-check] |
| 177 | + steps: |
| 178 | + - name: Check job status |
| 179 | + run: | |
| 180 | + echo "Checking status of all required jobs..." |
| 181 | + |
| 182 | + # Check each job status |
| 183 | + if [ "${{ needs.lint.result }}" != "success" ]; then |
| 184 | + echo "❌ Lint job failed or was cancelled" |
| 185 | + exit 1 |
| 186 | + fi |
| 187 | + |
| 188 | + if [ "${{ needs.prettier.result }}" != "success" ]; then |
| 189 | + echo "❌ Prettier job failed or was cancelled" |
| 190 | + exit 1 |
| 191 | + fi |
| 192 | + |
| 193 | + if [ "${{ needs.typecheck.result }}" != "success" ]; then |
| 194 | + echo "❌ TypeCheck job failed or was cancelled" |
| 195 | + exit 1 |
| 196 | + fi |
| 197 | + |
| 198 | + if [ "${{ needs.build.result }}" != "success" ]; then |
| 199 | + echo "❌ Build job failed or was cancelled" |
| 200 | + exit 1 |
| 201 | + fi |
| 202 | + |
| 203 | + if [ "${{ needs.release-check.result }}" != "success" ]; then |
| 204 | + echo "❌ Release Check job failed or was cancelled" |
| 205 | + exit 1 |
| 206 | + fi |
| 207 | + |
| 208 | + echo "✅ All validation checks passed successfully!" |
0 commit comments