|
| 1 | +name: Checks and release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, reopened] |
| 9 | + # Manual release support - consolidated here to work with npm trusted publishing |
| 10 | + # npm only allows ONE workflow file as trusted publisher, so all publishing |
| 11 | + # must go through this workflow (release.yml) |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + release_mode: |
| 15 | + description: 'Manual release mode' |
| 16 | + required: true |
| 17 | + type: choice |
| 18 | + default: 'instant' |
| 19 | + options: |
| 20 | + - instant |
| 21 | + - changeset-pr |
| 22 | + bump_type: |
| 23 | + description: 'Manual release type' |
| 24 | + required: true |
| 25 | + type: choice |
| 26 | + options: |
| 27 | + - patch |
| 28 | + - minor |
| 29 | + - major |
| 30 | + description: |
| 31 | + description: 'Manual release description (optional)' |
| 32 | + required: false |
| 33 | + type: string |
| 34 | + |
| 35 | +concurrency: ${{ github.workflow }}-${{ github.ref }} |
| 36 | + |
| 37 | +jobs: |
| 38 | + # === DETECT CHANGES - determines which jobs should run === |
| 39 | + detect-changes: |
| 40 | + name: Detect Changes |
| 41 | + runs-on: ubuntu-latest |
| 42 | + if: github.event_name != 'workflow_dispatch' |
| 43 | + outputs: |
| 44 | + mjs-changed: ${{ steps.changes.outputs.mjs-changed }} |
| 45 | + js-changed: ${{ steps.changes.outputs.js-changed }} |
| 46 | + package-changed: ${{ steps.changes.outputs.package-changed }} |
| 47 | + docs-changed: ${{ steps.changes.outputs.docs-changed }} |
| 48 | + workflow-changed: ${{ steps.changes.outputs.workflow-changed }} |
| 49 | + any-code-changed: ${{ steps.changes.outputs.any-code-changed }} |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v4 |
| 52 | + with: |
| 53 | + fetch-depth: 0 |
| 54 | + |
| 55 | + - name: Detect changes |
| 56 | + id: changes |
| 57 | + env: |
| 58 | + GITHUB_EVENT_NAME: ${{ github.event_name }} |
| 59 | + GITHUB_BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| 60 | + GITHUB_HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 61 | + run: node scripts/detect-code-changes.mjs |
| 62 | + |
| 63 | + # === VERSION CHANGE CHECK === |
| 64 | + # Prohibit manual version changes in package.json - versions should only be changed by CI/CD |
| 65 | + version-check: |
| 66 | + name: Check for Manual Version Changes |
| 67 | + runs-on: ubuntu-latest |
| 68 | + if: github.event_name == 'pull_request' |
| 69 | + steps: |
| 70 | + - uses: actions/checkout@v4 |
| 71 | + with: |
| 72 | + fetch-depth: 0 |
| 73 | + |
| 74 | + - name: Check for version changes in package.json |
| 75 | + env: |
| 76 | + GITHUB_HEAD_REF: ${{ github.head_ref }} |
| 77 | + GITHUB_BASE_REF: ${{ github.base_ref }} |
| 78 | + run: node scripts/check-version.mjs |
| 79 | + |
| 80 | + # === CHANGESET CHECK - only runs on PRs with code changes === |
| 81 | + # Docs-only PRs (./docs folder, markdown files) don't require changesets |
| 82 | + changeset-check: |
| 83 | + name: Check for Changesets |
| 84 | + runs-on: ubuntu-latest |
| 85 | + needs: [detect-changes] |
| 86 | + if: github.event_name == 'pull_request' && needs.detect-changes.outputs.any-code-changed == 'true' |
| 87 | + steps: |
| 88 | + - uses: actions/checkout@v4 |
| 89 | + with: |
| 90 | + fetch-depth: 0 |
| 91 | + |
| 92 | + - name: Setup Node.js |
| 93 | + uses: actions/setup-node@v4 |
| 94 | + with: |
| 95 | + node-version: '20.x' |
| 96 | + |
| 97 | + - name: Install dependencies |
| 98 | + run: npm install |
| 99 | + |
| 100 | + - name: Check for changesets |
| 101 | + env: |
| 102 | + # Pass PR context to the validation script |
| 103 | + GITHUB_BASE_REF: ${{ github.base_ref }} |
| 104 | + GITHUB_BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| 105 | + GITHUB_HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 106 | + run: | |
| 107 | + # Skip changeset check for automated version PRs |
| 108 | + if [[ "${{ github.head_ref }}" == "changeset-release/"* ]]; then |
| 109 | + echo "Skipping changeset check for automated release PR" |
| 110 | + exit 0 |
| 111 | + fi |
| 112 | +
|
| 113 | + # Run changeset validation script |
| 114 | + # This validates that exactly ONE changeset was ADDED by this PR |
| 115 | + # Pre-existing changesets from other merged PRs are ignored |
| 116 | + node scripts/validate-changeset.mjs |
| 117 | +
|
| 118 | + # === LINT AND FORMAT CHECK === |
| 119 | + # Lint runs independently of changeset-check - it's a fast check that should always run |
| 120 | + # See: https://github.com/link-assistant/hive-mind/pull/1024 for why this dependency was removed |
| 121 | + lint: |
| 122 | + name: Lint and Format Check |
| 123 | + runs-on: ubuntu-latest |
| 124 | + needs: [detect-changes] |
| 125 | + if: | |
| 126 | + github.event_name == 'push' || |
| 127 | + needs.detect-changes.outputs.mjs-changed == 'true' || |
| 128 | + needs.detect-changes.outputs.js-changed == 'true' || |
| 129 | + needs.detect-changes.outputs.docs-changed == 'true' || |
| 130 | + needs.detect-changes.outputs.package-changed == 'true' || |
| 131 | + needs.detect-changes.outputs.workflow-changed == 'true' |
| 132 | + steps: |
| 133 | + - uses: actions/checkout@v4 |
| 134 | + |
| 135 | + - name: Setup Node.js |
| 136 | + uses: actions/setup-node@v4 |
| 137 | + with: |
| 138 | + node-version: '20.x' |
| 139 | + |
| 140 | + - name: Install dependencies |
| 141 | + run: npm install |
| 142 | + |
| 143 | + - name: Run ESLint |
| 144 | + run: npm run lint |
| 145 | + |
| 146 | + - name: Check formatting |
| 147 | + run: npm run format:check |
| 148 | + |
| 149 | + - name: Check code duplication |
| 150 | + run: npm run check:duplication |
| 151 | + |
| 152 | + # Test matrix: 3 runtimes (Node.js, Bun, Deno) x 3 OS (Ubuntu, macOS, Windows) |
| 153 | + test: |
| 154 | + name: Test (${{ matrix.runtime }} on ${{ matrix.os }}) |
| 155 | + runs-on: ${{ matrix.os }} |
| 156 | + needs: [detect-changes, changeset-check] |
| 157 | + # Run if: push event, OR changeset-check succeeded, OR changeset-check was skipped (docs-only PR) |
| 158 | + if: always() && (github.event_name == 'push' || needs.changeset-check.result == 'success' || needs.changeset-check.result == 'skipped') |
| 159 | + strategy: |
| 160 | + fail-fast: false |
| 161 | + matrix: |
| 162 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 163 | + runtime: [node, bun, deno] |
| 164 | + steps: |
| 165 | + - uses: actions/checkout@v4 |
| 166 | + |
| 167 | + - name: Setup Node.js |
| 168 | + if: matrix.runtime == 'node' |
| 169 | + uses: actions/setup-node@v4 |
| 170 | + with: |
| 171 | + node-version: '20.x' |
| 172 | + |
| 173 | + - name: Install dependencies (Node.js) |
| 174 | + if: matrix.runtime == 'node' |
| 175 | + run: npm install |
| 176 | + |
| 177 | + - name: Run tests (Node.js) |
| 178 | + if: matrix.runtime == 'node' |
| 179 | + run: npm test |
| 180 | + |
| 181 | + - name: Setup Bun |
| 182 | + if: matrix.runtime == 'bun' |
| 183 | + uses: oven-sh/setup-bun@v2 |
| 184 | + with: |
| 185 | + bun-version: latest |
| 186 | + |
| 187 | + - name: Install dependencies (Bun) |
| 188 | + if: matrix.runtime == 'bun' |
| 189 | + run: bun install |
| 190 | + |
| 191 | + - name: Run tests (Bun) |
| 192 | + if: matrix.runtime == 'bun' |
| 193 | + run: bun test |
| 194 | + |
| 195 | + - name: Setup Deno |
| 196 | + if: matrix.runtime == 'deno' |
| 197 | + uses: denoland/setup-deno@v2 |
| 198 | + with: |
| 199 | + deno-version: v2.x |
| 200 | + |
| 201 | + - name: Run tests (Deno) |
| 202 | + if: matrix.runtime == 'deno' |
| 203 | + run: deno test --allow-read |
| 204 | + |
| 205 | + # Release - only runs on main after tests pass (for push events) |
| 206 | + release: |
| 207 | + name: Release |
| 208 | + needs: [lint, test] |
| 209 | + # Use always() to ensure this job runs even if changeset-check was skipped |
| 210 | + # This is needed because lint/test jobs have a transitive dependency on changeset-check |
| 211 | + if: always() && github.ref == 'refs/heads/main' && github.event_name == 'push' && needs.lint.result == 'success' && needs.test.result == 'success' |
| 212 | + runs-on: ubuntu-latest |
| 213 | + # Permissions required for npm OIDC trusted publishing |
| 214 | + permissions: |
| 215 | + contents: write |
| 216 | + pull-requests: write |
| 217 | + id-token: write |
| 218 | + steps: |
| 219 | + - uses: actions/checkout@v4 |
| 220 | + with: |
| 221 | + fetch-depth: 0 |
| 222 | + |
| 223 | + - name: Setup Node.js |
| 224 | + uses: actions/setup-node@v4 |
| 225 | + with: |
| 226 | + node-version: '20.x' |
| 227 | + registry-url: 'https://registry.npmjs.org' |
| 228 | + |
| 229 | + - name: Install dependencies |
| 230 | + run: npm install |
| 231 | + |
| 232 | + - name: Update npm for OIDC trusted publishing |
| 233 | + run: node scripts/setup-npm.mjs |
| 234 | + |
| 235 | + - name: Check for changesets |
| 236 | + id: check_changesets |
| 237 | + run: node scripts/check-changesets.mjs |
| 238 | + |
| 239 | + - name: Merge multiple changesets |
| 240 | + if: steps.check_changesets.outputs.has_changesets == 'true' && steps.check_changesets.outputs.changeset_count > 1 |
| 241 | + run: | |
| 242 | + echo "Multiple changesets detected, merging..." |
| 243 | + node scripts/merge-changesets.mjs |
| 244 | +
|
| 245 | + - name: Version packages and commit to main |
| 246 | + if: steps.check_changesets.outputs.has_changesets == 'true' |
| 247 | + id: version |
| 248 | + run: node scripts/version-and-commit.mjs --mode changeset |
| 249 | + |
| 250 | + - name: Publish to npm |
| 251 | + # Run if version was committed OR if a previous attempt already committed (for re-runs) |
| 252 | + if: steps.version.outputs.version_committed == 'true' || steps.version.outputs.already_released == 'true' |
| 253 | + id: publish |
| 254 | + run: node scripts/publish-to-npm.mjs --should-pull |
| 255 | + |
| 256 | + - name: Create GitHub Release |
| 257 | + if: steps.publish.outputs.published == 'true' |
| 258 | + env: |
| 259 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 260 | + run: node scripts/create-github-release.mjs --release-version "${{ steps.publish.outputs.published_version }}" --repository "${{ github.repository }}" |
| 261 | + |
| 262 | + - name: Format GitHub release notes |
| 263 | + if: steps.publish.outputs.published == 'true' |
| 264 | + env: |
| 265 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 266 | + run: node scripts/format-github-release.mjs --release-version "${{ steps.publish.outputs.published_version }}" --repository "${{ github.repository }}" --commit-sha "${{ github.sha }}" |
| 267 | + |
| 268 | + # Manual Instant Release - triggered via workflow_dispatch with instant mode |
| 269 | + # This job is in release.yml because npm trusted publishing |
| 270 | + # only allows one workflow file to be registered as a trusted publisher |
| 271 | + instant-release: |
| 272 | + name: Instant Release |
| 273 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'instant' |
| 274 | + runs-on: ubuntu-latest |
| 275 | + # Permissions required for npm OIDC trusted publishing |
| 276 | + permissions: |
| 277 | + contents: write |
| 278 | + pull-requests: write |
| 279 | + id-token: write |
| 280 | + steps: |
| 281 | + - uses: actions/checkout@v4 |
| 282 | + with: |
| 283 | + fetch-depth: 0 |
| 284 | + |
| 285 | + - name: Setup Node.js |
| 286 | + uses: actions/setup-node@v4 |
| 287 | + with: |
| 288 | + node-version: '20.x' |
| 289 | + registry-url: 'https://registry.npmjs.org' |
| 290 | + |
| 291 | + - name: Install dependencies |
| 292 | + run: npm install |
| 293 | + |
| 294 | + - name: Update npm for OIDC trusted publishing |
| 295 | + run: node scripts/setup-npm.mjs |
| 296 | + |
| 297 | + - name: Version packages and commit to main |
| 298 | + id: version |
| 299 | + run: node scripts/version-and-commit.mjs --mode instant --bump-type "${{ github.event.inputs.bump_type }}" --description "${{ github.event.inputs.description }}" |
| 300 | + |
| 301 | + - name: Publish to npm |
| 302 | + # Run if version was committed OR if a previous attempt already committed (for re-runs) |
| 303 | + if: steps.version.outputs.version_committed == 'true' || steps.version.outputs.already_released == 'true' |
| 304 | + id: publish |
| 305 | + run: node scripts/publish-to-npm.mjs |
| 306 | + |
| 307 | + - name: Create GitHub Release |
| 308 | + if: steps.publish.outputs.published == 'true' |
| 309 | + env: |
| 310 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 311 | + run: node scripts/create-github-release.mjs --release-version "${{ steps.publish.outputs.published_version }}" --repository "${{ github.repository }}" |
| 312 | + |
| 313 | + - name: Format GitHub release notes |
| 314 | + if: steps.publish.outputs.published == 'true' |
| 315 | + env: |
| 316 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 317 | + run: node scripts/format-github-release.mjs --release-version "${{ steps.publish.outputs.published_version }}" --repository "${{ github.repository }}" --commit-sha "${{ github.sha }}" |
| 318 | + |
| 319 | + # Manual Changeset PR - creates a pull request with the changeset for review |
| 320 | + changeset-pr: |
| 321 | + name: Create Changeset PR |
| 322 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'changeset-pr' |
| 323 | + runs-on: ubuntu-latest |
| 324 | + permissions: |
| 325 | + contents: write |
| 326 | + pull-requests: write |
| 327 | + steps: |
| 328 | + - uses: actions/checkout@v4 |
| 329 | + with: |
| 330 | + fetch-depth: 0 |
| 331 | + |
| 332 | + - name: Setup Node.js |
| 333 | + uses: actions/setup-node@v4 |
| 334 | + with: |
| 335 | + node-version: '20.x' |
| 336 | + |
| 337 | + - name: Install dependencies |
| 338 | + run: npm install |
| 339 | + |
| 340 | + - name: Create changeset file |
| 341 | + run: node scripts/create-manual-changeset.mjs --bump-type "${{ github.event.inputs.bump_type }}" --description "${{ github.event.inputs.description }}" |
| 342 | + |
| 343 | + - name: Format changeset with Prettier |
| 344 | + run: | |
| 345 | + # Run Prettier on the changeset file to ensure it matches project style |
| 346 | + npx prettier --write ".changeset/*.md" || true |
| 347 | +
|
| 348 | + echo "Formatted changeset files" |
| 349 | +
|
| 350 | + - name: Create Pull Request |
| 351 | + uses: peter-evans/create-pull-request@v7 |
| 352 | + with: |
| 353 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 354 | + commit-message: 'chore: add changeset for manual ${{ github.event.inputs.bump_type }} release' |
| 355 | + branch: changeset-manual-release-${{ github.run_id }} |
| 356 | + delete-branch: true |
| 357 | + title: 'chore: manual ${{ github.event.inputs.bump_type }} release' |
| 358 | + body: | |
| 359 | + ## Manual Release Request |
| 360 | +
|
| 361 | + This PR was created by a manual workflow trigger to prepare a **${{ github.event.inputs.bump_type }}** release. |
| 362 | +
|
| 363 | + ### Release Details |
| 364 | + - **Type:** ${{ github.event.inputs.bump_type }} |
| 365 | + - **Description:** ${{ github.event.inputs.description || 'Manual release' }} |
| 366 | + - **Triggered by:** @${{ github.actor }} |
| 367 | +
|
| 368 | + ### Next Steps |
| 369 | + 1. Review the changeset in this PR |
| 370 | + 2. Merge this PR to main |
| 371 | + 3. The automated release workflow will create a version PR |
| 372 | + 4. Merge the version PR to publish to npm and create a GitHub release |
0 commit comments