Repository navigation
chore: migrate format and lint to oxc toolchain #11
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: Release | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'package.json' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| tag: | |
| name: Create tag from version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version_changed: ${{ steps.version.outputs.changed }} | |
| version: ${{ steps.version.outputs.current }} | |
| tag_name: ${{ format('v{0}', steps.version.outputs.current) }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Detect package version change | |
| id: version | |
| run: | | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| BEFORE_SHA="${{ github.event.before }}" | |
| if [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then | |
| PREVIOUS_VERSION="" | |
| else | |
| PREVIOUS_VERSION=$(git show "$BEFORE_SHA:package.json" 2>/dev/null | node -e "const fs = require('fs'); const input = fs.readFileSync(0, 'utf8'); try { process.stdout.write(String(JSON.parse(input).version ?? '')) } catch { process.stdout.write('') }") | |
| fi | |
| if [ "$CURRENT_VERSION" = "$PREVIOUS_VERSION" ]; then | |
| VERSION_CHANGED=false | |
| else | |
| VERSION_CHANGED=true | |
| fi | |
| echo "current=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "previous=$PREVIOUS_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "changed=$VERSION_CHANGED" >> "$GITHUB_OUTPUT" | |
| - name: Check tag existence | |
| if: steps.version.outputs.changed == 'true' | |
| id: tag | |
| run: | | |
| TAG_NAME="v${{ steps.version.outputs.current }}" | |
| if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then | |
| TAG_EXISTS=true | |
| elif git ls-remote --exit-code --tags origin "refs/tags/$TAG_NAME" >/dev/null 2>&1; then | |
| TAG_EXISTS=true | |
| else | |
| TAG_EXISTS=false | |
| fi | |
| echo "name=$TAG_NAME" >> "$GITHUB_OUTPUT" | |
| echo "exists=$TAG_EXISTS" >> "$GITHUB_OUTPUT" | |
| - name: Create and push tag | |
| if: steps.version.outputs.changed == 'true' && steps.tag.outputs.exists != 'true' | |
| run: | | |
| TAG_NAME="${{ steps.tag.outputs.name }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git tag "$TAG_NAME" "${GITHUB_SHA}" | |
| git push origin "$TAG_NAME" | |
| - name: Skip when version is unchanged | |
| if: steps.version.outputs.changed != 'true' | |
| run: echo "package.json version unchanged; skip tag creation." | |
| - name: Skip when tag already exists | |
| if: steps.version.outputs.changed == 'true' && steps.tag.outputs.exists == 'true' | |
| run: echo "Tag ${{ steps.tag.outputs.name }} already exists; skip tag creation." | |
| publish: | |
| name: Publish to npm | |
| if: needs.tag.outputs.version_changed == 'true' | |
| needs: tag | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: pnpm/action-setup@v2 | |
| with: | |
| version: 9 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| registry-url: 'https://registry.npmjs.org/' | |
| - name: Install ripgrep | |
| run: sudo apt-get update && sudo apt-get install -y ripgrep | |
| - run: pnpm install | |
| - run: pnpm run build | |
| - name: Check if npm version exists | |
| id: npm | |
| run: | | |
| PACKAGE_NAME=$(node -p "require('./package.json').name") | |
| PACKAGE_VERSION="${{ needs.tag.outputs.version }}" | |
| if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" version >/dev/null 2>&1; then | |
| echo "already_published=true" >> "$GITHUB_OUTPUT" | |
| echo "Version ${PACKAGE_NAME}@${PACKAGE_VERSION} already exists on npm; skip publish." | |
| else | |
| echo "already_published=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Publish to npm | |
| if: steps.npm.outputs.already_published != 'true' | |
| run: pnpm publish --no-git-checks | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |