feat: 正式发布 #21
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Release tag to publish, for example v0.1.0" | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| name: Build GitHub Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ inputs.tag || github.ref }} | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: "1.23" | |
| cache: true | |
| - name: Verify package version matches tag | |
| run: | | |
| TAG="${{ inputs.tag || github.ref_name }}" | |
| PACKAGE_VERSION="$(node -p "require('./package.json').version")" | |
| if [ "$TAG" != "v$PACKAGE_VERSION" ]; then | |
| echo "Tag $TAG does not match package.json version $PACKAGE_VERSION" | |
| exit 1 | |
| fi | |
| - name: Run Go tests | |
| run: go test ./... | |
| - name: Run GoReleaser | |
| uses: goreleaser/goreleaser-action@v6 | |
| with: | |
| distribution: goreleaser | |
| version: latest | |
| args: release --clean | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download release checksums for npm package | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TAG: ${{ inputs.tag || github.ref_name }} | |
| run: gh release download "$TAG" --pattern checksums.txt --clobber | |
| - name: Set up Node.js for npm publish | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Publish npm package | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: | | |
| PACKAGE_VERSION="$(node -p "require('./package.json').version")" | |
| if [[ "$PACKAGE_VERSION" == *-* ]]; then | |
| npm publish --access public --tag beta | |
| else | |
| npm publish --access public | |
| fi |