only reload local-server on src changes, and improve logic around inv… #24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| concurrency: | |
| group: publish | |
| cancel-in-progress: false | |
| jobs: | |
| prepare_release_pr: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22 | |
| package-manager-cache: false | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run checks | |
| run: npm run check | |
| - name: Create or update release PR | |
| uses: changesets/action@v1 | |
| with: | |
| commit: "chore: version packages" | |
| title: "chore: version packages" | |
| version: npm run version-packages | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| detect_publish: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| needs: prepare_release_pr | |
| permissions: | |
| contents: read | |
| outputs: | |
| should_publish: ${{ steps.detect.outputs.should_publish }} | |
| local_version: ${{ steps.detect.outputs.local_version }} | |
| registry_version: ${{ steps.detect.outputs.registry_version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22 | |
| package-manager-cache: false | |
| - name: Detect pending npm publish | |
| id: detect | |
| shell: bash | |
| run: | | |
| node --input-type=module <<'EOF' | |
| import { readFileSync, appendFileSync } from "node:fs"; | |
| const packageJson = JSON.parse( | |
| readFileSync("packages/blr/package.json", "utf8"), | |
| ); | |
| const packageName = packageJson.name; | |
| const localVersion = packageJson.version; | |
| let registryVersion = ""; | |
| try { | |
| const response = await fetch( | |
| `https://registry.npmjs.org/${encodeURIComponent(packageName)}/latest`, | |
| ); | |
| if (response.ok) { | |
| const payload = await response.json(); | |
| registryVersion = String(payload.version ?? ""); | |
| } else if (response.status !== 404) { | |
| throw new Error( | |
| `npm registry lookup failed with ${response.status} ${response.statusText}`, | |
| ); | |
| } | |
| } catch (error) { | |
| console.error( | |
| `[release] Failed to determine npm registry version: ${error instanceof Error ? error.message : String(error)}`, | |
| ); | |
| process.exit(1); | |
| } | |
| const shouldPublish = localVersion !== registryVersion; | |
| console.log( | |
| `[release] local=${localVersion} registry=${registryVersion || "<missing>"} should_publish=${shouldPublish}`, | |
| ); | |
| const outputPath = process.env.GITHUB_OUTPUT; | |
| if (!outputPath) { | |
| throw new Error("GITHUB_OUTPUT is not set."); | |
| } | |
| appendFileSync(outputPath, `local_version=${localVersion}\n`); | |
| appendFileSync(outputPath, `registry_version=${registryVersion}\n`); | |
| appendFileSync(outputPath, `should_publish=${shouldPublish}\n`); | |
| EOF | |
| publish_package: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| needs: detect_publish | |
| if: needs.detect_publish.outputs.should_publish == 'true' | |
| environment: release | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| package-manager-cache: false | |
| registry-url: https://registry.npmjs.org | |
| - name: Report publish toolchain | |
| run: | | |
| node --version | |
| npm --version | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run checks | |
| run: npm run check | |
| - name: Publish package | |
| run: npm run release |