|
| 1 | +# Publishes @typetorch/cli to npm when a version tag is pushed: |
| 2 | +# npm version <x.y.z> -m "release %s" && git push origin main --follow-tags |
| 3 | +# The tag must match package.json. `npm publish` runs prepublishOnly (build, bun test, pack smoke test) first, and |
| 4 | +# publishes with provenance. Auth: npm trusted publishing (OIDC; set this repo and workflow as a trusted publisher of |
| 5 | +# @typetorch/cli on npmjs.com), or an NPM_TOKEN repository secret (an automation token) until that is set up. |
| 6 | +# A prerelease version (0.11.0-next.0) goes to the "next" dist-tag; anything else to "latest". |
| 7 | +name: Publish |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + tags: ["v*"] |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write # the GitHub release |
| 15 | + id-token: write # npm provenance and trusted publishing |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: publish |
| 19 | + cancel-in-progress: false |
| 20 | + |
| 21 | +jobs: |
| 22 | + publish: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + environment: npm |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + - uses: ./.github/actions/setup |
| 28 | + - name: npm 11.5+ (trusted publishing) |
| 29 | + run: npm install -g npm@^11.5.1 |
| 30 | + - name: The tag, package.json and npm agree |
| 31 | + id: version |
| 32 | + run: | |
| 33 | + set -euo pipefail |
| 34 | + version=$(node -p "require('./package.json').version") |
| 35 | + name=$(node -p "require('./package.json').name") |
| 36 | + if [ "${GITHUB_REF_NAME}" != "v${version}" ]; then |
| 37 | + echo "::error::tag ${GITHUB_REF_NAME} but package.json is ${version}" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + if npm view "${name}@${version}" version >/dev/null 2>&1; then |
| 41 | + echo "::error::${name}@${version} is already on npm" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + tag=latest |
| 45 | + case "$version" in *-*) tag=next ;; esac |
| 46 | + echo "version=${version}" >> "$GITHUB_OUTPUT" |
| 47 | + echo "tag=${tag}" >> "$GITHUB_OUTPUT" |
| 48 | + - name: Publish |
| 49 | + run: npm publish --provenance --access public --tag "${{ steps.version.outputs.tag }}" |
| 50 | + env: |
| 51 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 52 | + - name: GitHub release |
| 53 | + run: gh release create "${GITHUB_REF_NAME}" --title "${GITHUB_REF_NAME}" --generate-notes ${{ steps.version.outputs.tag == 'next' && '--prerelease' || '' }} |
| 54 | + env: |
| 55 | + GH_TOKEN: ${{ github.token }} |
0 commit comments