Publish to NPM #13
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 to NPM | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release-type: | |
| description: 'Release type' | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| - prepatch | |
| - preminor | |
| - premajor | |
| - prerelease | |
| default: 'patch' | |
| prerelease-id: | |
| description: 'Prerelease identifier (beta, alpha, rc, etc.)' | |
| required: false | |
| default: 'rc' | |
| dist-tag: | |
| description: 'NPM dist-tag' | |
| required: true | |
| type: choice | |
| options: | |
| - latest | |
| - beta | |
| - alpha | |
| - next | |
| - canary | |
| default: 'latest' | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v1 | |
| with: | |
| bun-version: latest | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Bump version | |
| id: version | |
| run: | | |
| # Determine version bump command | |
| if [[ "${{ inputs.release-type }}" == pre* ]]; then | |
| NEW_VERSION=$(npm version ${{ inputs.release-type }} --preid=${{ inputs.prerelease-id }} --no-git-tag-version) | |
| else | |
| NEW_VERSION=$(npm version ${{ inputs.release-type }} --no-git-tag-version) | |
| fi | |
| # Remove 'v' prefix for output | |
| VERSION=${NEW_VERSION#v} | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "📦 New version: $VERSION" | |
| - name: Build package | |
| run: bun run build | |
| - name: Generate Changelog | |
| run: bun run changelog | |
| - name: Publish to NPM | |
| run: | | |
| if [ "${{ inputs.dist-tag }}" == "latest" ]; then | |
| npm publish --provenance --access public | |
| else | |
| npm publish --provenance --access public --tag ${{ inputs.dist-tag }} | |
| fi | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Commit version bump | |
| run: | | |
| git add package.json CHANGELOG.md | |
| git commit -m "chore(release): bump version to ${{ steps.version.outputs.version }}" | |
| - name: Create Git Tag | |
| run: | | |
| git tag -a ${{ steps.version.outputs.tag }} -m "Release ${{ steps.version.outputs.version }}" | |
| - name: Push changes | |
| run: | | |
| git push origin HEAD:master | |
| git push origin ${{ steps.version.outputs.tag }} | |
| - name: Create GitHub Release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.version.outputs.tag }} | |
| release_name: Release ${{ steps.version.outputs.version }} | |
| body: | | |
| ## 🚀 Release ${{ steps.version.outputs.version }} | |
| **Release Type:** ${{ inputs.release-type }} | |
| **Dist Tag:** ${{ inputs.dist-tag }} | |
| ### Installation | |
| ```bash | |
| npm install moicle@${{ steps.version.outputs.version }} | |
| ``` | |
| ### Changes | |
| See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/master/CHANGELOG.md) for details. | |
| draft: false | |
| prerelease: ${{ inputs.dist-tag != 'latest' }} |