From 4d5a4006cf53202b475e4f0c0b5b95c984fdc0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E6=BE=9C?= Date: Thu, 30 Jul 2026 21:13:59 +0800 Subject: [PATCH] ci: use npm trusted publishing --- .github/workflows/publish.yml | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fca9727..acf26aa 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,25 +2,44 @@ name: Publish Package to npmjs on: release: types: [published] + workflow_dispatch: + inputs: + npm_tag: + description: npm distribution tag + required: true + default: beta + type: choice + options: + - beta + - latest + +permissions: + contents: read + id-token: write + jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - # Setup .npmrc file to publish to npm - - uses: actions/setup-node@v4 + - uses: actions/checkout@v6 + - uses: actions/setup-node@v6 with: - node-version: '22.x' + node-version: '24.x' registry-url: 'https://registry.npmjs.org' - cache: npm - run: npm ci - run: npm test - name: Publish package run: | - if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + NPM_TAG="${{ inputs.npm_tag }}" + elif [[ "${{ github.event.release.prerelease }}" == "true" ]]; then + NPM_TAG="beta" + else + NPM_TAG="latest" + fi + + if [[ "$NPM_TAG" == "beta" ]]; then npm publish --tag beta else npm publish fi - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}