Revert "chore: bump version to 0.1.4" #14
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
| # --- | |
| # id: ci/npm-publish | |
| # category: ci | |
| # type: template | |
| # name: NPM Publish | |
| # description: Automatically publish to npm when version changes on main branch. NOTE: NPM_TOKEN is a granular access token (read-write) that expires after 90 days and must be rotated quarterly. | |
| # secrets: | |
| # - name: NPM_TOKEN | |
| # description: NPM granular access token with publish access (read-write tokens expire after 90 days, requires quarterly rotation) | |
| # required: true | |
| # inputs: [] | |
| # triggers: [push] | |
| # variants: | |
| # - name: standard | |
| # description: Publishes when package.json version changes on main branch pushes | |
| # --- | |
| name: NPM Publish | |
| on: | |
| push: | |
| branches: [main] | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| if: github.repository_owner == 'OpenStaticFish' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v1 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Build package | |
| run: bun run build | |
| - name: Check version change | |
| id: check | |
| run: | | |
| # Get the current version from package.json | |
| CURRENT_VERSION=$(jq -r '.version' package.json) | |
| echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| # Get the previous version from the last commit | |
| PREVIOUS_VERSION=$(git show HEAD~1:package.json | jq -r '.version') | |
| echo "previous_version=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT | |
| if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then | |
| echo "version_changed=true" >> $GITHUB_OUTPUT | |
| echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION" | |
| else | |
| echo "version_changed=false" >> $GITHUB_OUTPUT | |
| echo "Version unchanged: $CURRENT_VERSION" | |
| fi | |
| # NOTE: NPM_TOKEN is a granular access token that expires after 90 days. | |
| # Set a calendar reminder to rotate this token every ~80 days. | |
| # Go to npmjs.com → Access Tokens → Generate New Token → Granular Access Token | |
| - name: Publish to npm | |
| if: steps.check.outputs.version_changed == 'true' | |
| env: | |
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: | | |
| echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc | |
| npm publish --access public | |
| - name: Create GitHub Release | |
| if: steps.check.outputs.version_changed == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const version = '${{ steps.check.outputs.current_version }}'; | |
| const tag = `v${version}`; | |
| await github.rest.git.createRef({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| ref: `refs/tags/${tag}`, | |
| sha: context.sha | |
| }); | |
| await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: tag, | |
| name: `Release ${tag}`, | |
| body: `Published version ${version} to npm`, | |
| draft: false, | |
| prerelease: false | |
| }); | |
| - name: Post success comment | |
| if: steps.check.outputs.version_changed == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const version = '${{ steps.check.outputs.current_version }}'; | |
| await github.rest.repos.createCommitComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| commit_sha: context.sha, | |
| body: `🚀 Successfully published version ${version} to npm!\n\nPackage: @openstaticfish/actionflow@${version}` | |
| }); |