# This file must be named release.yml: npm's Trusted Publishing configuration # for our packages allows a single workflow filename, shared across branches. name: Release on: push: branches: [main] # Manually recompile the preview templates for the versions already # published from the selected ref, without publishing anything to npm workflow_dispatch: concurrency: # Hardcoded so a workflow_dispatch from any ref queues behind releases # instead of racing their force-push to dist group: release # Queue runs instead of cancelling: a cancel that lands between npm # publish and tag creation strands state a rerun cannot rebuild. Without # `queue: max`, a newer push would still replace a pending publish run cancel-in-progress: false queue: max jobs: release: name: Release runs-on: ubuntu-latest # A hung run would hold the release concurrency group timeout-minutes: 30 if: github.event_name == 'push' && github.repository_owner == 'shopify' permissions: contents: write # push the version branch and create git tags pull-requests: write # open and update the version PR id-token: write # generate an ID token for npm Trusted Publishing env: npm_config_registry: https://registry.npmjs.org/ TURBO_TELEMETRY_DISABLED: "1" outputs: published: ${{ steps.changesets.outputs.published }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: # Changesets needs full history to generate changelogs with the correct commits fetch-depth: 0 - uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 with: version: 10.33.0 - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 with: node-version-file: package.json cache: pnpm - name: Install dependencies run: pnpm install --frozen-lockfile - name: Ensure Hydrogen changesets map onto CalVer run: node scripts/calver.ts check - name: Resolve release title id: title # "[ci] release 2026.10.1" when Hydrogen releases, "[ci] release semver" otherwise. # The assignment is separate so a failing `next` fails the step run: | next=$(node scripts/calver.ts next) echo "title=[ci] release $next" >> "$GITHUB_OUTPUT" - name: Build packages run: pnpm run build:pkgs - name: Create release PR or publish id: changesets # v2 of the action is required for changesets v3: it detects published # packages through the CHANGESETS_OUTPUT file instead of parsing the # "New tag:" stdout lines that v3 no longer prints. With v1.7.0 the # `published` output stayed "false" after a successful npm publish, # which skipped compile-preview-templates and the tag/release push uses: changesets/action@198f833dd7d863100ea6e28967bc9a9fdefadb0a # v2.1.0 with: # Runs `changeset version`, then rewrites Hydrogen's semver bump to CalVer version-script: pnpm run version-packages publish-script: pnpm changeset publish commit-message: ${{ steps.title.outputs.title }} pr-title: ${{ steps.title.outputs.title }} github-token: ${{ secrets.SHOPIFY_GH_ACCESS_TOKEN }} compile-preview-templates: name: Compile Preview Templates needs: release # `!cancelled()` lets this run on workflow_dispatch, where release is # skipped and would otherwise skip every job that needs it if: >- !cancelled() && github.repository_owner == 'shopify' && (needs.release.outputs.published == 'true' || github.event_name == 'workflow_dispatch') runs-on: ubuntu-latest timeout-minutes: 30 permissions: contents: read env: npm_config_registry: https://registry.npmjs.org/ TURBO_TELEMETRY_DISABLED: "1" steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: # Keep the write token unavailable while installing and building template dependencies. persist-credentials: false - uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 with: version: 10.33.0 - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 with: node-version-file: package.json registry-url: "https://registry.npmjs.org" cache: pnpm - name: Install dependencies run: pnpm install --frozen-lockfile - name: Resolve published versions id: version # The templates pin the workspace versions of Hydrogen and MiniOxygen, # which match npm once a release has published. A MiniOxygen-only # release therefore recompiles against the current Hydrogen version. # The prepare and validate steps assert Hydrogen's is a stable version run: | echo "hydrogen=$(node -p "require('./packages/hydrogen/package.json').version")" >> "$GITHUB_OUTPUT" echo "mini_oxygen=$(node -p "require('./packages/mini-oxygen/package.json').version")" >> "$GITHUB_OUTPUT" - name: Wait for the published packages env: HYDROGEN_VERSION: ${{ steps.version.outputs.hydrogen }} MINI_OXYGEN_VERSION: ${{ steps.version.outputs.mini_oxygen }} run: | for spec in "@shopify/hydrogen@$HYDROGEN_VERSION" "@shopify/mini-oxygen@$MINI_OXYGEN_VERSION"; do version="${spec##*@}" found=false for attempt in $(seq 1 24); do if [ "$(npm view "$spec" version 2>/dev/null || true)" = "$version" ]; then echo "Found $spec" found=true break fi echo "Waiting for $spec ($attempt/24)" sleep 5 done if [ "$found" != true ]; then echo "$spec was not available after 120 seconds" exit 1 fi done - name: Prepare preview templates run: pnpm prepare:preview-dist "${{ steps.version.outputs.hydrogen }}" - name: Stage standalone templates run: | dist_root="$RUNNER_TEMP/preview-template-dist" rm -rf "$dist_root" mkdir -p "$dist_root" tar \ --exclude='*/node_modules' \ --exclude='*/dist' \ --exclude='*/.next' \ --exclude='*/.turbo' \ --exclude='*/.react-router' \ --exclude='*/.env' \ -C templates -cf - react-router | tar -C "$dist_root" -xf - echo "DIST_ROOT=$dist_root" >> "$GITHUB_ENV" - name: Generate React Router lockfile run: | cd "$DIST_ROOT/react-router" npm_version=$(node -p "require('./package.json').packageManager.split('@').at(-1)") npx --yes "npm@$npm_version" install --package-lock-only --ignore-scripts --no-audit --no-fund cp package-lock.json "$GITHUB_WORKSPACE/templates/react-router/package-lock.json" - name: Validate preview templates run: pnpm validate:preview-dist "${{ steps.version.outputs.hydrogen }}" - name: Test standalone templates run: | cd "$DIST_ROOT/react-router" npm_version=$(node -p "require('./package.json').packageManager.split('@').at(-1)") npx --yes "npm@$npm_version" ci --no-audit --no-fund npm run build - name: Update dist env: DIST_PUSH_TOKEN: ${{ secrets.SHOPIFY_GH_ACCESS_TOKEN }} HYDROGEN_VERSION: ${{ steps.version.outputs.hydrogen }} MINI_OXYGEN_VERSION: ${{ steps.version.outputs.mini_oxygen }} SOURCE_SHA: ${{ github.sha }} run: | git add -u git add templates/react-router/.agents/skills templates/react-router/.claude/skills git add --force templates/react-router/package-lock.json git diff --cached --check -- templates/react-router/package.json unexpected_paths=$(git diff --cached --name-only | grep -Ev '^templates/react-router/((\.agents|\.claude)/skills/.*|__test__/.*|package\.json|package-lock\.json)$' || true) if [ -n "$unexpected_paths" ]; then echo "Unexpected compiled changes:" echo "$unexpected_paths" exit 1 fi git status --short export GIT_AUTHOR_NAME="Hydrogen Bot" export GIT_AUTHOR_EMAIL="hydrogen@shopify.com" export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL" tree=$(git write-tree) commit=$(printf 'Update preview templates for @shopify/hydrogen@%s and @shopify/mini-oxygen@%s\n\nSource: %s\n' "$HYDROGEN_VERSION" "$MINI_OXYGEN_VERSION" "$SOURCE_SHA" | git commit-tree "$tree") auth=$(printf 'x-access-token:%s' "$DIST_PUSH_TOKEN" | base64 | tr -d '\n') git -c http.https://github.com/.extraheader="AUTHORIZATION: basic $auth" \ push origin "$commit:refs/heads/dist" --force