chore: release v0.3.2 (#16) #19
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 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| concurrency: | |
| group: publish-main | |
| cancel-in-progress: false | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Read package metadata | |
| id: pkg | |
| run: | | |
| PKG_NAME=$(node -p "require('./package.json').name") | |
| PKG_VERSION=$(node -p "require('./package.json').version") | |
| echo "name=$PKG_NAME" >> "$GITHUB_OUTPUT" | |
| echo "version=$PKG_VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Check published version | |
| id: npm | |
| run: | | |
| if npm view "${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }}" version >/dev/null 2>&1; then | |
| echo "exists=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "exists=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Install | |
| if: steps.npm.outputs.exists == 'false' && success() | |
| run: bun install --ignore-scripts | |
| - name: Build | |
| if: steps.npm.outputs.exists == 'false' && success() | |
| run: bun run build | |
| - name: Test | |
| if: steps.npm.outputs.exists == 'false' && success() | |
| run: bun test | |
| - name: Publish | |
| if: steps.npm.outputs.exists == 'false' && success() | |
| run: npm publish --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create tag | |
| if: steps.npm.outputs.exists == 'false' && success() | |
| uses: actions/github-script@v7 | |
| env: | |
| TAG_NAME: v${{ steps.pkg.outputs.version }} | |
| with: | |
| script: | | |
| const { owner, repo } = context.repo | |
| const tag = process.env.TAG_NAME | |
| try { | |
| await github.rest.git.getRef({ owner, repo, ref: `tags/${tag}` }) | |
| core.info(`tag already exists: ${tag}`) | |
| return | |
| } catch (error) { | |
| if (error.status !== 404) throw error | |
| } | |
| await github.rest.git.createRef({ | |
| owner, | |
| repo, | |
| ref: `refs/tags/${tag}`, | |
| sha: context.sha, | |
| }) | |
| core.info(`tag created: ${tag}`) | |
| - name: Create GitHub Release | |
| if: steps.npm.outputs.exists == 'false' && success() | |
| uses: actions/github-script@v7 | |
| env: | |
| TAG_NAME: v${{ steps.pkg.outputs.version }} | |
| with: | |
| script: | | |
| const { owner, repo } = context.repo | |
| const tag = process.env.TAG_NAME | |
| try { | |
| await github.rest.repos.getReleaseByTag({ owner, repo, tag }) | |
| core.info(`release already exists: ${tag}`) | |
| return | |
| } catch (error) { | |
| if (error.status !== 404) throw error | |
| } | |
| await github.rest.repos.createRelease({ | |
| owner, | |
| repo, | |
| tag_name: tag, | |
| name: tag, | |
| generate_release_notes: true, | |
| }) | |
| core.info(`release created: ${tag}`) |