release: 0.0.5 #10
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' | |
| jobs: | |
| check-version: | |
| name: Check Version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.extract.outputs.version }} | |
| release: ${{ steps.check.outputs.release }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract Version | |
| id: extract | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Package version: $VERSION" | |
| - name: Check Version and Tag | |
| id: check | |
| run: | | |
| VERSION="${{ steps.extract.outputs.version }}" | |
| if [[ "$VERSION" == "0.0.0" ]]; then | |
| echo "release=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # Check if tag already exists | |
| TAG="v$VERSION" | |
| git fetch --all --tags | |
| if git tag -l | grep -q "^$TAG$"; then | |
| echo "Tag $TAG already exists." | |
| echo "release=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Tag $TAG does not exist. Will create." | |
| echo "release=true" >> $GITHUB_OUTPUT | |
| fi | |
| release: | |
| name: Release Package | |
| needs: check-version | |
| if: needs.check-version.outputs.release == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22.x" | |
| cache: "npm" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Install Dependencies | |
| run: npm ci | |
| - name: Build Package | |
| run: npm run build | |
| - name: Push Tag | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git tag -a "v${{ needs.check-version.outputs.version }}" -m "Release v${{ needs.check-version.outputs.version }}" | |
| git push origin "v${{ needs.check-version.outputs.version }}" | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ needs.check-version.outputs.version }} | |
| name: Release v${{ needs.check-version.outputs.version }} | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish to NPM | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |