# Publishes unity-types to npm through trusted publishing (OIDC), so no npm # token exists anywhere: not in repository secrets, not on a laptop. GitHub # mints a short-lived token for this one workflow, npm verifies it against the # trusted publisher registered in the package settings, and provenance is # attached automatically. # # The filename matters. npm matches "publish.yml" literally against the trusted # publisher entry, so renaming this file breaks publishing until the entry on # npmjs.com is deleted and recreated (entries cannot be edited). name: Publish on: push: tags: - "v*" permissions: # The OIDC token npm authenticates with. Without this the publish fails with # ENEEDAUTH and nothing else in the file matters. id-token: write contents: read concurrency: # Deliberately not cancel-in-progress: cancelling a half-finished publish is # worse than letting two tags queue behind each other. group: publish-${{ github.ref }} cancel-in-progress: false jobs: publish: name: publish to npm runs-on: ubuntu-latest steps: # A single checkout: unity-types is hand-written .d.ts files with no # dependencies of its own. It is what the other packages sit beside, not # the other way round. - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: # Trusted publishing needs Node >= 22.14.0 and an npm that speaks # OIDC. This repo has no ci.yml to stay in step with. node-version: 24 registry-url: "https://registry.npmjs.org" # No dependency cache in a release build. # Node's bundled npm drifts, and the floor here is exact: 11.5.1 for # trusted publishing, 11.15.0 for `npm stage publish`. A floor, not a # pin: ">=" keeps taking new majors, where "^11.15.0" would quietly hold # the workflow on npm 11 for as long as nobody reread this line. - name: Ensure npm supports trusted publishing run: npm install -g "npm@>=11.15.0" # The tag is the only thing a human types during a release, so it is the # only thing that can disagree with package.json. Catch it here rather # than discovering v6000.5.1 on the registry as 6000.5.0. - name: Check the tag matches package.json run: | tag_version="${GITHUB_REF_NAME#v}" pkg_version="$(node -p "require('./package.json').version")" if [ "$tag_version" != "$pkg_version" ]; then echo "Tag $GITHUB_REF_NAME is version $tag_version, package.json is $pkg_version." >&2 exit 1 fi echo "Publishing $pkg_version" # Installs the TypeScript the typecheck below compiles with, the package's # only dependency and a dev one, so nothing is added to what it ships. - run: npm install --no-audit --no-fund # Every gate is --if-present. typecheck compiles test/ against the # declarations; the other three are no-ops until a script is added, and # one added later starts gating without anyone editing this file. - run: npm run typecheck --if-present - run: npm run lint --if-present - run: npm run build --if-present - run: npm run test --if-present # No --provenance flag and no NODE_AUTH_TOKEN: npm detects the OIDC # environment, authenticates with it, and attaches provenance by itself # for a public package from a public repo. # # This needs the trusted publisher on npmjs.com to allow the "npm publish" # action. Entries created since 3 September 2026 allow only "npm stage # publish" unless direct publishing is ticked; with a stage-only entry # this step fails with E_STAGE_REQUIRED. To take the safer route instead, # change this one line to `npm stage publish` and approve each release # with 2FA from the Staged Packages tab on npmjs.com. - run: npm publish