Publish Release #4
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: Publish Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_tag: | |
| description: "Release tag (e.g., v0.1.0)" | |
| required: true | |
| type: string | |
| release_notes: | |
| description: "Release notes content (markdown supported)" | |
| required: true | |
| type: string | |
| prerelease: | |
| description: "Mark as pre-release" | |
| required: false | |
| type: boolean | |
| default: false | |
| draft: | |
| description: "Create as draft release" | |
| required: false | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write | |
| id-token: write | |
| jobs: | |
| prepare: | |
| name: Prepare Release | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Create and push release tag | |
| run: | | |
| RELEASE_TAG="${{ github.event.inputs.release_tag }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| if ! git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then | |
| echo "Creating new tag: $RELEASE_TAG" | |
| git tag -a "$RELEASE_TAG" -m "Release $RELEASE_TAG" | |
| git push origin "$RELEASE_TAG" | |
| else | |
| echo "Tag $RELEASE_TAG already exists" | |
| fi | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| RELEASE_TAG="${{ github.event.inputs.release_tag }}" | |
| VERSION=${RELEASE_TAG#v} | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Setting version to: $VERSION" | |
| - name: Save release notes | |
| run: | | |
| cat << 'EOF' > release_notes.md | |
| ${{ github.event.inputs.release_notes }} | |
| EOF | |
| - name: Upload release notes artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-notes | |
| path: release_notes.md | |
| publish: | |
| name: Publish to npm | |
| runs-on: ubuntu-latest | |
| needs: prepare | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.inputs.release_tag }} | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| registry-url: https://registry.npmjs.org | |
| - run: npm install | |
| - name: Set package version | |
| run: npm version "${{ needs.prepare.outputs.version }}" --no-git-tag-version | |
| - name: Verify package | |
| run: npm pack --dry-run | |
| - name: Publish to npm | |
| run: npm publish --access public | |
| - name: Download release notes | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: release-notes | |
| path: /tmp/release | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh release create "${{ github.event.inputs.release_tag }}" \ | |
| --title "${{ github.event.inputs.release_tag }}" \ | |
| --notes-file /tmp/release/release_notes.md \ | |
| ${{ github.event.inputs.draft == 'true' && '--draft' || '' }} \ | |
| ${{ github.event.inputs.prerelease == 'true' && '--prerelease' || '' }} |