name: Release Mentra Developer Tools run-name: >- ${{ github.event_name == 'repository_dispatch' && format('Release Mentra Developer Tools ({0}), request {1}', github.event.client_payload.branch, github.event.client_payload.request) || 'Release Mentra Developer Tools' }} # Publishes developer tooling that is intentionally outside the coordinated # Mentra product family: @mentra/miniapp-cli, create-mentra-miniapp, # @mentra/auth, @mentra/miniapp-tools, and @mentra/cli. The coordinated release workflow exclusively # owns @mentra/miniapp and the Engine dependency closure. # # Channel selection (see .github/scripts/npm-channel.mjs): git holds one # prerelease base version per package (X.Y.Z-dev.N, only edited on dev) and the # branch derives what publishes: # dev -> X.Y.Z-dev.N (dev tag) # staging -> X.Y.Z-beta.N (beta tag) # main -> X.Y.Z (latest tag) # It runs from a manual dispatch on the selected branch, or from a # repository_dispatch `release-developer-tools` whose client_payload names the # branch and the commit to publish (sent when a version changes). Either way, # start it after the coordinated @mentra/miniapp version for that channel is # publicly readable. # A package publishes when its derived version is absent from npm (E404-strict), # so retries are no-ops. First-ever publishes additionally require # force_release=true. # # Publish mode per channel: dev publishes DIRECTLY (fast internal iteration); # beta and latest go through npm's STAGING QUEUE (`npm stage publish`) and a # maintainer must approve each version in the npm UI before it goes live. # # Before packing, manifests are stamped to the channel's derived versions and # ranges (stamp-channel-manifests.mjs), then workspace `file:` deps are # rewritten to exact published versions (rewrite-file-deps.mjs) so wrappers # like @mentra/cli install cleanly for users. # # Publishing uses npm trusted publishing, without a token: each package's npm # settings name this workflow (Mentra-Community/MentraOS, # developer-tools-release.yml, no environment) as its trusted publisher, which # needs a GitHub-hosted runner and npm >= 11.5.1. See sdk/PUBLISHING.md. on: workflow_dispatch: inputs: dry_run: description: "Build + pack but do not publish to npm" required: true default: true type: boolean force_release: description: "Bootstrap first-ever publishes (packages absent from npm never auto-release)." required: true default: false type: boolean repository_dispatch: types: [release-developer-tools] concurrency: group: developer-tools-release-${{ github.event.client_payload.branch || github.ref_name }} cancel-in-progress: false permissions: contents: read # The branch whose channel publishes, and the commit to check out: the # dispatch's, else this run's. The scripts read MENTRA_RELEASE_BRANCH. env: MENTRA_RELEASE_BRANCH: ${{ github.event.client_payload.branch || github.ref_name }} RELEASE_REF: ${{ github.event.client_payload.commit || github.sha }} jobs: detect: name: Detect version changes runs-on: blacksmith-2vcpu-ubuntu-2404 outputs: matrix: ${{ steps.info.outputs.matrix }} has_publishes: ${{ steps.info.outputs.has_publishes }} dry_run: ${{ steps.info.outputs.dry_run }} force_release: ${{ steps.info.outputs.force_release }} steps: - uses: actions/setup-node@v4 with: node-version: "24" - name: Checkout source uses: actions/checkout@v4 # Depth 1 is fine: the decision reads the working tree + the npm # registry, never git history. with: ref: ${{ env.RELEASE_REF }} - name: Check the release branch and commit env: EVENT: ${{ github.event_name }} GH_TOKEN: ${{ github.token }} PAYLOAD_BRANCH: ${{ github.event.client_payload.branch }} PAYLOAD_COMMIT: ${{ github.event.client_payload.commit }} run: | [[ "$MENTRA_RELEASE_BRANCH" =~ ^(dev|staging|main)$ ]] || { echo "::error::No developer-tools channel for branch '$MENTRA_RELEASE_BRANCH'"; exit 1; } # A dispatch names both, or nothing publishes: never the default branch's head. if [[ "$EVENT" == repository_dispatch ]]; then [[ -n "$PAYLOAD_BRANCH" && "$PAYLOAD_COMMIT" =~ ^[0-9a-f]{40}$ ]] || { echo "::error::A release-developer-tools dispatch needs client_payload.branch and a full client_payload.commit"; exit 1; } status=$(gh api "repos/$GITHUB_REPOSITORY/compare/$PAYLOAD_COMMIT...$PAYLOAD_BRANCH" --jq .status) [[ "$status" == ahead || "$status" == identical ]] || { echo "::error::$PAYLOAD_COMMIT is not on $PAYLOAD_BRANCH ($status)"; exit 1; } fi - name: Decide developer-tool releases for this channel id: info run: node .github/scripts/developer-tools-release-info.mjs env: DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run || false }} FORCE_RELEASE: ${{ github.event_name == 'workflow_dispatch' && inputs.force_release || false }} publish: name: Publish ${{ matrix.pkg.name }}@${{ matrix.pkg.version }} needs: detect if: needs.detect.outputs.has_publishes == 'true' # npm trusted publishing accepts only GitHub-hosted runners. runs-on: ubuntu-latest permissions: contents: read id-token: write strategy: # Sequential + dependency-ordered: the scaffolder's template pins # @mentra/miniapp-cli, so it publishes first. # fail-fast: the detect script admits a package on the promise that its # deps publish earlier in this run — if an upstream job fails, later # packages would ship pins to versions that never landed, so the whole # matrix stops. Re-running after a fix is safe: already-published # versions skip. max-parallel: 1 fail-fast: true matrix: pkg: ${{ fromJSON(needs.detect.outputs.matrix) }} steps: - name: Checkout source uses: actions/checkout@v4 with: ref: ${{ env.RELEASE_REF }} - name: Setup Bun uses: oven-sh/setup-bun@v2 with: bun-version: latest - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "20" registry-url: "https://registry.npmjs.org" - name: Use npm with trusted and staged publishing support # Trusted publishing needs npm >=11.5.1; beta/latest publishes go # through npm's staging queue for human approval, and `npm stage # publish` needs npm >=11.15.0. Pin the major so the release path # doesn't pick up whatever npm shipped this morning. run: | npm install -g npm@11 if [[ "$MENTRA_RELEASE_BRANCH" != dev ]]; then npm stage --help >/dev/null 2>&1 || { echo "::error::this npm ($(npm --version)) lacks 'npm stage' — staged publishing needs >=11.15.0."; exit 1; } fi - name: Cache Bun cache uses: actions/cache@v4 with: path: ~/.bun/install/cache key: ${{ runner.os }}-bun-cache-miniapp-sdk-${{ matrix.pkg.installDir }} restore-keys: | ${{ runner.os }}-bun-cache-miniapp-sdk- - name: Install workspace dependencies working-directory: ${{ matrix.pkg.installDir }} run: bun install - name: Build package if: matrix.pkg.buildCmd != '' working-directory: ${{ matrix.pkg.dir }} run: ${{ matrix.pkg.buildCmd }} # After install+build (a frozen install would reject changed version # fields): stamp every channel-released manifest to this branch's derived # versions and cross-package ranges. The later rewrite/stamp steps read # the stamped manifests, so their pins come out channel-correct. This # only mutates the checkout that gets packed/published — never committed. - name: Stamp channel versions run: node .github/scripts/stamp-channel-manifests.mjs # Rewrite workspace `file:` deps to exact published versions so the tarball # installs for end users (no-op for packages without them). - name: "Rewrite workspace file: deps" run: node .github/scripts/rewrite-file-deps.mjs "${{ matrix.pkg.dir }}" - name: Resolve the published Miniapp version for scaffolds if: matrix.pkg.name == 'create-mentra-miniapp' id: miniapp run: | set -euo pipefail case "$MENTRA_RELEASE_BRANCH" in dev) tag=dev ;; staging) tag=beta ;; main) tag=latest ;; *) exit 1 ;; esac version=$(npm view "@mentra/miniapp" "dist-tags.$tag" --json --registry=https://registry.npmjs.org | jq -er .) echo "version=$version" >> "$GITHUB_OUTPUT" # Stamp the scaffolder's template pins to the exact versions being published # this run, so a scaffolded project installs on any channel (the caret pins # in the repo can't reach -dev prereleases). No-op for packages without a # template/package.json. Packed checkout only — never committed. - name: Stamp scaffolder template versions env: MENTRA_MINIAPP_VERSION: ${{ steps.miniapp.outputs.version }} run: node .github/scripts/stamp-template-versions.mjs "${{ matrix.pkg.dir }}" - name: Check npm registry id: registry run: | set -euo pipefail # E404 is the ONLY absence signal; any other npm failure (5xx, # network, auth) fails the job rather than being read as "absent". check_absent() { local spec="$1" out code set +e out=$(npm view "$spec" version --json --registry=https://registry.npmjs.org 2>&1) code=$? set -e if [[ $code -eq 0 ]]; then echo "exists"; return 0; fi if echo "$out" | grep -q '"code": *"E404"' || echo "$out" | grep -q "code E404"; then echo "absent"; return 0 fi echo "::error::npm view '$spec' failed with a non-404 error — refusing to guess registry state." >&2 echo "$out" >&2 return 1 } pkg_state=$(check_absent "${{ matrix.pkg.name }}") echo "package_exists=$([[ "$pkg_state" == "exists" ]] && echo true || echo false)" >> "$GITHUB_OUTPUT" ver_state=$(check_absent "${{ matrix.pkg.name }}@${{ matrix.pkg.version }}") if [[ "$ver_state" == "exists" ]]; then echo "exists=true" >> "$GITHUB_OUTPUT" echo "npm already has ${{ matrix.pkg.name }}@${{ matrix.pkg.version }}; nothing to do." else echo "exists=false" >> "$GITHUB_OUTPUT" fi - name: Pack (dry run) if: steps.registry.outputs.exists != 'true' working-directory: ${{ matrix.pkg.dir }} run: npm pack --dry-run - name: Bootstrap gate — first publish must be supervised # A package that has NEVER been published does not auto-release from a # version bump landing on a branch: its first publish is a deliberate # workflow_dispatch with force_release=true. if: needs.detect.outputs.dry_run != 'true' && steps.registry.outputs.exists != 'true' && steps.registry.outputs.package_exists != 'true' && needs.detect.outputs.force_release != 'true' run: | echo "::notice::${{ matrix.pkg.name }} is not on npm yet — skipping auto-publish. Bootstrap it with a workflow_dispatch (force_release=true)." # Direct publish covers the dev channel (fast internal iteration) and # bootstraps (npm cannot stage a package that does not exist — those are # supervised force_release dispatches anyway). Everything else on # beta/latest goes through the staging queue below. - name: Publish to npm (dev channel / bootstrap) if: needs.detect.outputs.dry_run != 'true' && steps.registry.outputs.exists != 'true' && (env.MENTRA_RELEASE_BRANCH == 'dev' || steps.registry.outputs.package_exists != 'true') && (steps.registry.outputs.package_exists == 'true' || needs.detect.outputs.force_release == 'true') working-directory: ${{ matrix.pkg.dir }} run: npm publish --tag "${{ matrix.pkg.tag }}" --access public - name: Stage for approval (beta/latest channels) if: needs.detect.outputs.dry_run != 'true' && steps.registry.outputs.exists != 'true' && steps.registry.outputs.package_exists == 'true' && env.MENTRA_RELEASE_BRANCH != 'dev' working-directory: ${{ matrix.pkg.dir }} # The tag is immutable once staged, so it must be right here. A staged # version is not live yet (npm view won't list it), so a re-merge before # anyone approves re-attempts the stage — tolerate that one error. run: | set +e out=$(npm stage publish --tag "${{ matrix.pkg.tag }}" --access public 2>&1) code=$? set -e echo "$out" if [[ $code -ne 0 ]]; then if echo "$out" | grep -qi "already"; then echo "::notice::${{ matrix.pkg.name }}@${{ matrix.pkg.version }} is already in the staging queue — approve or reject it in the npm UI." else exit $code fi else echo "::notice::${{ matrix.pkg.name }}@${{ matrix.pkg.version }} staged for '${{ matrix.pkg.tag }}' — a maintainer must approve it in the npm UI before it goes live." fi - name: Summarize if: always() run: | { echo "## ${{ matrix.pkg.name }}" echo "" echo "- Version: \`${{ matrix.pkg.version }}\`" echo "- Dist-tag: \`${{ matrix.pkg.tag }}\`" echo "- Already on npm: \`${{ steps.registry.outputs.exists }}\`" echo "- Dry run: \`${{ needs.detect.outputs.dry_run }}\`" } >> "$GITHUB_STEP_SUMMARY"