|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + packages: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + release: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - name: Setup Bun |
| 23 | + uses: oven-sh/setup-bun@v1 |
| 24 | + with: |
| 25 | + bun-version: latest |
| 26 | + |
| 27 | + - name: Install dependencies |
| 28 | + run: bun install |
| 29 | + |
| 30 | + - name: Run lint & tests |
| 31 | + run: bun run test |
| 32 | + |
| 33 | + - name: Bump version & generate changelog |
| 34 | + run: npx standard-version --release-as auto |
| 35 | + env: |
| 36 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + - name: Push changes & tags |
| 39 | + run: | |
| 40 | + git config user.name "github-actions[bot]" |
| 41 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 42 | + git push --follow-tags origin main |
| 43 | +
|
| 44 | + - name: Build project |
| 45 | + run: bun run build |
| 46 | + |
| 47 | + - name: Check if version already exists on npm |
| 48 | + run: | |
| 49 | + PKG_NAME=$(jq -r .name package.json) |
| 50 | + VERSION=$(jq -r .version package.json) |
| 51 | + if npm view $PKG_NAME versions --json | grep -q "\"$VERSION\""; then |
| 52 | + echo "⚠️ Version $VERSION already exists on npm. Skipping publish." |
| 53 | + exit 0 |
| 54 | + fi |
| 55 | +
|
| 56 | + - name: Get version from package.json |
| 57 | + id: get_version |
| 58 | + run: echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT |
| 59 | + |
| 60 | + - name: Create GitHub Release |
| 61 | + uses: softprops/action-gh-release@v2 |
| 62 | + with: |
| 63 | + tag_name: ${{ steps.get_version.outputs.version }} |
| 64 | + body_path: CHANGELOG.md |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + - name: Publish to npm |
| 69 | + run: bun publish --access public |
| 70 | + env: |
| 71 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments