# Publishes @hatk/hatk to npm, under the `alpha` tag, when main's version has # not been published yet. Bump `version` in packages/hatk/package.json in a # pull; once it lands, this publishes it. A version on npm already is left # alone, so the run passes at once. # # It runs the checks itself before publishing rather than waiting on ci's, so # nothing is published from a commit that does not pass them. # # NPM_TOKEN is an npm granular access token that may publish @hatk/hatk, # granted to pushes to main alone in the runner's secrets file. Asked for on # any other branch, # knotless rerun knotless://chadtmiller.com/hatk --ref refs/heads/ --workflow release # it checks and packs everything and publishes nothing, to try it. on: push: { refs: [refs/heads/main], paths: [packages/hatk/package.json] } asked: { refs: [refs/heads/*] } superseded: finish image: node:26-trixie cache: [/root/.npm] secrets: [NPM_TOKEN] steps: - name: version run: | version=$(node -p 'require("./packages/hatk/package.json").version') echo "$version" > ~/.version if [ -n "$(npm view "@hatk/hatk@$version" version 2>/dev/null)" ]; then echo "@hatk/hatk@$version is published already" touch ~/.done elif [ "$KNOTLESS_RUN_REF" != refs/heads/main ]; then echo "on $KNOTLESS_RUN_REF: checking $version, publishing nothing" else echo "publishing @hatk/hatk@$version" fi - name: install run: | [ ! -e ~/.done ] || exit 0 npm ci - name: check run: | [ ! -e ~/.done ] || exit 0 npm run check - name: test timeout: 30 run: | [ ! -e ~/.done ] || exit 0 npm test - name: publish run: | [ ! -e ~/.done ] || exit 0 if [ "$KNOTLESS_RUN_REF" != refs/heads/main ]; then npm publish -w @hatk/hatk --tag alpha --dry-run exit 0 fi [ -n "$NPM_TOKEN" ] || { echo "NPM_TOKEN is not granted: not publishing"; exit 1; } echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc npm publish -w @hatk/hatk --tag alpha rm ~/.npmrc