# Releases new versions on npm with trusted publishing (OIDC). No NPM_TOKEN anywhere. # # Data-only releases publish on their own. Any other release is staged on npm # and waits for Vincent's 2FA approval, with an issue telling him so. The npm # trusted publisher for @vvo/tzdb points at this file (release.yml) and allows # `npm publish` and `npm stage publish`. # # The `release` job runs our dependencies but has no OIDC token: it versions, # tags, creates the GitHub release and packs the tarball. The `publish` job holds # the OIDC token and installs no dependencies: it only runs git, Node and npm on # that tarball. name: Release on: workflow_dispatch: push: branches: - main - next schedule: - cron: "0 14 * * *" # Reset the default token scope, then grant per job. permissions: {} # One release at a time, each pushes a data commit to main concurrency: group: push-to-main jobs: release: runs-on: ubuntu-latest timeout-minutes: 15 permissions: contents: write # commit data updates, push release tags issues: write # comment on released issues pull-requests: write # comment on released pull requests outputs: tarball: ${{ steps.tarball.outputs.name }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10 - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version-file: .node-version package-manager-cache: false # No dependency needs an install script, so none gets to run - run: pnpm install --frozen-lockfile --ignore-scripts - run: pnpm run generate # Never commit or publish data that fails the tests - run: pnpm run lint - run: pnpm test - uses: stefanzweifel/git-auto-commit-action@d0b01107b5db882071f96de5dd4b54961ea93f4c # v7.2.1 with: commit_message: "feat(data): Automatic data update" file_pattern: raw-time-zones.json time-zones-names.json src/tzdb-version.ts src/countries.ts # Versions, tags and creates the GitHub release, packs into release/, does not publish - run: pnpm exec semantic-release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - id: tarball run: | shopt -s nullglob files=(release/*.tgz) if [ "${#files[@]}" -gt 0 ]; then echo "name=$(basename "${files[0]}")" >> "$GITHUB_OUTPUT" fi - if: steps.tarball.outputs.name != '' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: tarball path: release/${{ steps.tarball.outputs.name }} if-no-files-found: error retention-days: 7 publish: needs: release if: needs.release.outputs.tarball != '' runs-on: ubuntu-latest timeout-minutes: 10 permissions: contents: read id-token: write # mint the OIDC token npm exchanges for a publish or stage token issues: write # ask Vincent to approve a staged version steps: # Tags only, to compare the release with what is live on npm. Never installs anything. - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false # Writes the .npmrc pointing at the npm registry. Deliberately without # NODE_AUTH_TOKEN: a token in the environment would take precedence over OIDC. - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: 24 registry-url: https://registry.npmjs.org/ package-manager-cache: false # `npm stage` needs npm >= 11.15 - run: npm install --global --ignore-scripts npm@11.21.2 - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: tarball path: ${{ runner.temp }}/release # Publishes on its own only when every commit since the version live on npm # touched data files and nothing else: same code, lockfile and workflows as # a release that already went out. Anything else waits for Vincent's 2FA. - id: decide run: | version="${TARBALL#vvo-tzdb-}" version="${version%.tgz}" live=$(npm view @vvo/tzdb version) echo "version=$version" >> "$GITHUB_OUTPUT" echo "live=$live" >> "$GITHUB_OUTPUT" git fetch --tags --force --quiet changed=$(git diff --name-only "v$live" "v$version") echo "Changed since v$live:" echo "$changed" other=$(echo "$changed" | grep -vxE 'raw-time-zones\.json|time-zones-names\.json|src/tzdb-version\.ts|src/countries\.ts' || true) # The two TypeScript data files end up in the bundle as code, so every line # must match its generated shape: data only, no statements. bad="" if echo "$changed" | grep -qx 'src/countries\.ts'; then bad+=$(git show "v$version:src/countries.ts" | grep -vxE \ '// Country codes and their time zone names, generated by scripts/generate\.ts|export const countries: Record = \{| [A-Z]{2}: "[A-Za-z0-9_+/ -]+",|\};' || true) fi if echo "$changed" | grep -qx 'src/tzdb-version\.ts'; then bad+=$(git show "v$version:src/tzdb-version.ts" | grep -vxE 'export const tzdbVersion = "[0-9]{4}[a-z]";' || true) fi if [ -n "$bad" ]; then echo "Data files contain lines that are not data:" echo "$bad" fi if [ "$DIST_TAG" = latest ] && [ -n "$changed" ] && [ -z "$other" ] && [ -z "$bad" ]; then echo "mode=publish" >> "$GITHUB_OUTPUT" else echo "mode=stage" >> "$GITHUB_OUTPUT" echo "Needs approval." fi env: TARBALL: ${{ needs.release.outputs.tarball }} DIST_TAG: ${{ github.ref_name == 'next' && 'next' || 'latest' }} - if: steps.decide.outputs.mode == 'publish' run: npm publish "$RUNNER_TEMP/release/$TARBALL" --provenance --tag latest env: TARBALL: ${{ needs.release.outputs.tarball }} - if: steps.decide.outputs.mode == 'stage' run: | npm stage publish "$RUNNER_TEMP/release/$TARBALL" --provenance --tag "$DIST_TAG" gh issue create --repo "$GITHUB_REPOSITORY" \ --title "Approve @vvo/tzdb $VERSION on npm" \ --body "This release changes more than the time zone data, so it is staged on npm and waits for your approval. - Compare: https://github.com/$GITHUB_REPOSITORY/compare/v$LIVE...v$VERSION - Approve: npmjs.com, avatar menu, Staged Packages, or \`npm stage list @vvo/tzdb\` then \`npm stage approve \` Close this issue once it is approved or rejected." env: TARBALL: ${{ needs.release.outputs.tarball }} DIST_TAG: ${{ github.ref_name == 'next' && 'next' || 'latest' }} VERSION: ${{ steps.decide.outputs.version }} LIVE: ${{ steps.decide.outputs.live }} GH_TOKEN: ${{ github.token }}