ci: add ts shape action (#1849) #254
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: publish | |
| # All npm-publishing flows live in this single file. npm's trusted-publisher | |
| # config for every `@stacks/*` package points at `publish.yml` — renaming this | |
| # file requires updating that config on npmjs.com per package. | |
| # | |
| # release — push to main / workflow_dispatch. | |
| # changesets/action opens/updates the "chore: version packages" | |
| # PR. When that PR is merged, the same action publishes the | |
| # bumped packages to npm under `latest`. `commitMode: github-api` | |
| # gives commits a Verified badge without signing keys in CI. | |
| # | |
| # beta — push to main. | |
| # Snapshot-publishes every push to `@beta`, with versions of the | |
| # form `<next-release>-beta.<N>` (counter scoped to the base | |
| # version, queried from npm). | |
| # | |
| # pr — pull_request. | |
| # Same as `beta` but `@pr` dist-tag and versions of the form | |
| # `<next-release>-pr.<PR#>.<N>`. Sticky-header'd into the PR | |
| # description so reviewers can install the canary build. | |
| # | |
| # Forks never reach the publish step (`is-not-fork` gate from pre-run). | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags-ignore: | |
| - '**' | |
| paths-ignore: | |
| - '**.md' | |
| workflow_dispatch: | |
| inputs: | |
| pr-number: | |
| description: 'PR number to publish a canary build for (leave blank for a normal release dispatch)' | |
| type: string | |
| required: false | |
| default: '' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| id-token: write # npm OIDC trusted publishing | |
| concurrency: ${{ github.workflow }}-${{ github.ref }} | |
| jobs: | |
| pre-run: | |
| uses: ./.github/workflows/pre-run.yml | |
| secrets: inherit | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: pre-run | |
| if: needs.pre-run.outputs.is-not-fork == 'true' && (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.pr-number == '')) | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| - run: npm ci | |
| - name: Create release PR or publish | |
| uses: changesets/action@63a615b9cd06ba9a3e6d13796c7fbcb080a60a0b # v1.8.0 | |
| with: | |
| version: npm run version | |
| publish: npm run release | |
| title: 'chore: version packages' | |
| commit: 'chore: version packages' | |
| commitMode: github-api | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| beta: | |
| runs-on: ubuntu-latest | |
| needs: pre-run | |
| if: needs.pre-run.outputs.is-not-fork == 'true' && github.event_name == 'push' | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| - run: npm ci | |
| - name: Seed dummy changeset if none present | |
| run: | | |
| if ! ls .changeset/*.md 2>/dev/null | grep -vqi readme; then | |
| cat > .changeset/__snapshot.md <<'EOF' | |
| --- | |
| "@stacks/common": patch | |
| --- | |
| snapshot | |
| EOF | |
| fi | |
| - run: npx changeset version | |
| - run: node .github/scripts/snapshot-version.mjs beta | |
| - name: Build packages | |
| run: | | |
| npm run clean --workspaces --if-present | |
| npm run build:cjs --workspaces --if-present | |
| npm run build:esm --workspaces --if-present | |
| npm run build:umd --workspaces --if-present | |
| # NPM_CONFIG_IGNORE_SCRIPTS skips each package's prepublishOnly hook, | |
| # avoiding duplicate test/build work during publish. | |
| - run: npx changeset publish --tag beta --no-git-tag | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_CONFIG_IGNORE_SCRIPTS: 'true' | |
| pr: | |
| runs-on: ubuntu-latest | |
| needs: pre-run | |
| if: needs.pre-run.outputs.is-not-fork == 'true' && github.event_name == 'workflow_dispatch' && inputs.pr-number != '' | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| - run: npm ci | |
| - name: Seed dummy changeset if none present | |
| run: | | |
| if ! ls .changeset/*.md 2>/dev/null | grep -vqi readme; then | |
| cat > .changeset/__snapshot.md <<'EOF' | |
| --- | |
| "@stacks/common": patch | |
| --- | |
| snapshot | |
| EOF | |
| fi | |
| - run: npx changeset version | |
| - id: snapshot | |
| run: node .github/scripts/snapshot-version.mjs pr --pr ${{ inputs.pr-number }} | |
| - name: Build packages | |
| run: | | |
| npm run clean --workspaces --if-present | |
| npm run build:cjs --workspaces --if-present | |
| npm run build:esm --workspaces --if-present | |
| npm run build:umd --workspaces --if-present | |
| - run: npx changeset publish --tag pr --no-git-tag | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_CONFIG_IGNORE_SCRIPTS: 'true' | |
| - name: Update PR sticky header | |
| uses: janniks/pull-request-fixed-header@f41837c1d1cee46efb1481db5b6045748202ff09 # v1.3.0 | |
| with: | |
| header: | | |
| > This PR was published to npm with the version `${{ steps.snapshot.outputs.version }}` (dist-tag `pr`). | |
| > e.g. `npm install @stacks/common@${{ steps.snapshot.outputs.version }} --save-exact` | |
| pr-number: ${{ inputs.pr-number }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |