|
| 1 | +# Publishes @typetorch/framework 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 (a clean `rbxtsc --type package` into out/) first. |
| 4 | +# Auth: npm trusted publishing (on npmjs.com, @typetorch/framework > Settings > Trusted publishing: this repo, workflow |
| 5 | +# publish.yml, environment npm), or an NPM_TOKEN secret (an automation token) on this repo until that is set up. |
| 6 | +# Same flow as typetorch/cli. A prerelease version (x.y.z-next.0) goes to the "next" dist-tag; anything else to |
| 7 | +# "latest". |
| 8 | +name: Publish |
| 9 | + |
| 10 | +on: |
| 11 | + push: |
| 12 | + tags: ["v*"] |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write # the GitHub release |
| 16 | + id-token: write # npm provenance and trusted publishing |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: publish |
| 20 | + cancel-in-progress: false |
| 21 | + |
| 22 | +jobs: |
| 23 | + publish: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + environment: npm |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + - uses: oven-sh/setup-bun@v2 |
| 29 | + with: |
| 30 | + bun-version: 1.4.2 |
| 31 | + - name: Dependencies |
| 32 | + run: bun install --frozen-lockfile |
| 33 | + - uses: actions/setup-node@v4 |
| 34 | + with: |
| 35 | + node-version: 22 |
| 36 | + registry-url: https://registry.npmjs.org |
| 37 | + - name: npm 11.5+ (trusted publishing) |
| 38 | + run: npm install -g npm@^11.5.1 |
| 39 | + - name: The tag, package.json and npm agree |
| 40 | + id: version |
| 41 | + run: | |
| 42 | + set -euo pipefail |
| 43 | + version=$(node -p "require('./package.json').version") |
| 44 | + name=$(node -p "require('./package.json').name") |
| 45 | + if [ "${GITHUB_REF_NAME}" != "v${version}" ]; then |
| 46 | + echo "::error::tag ${GITHUB_REF_NAME} but package.json is ${version}" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + if npm view "${name}@${version}" version >/dev/null 2>&1; then |
| 50 | + echo "::error::${name}@${version} is already on npm" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + tag=latest |
| 54 | + case "$version" in *-*) tag=next ;; esac |
| 55 | + echo "version=${version}" >> "$GITHUB_OUTPUT" |
| 56 | + echo "tag=${tag}" >> "$GITHUB_OUTPUT" |
| 57 | + - name: Publish |
| 58 | + run: npm publish --provenance --access public --tag "${{ steps.version.outputs.tag }}" |
| 59 | + env: |
| 60 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 61 | + - name: GitHub release |
| 62 | + run: gh release create "${GITHUB_REF_NAME}" --title "${GITHUB_REF_NAME}" --generate-notes ${{ steps.version.outputs.tag == 'next' && '--prerelease' || '' }} |
| 63 | + env: |
| 64 | + GH_TOKEN: ${{ github.token }} |
0 commit comments