Merge pull request #8 from EricLLLLLL/test #71
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: Production Release | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| jobs: | |
| check-and-publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install Bun | |
| uses: oven-sh/setup-bun@v1 | |
| with: | |
| bun-version: 'latest' | |
| - name: Check NPM & Determine Release | |
| id: check | |
| run: | | |
| VERSION=$(grep -oE '"version": "[^"]+"' package.json | cut -d'"' -f4) | |
| TAG_NAME="v$VERSION" | |
| PACKAGE_NAME=$(grep -oE '"name": "[^"]+"' package.json | cut -d'"' -f4) | |
| echo "Checking registry for $PACKAGE_NAME@$VERSION..." | |
| NPM_VERSION=$(npm view "$PACKAGE_NAME@$VERSION" version 2>/dev/null || echo "not_found") | |
| if [ "$NPM_VERSION" == "$VERSION" ]; then | |
| echo "✅ Version $VERSION already exists on NPM. Skipping release." | |
| echo "should_release=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "🚀 Version $VERSION not found on NPM. Preparing release." | |
| echo "should_release=true" >> $GITHUB_OUTPUT | |
| echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Install Dependencies | |
| if: steps.check.outputs.should_release == 'true' | |
| run: bun install | |
| - name: Run Integrity Check | |
| if: steps.check.outputs.should_release == 'true' | |
| run: bun run check-integrity | |
| - name: Build Project | |
| if: steps.check.outputs.should_release == 'true' | |
| run: bun run build | |
| - name: Calculate Fingerprints | |
| if: steps.check.outputs.should_release == 'true' | |
| run: bun run scripts/fingerprint.ts | |
| - name: Publish to NPM | |
| if: steps.check.outputs.should_release == 'true' | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: | | |
| echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc | |
| npm publish --access public | |
| rm .npmrc | |
| - name: Create Git Tag | |
| if: steps.check.outputs.should_release == 'true' | |
| continue-on-error: true | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| # Force tag update if it exists (to match the release commit) | |
| git tag -f -a "${{ steps.check.outputs.tag_name }}" -m "Release ${{ steps.check.outputs.tag_name }}" | |
| git push -f origin "${{ steps.check.outputs.tag_name }}" | |
| - name: Create GitHub Release | |
| if: steps.check.outputs.should_release == 'true' | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.check.outputs.tag_name }} | |
| files: | | |
| dist/index.js | |
| dist/bvm-shim.sh | |
| dist/bvm-shim.js | |
| install.sh | |
| install.ps1 | |
| generate_release_notes: true | |
| - name: Trigger Mirror Sync | |
| if: steps.check.outputs.should_release == 'true' | |
| run: | | |
| PACKAGE_NAME=$(grep -oE '"name": "[^"]+"' package.json | cut -d'"' -f4) | |
| curl -X PUT "https://registry-direct.npmmirror.com/$PACKAGE_NAME/sync?nodeps=true&publish=true" | |
| - name: Purge jsDelivr Cache | |
| if: steps.check.outputs.should_release == 'true' | |
| run: | | |
| TAG_NAME=${{ steps.check.outputs.tag_name }} | |
| curl -s https://purge.jsdelivr.net/gh/${{ github.repository }}@${TAG_NAME}/dist/index.js || true | |
| curl -s https://purge.jsdelivr.net/gh/${{ github.repository }}@latest/dist/index.js || true |