name: Publish to npm on: push: tags: - 'v*' workflow_dispatch: inputs: version: description: '版本号 (例如: v1.9.0)' required: true type: string permissions: contents: write packages: write id-token: write jobs: publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: ref: ${{ github.event.inputs.version || github.ref }} - uses: actions/setup-node@v6 with: node-version: "24" registry-url: "https://registry.npmjs.org" - name: Setup Bun uses: oven-sh/setup-bun@v2 with: bun-version: latest - name: Install dependencies run: bun install --frozen-lockfile - name: Type check run: bun run typecheck - name: Run tests run: bun test - name: Publish to npm run: npm publish --provenance --access public env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Generate changelog id: changelog run: | VERSION="${{ github.event.inputs.version || github.ref_name }}" PREV_TAG=$(git tag --sort=-version:refname | grep -v "^${VERSION#v}$" | head -1) if [ -n "$PREV_TAG" ]; then COMMITS=$(git log "${PREV_TAG}..${VERSION}" --pretty=format:"- %s (%h)" --no-merges) else COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges -20) fi { echo "commits<> "$GITHUB_OUTPUT" - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: name: ${{ github.event.inputs.version || github.ref_name }} body: | ## What's Changed ${{ steps.changelog.outputs.commits }} **Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ github.event.inputs.version || github.ref_name }}^...${{ github.event.inputs.version || github.ref_name }} draft: false prerelease: ${{ contains(github.event.inputs.version || github.ref_name, 'rc') || contains(github.event.inputs.version || github.ref_name, 'beta') || contains(github.event.inputs.version || github.ref_name, 'alpha') }}