|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + ci: |
| 10 | + name: CI - Build and Test |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Set up Bun |
| 17 | + uses: oven-sh/setup-bun@v2 |
| 18 | + |
| 19 | + - name: Install dependencies |
| 20 | + run: bun install --frozen-lockfile |
| 21 | + |
| 22 | + - name: Run TypeScript checks |
| 23 | + run: bun tsc --noEmit |
| 24 | + |
| 25 | + - name: Run Biome check |
| 26 | + run: bun biome ci . |
| 27 | + |
| 28 | + - name: Run tests |
| 29 | + run: bun test |
| 30 | + |
| 31 | + changelog: |
| 32 | + name: Generate changelog |
| 33 | + needs: ci |
| 34 | + runs-on: ubuntu-latest |
| 35 | + outputs: |
| 36 | + release_body: ${{ steps.git-cliff.outputs.content }} |
| 37 | + steps: |
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + fetch-depth: 0 |
| 42 | + lfs: true |
| 43 | + |
| 44 | + - name: Find latest stable tag |
| 45 | + id: latest_stable_tag |
| 46 | + run: | |
| 47 | + LATEST_TAG=$(git tag --sort=-creatordate | grep -v "-" | head -n1) |
| 48 | + echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV |
| 49 | +
|
| 50 | + - name: Generate changelog |
| 51 | + id: git-cliff |
| 52 | + uses: orhun/git-cliff-action@v4 |
| 53 | + with: |
| 54 | + config: cliff.toml |
| 55 | + args: ${{ env.PRERELEASE == 'true' && '--latest --strip all' || format('{0}..HEAD --strip all', env.LATEST_TAG) }} |
| 56 | + env: |
| 57 | + OUTPUT: CHANGES.md |
| 58 | + GITHUB_REPO: ${{ github.repository }} |
| 59 | + |
| 60 | + release: |
| 61 | + name: Create Release and Publish to NPM |
| 62 | + needs: changelog |
| 63 | + runs-on: ubuntu-latest |
| 64 | + steps: |
| 65 | + - name: Checkout |
| 66 | + uses: actions/checkout@v4 |
| 67 | + |
| 68 | + - name: Set up Bun |
| 69 | + uses: oven-sh/setup-bun@v2 |
| 70 | + |
| 71 | + - name: Install dependencies |
| 72 | + run: bun install --frozen-lockfile |
| 73 | + |
| 74 | + - name: Build package |
| 75 | + run: bun run build:prod |
| 76 | + |
| 77 | + - name: Determine if prerelease |
| 78 | + id: prerelease |
| 79 | + run: | |
| 80 | + if [[ "${{ github.ref_name }}" == *"-"* ]]; then |
| 81 | + echo "is_prerelease=true" >> $GITHUB_OUTPUT |
| 82 | + echo "PRERELEASE=true" >> $GITHUB_ENV |
| 83 | + else |
| 84 | + echo "is_prerelease=false" >> $GITHUB_OUTPUT |
| 85 | + echo "PRERELEASE=false" >> $GITHUB_ENV |
| 86 | + fi |
| 87 | +
|
| 88 | + - name: Create GitHub Release |
| 89 | + run: | |
| 90 | + if [[ "${{ steps.prerelease.outputs.is_prerelease }}" == "true" ]]; then |
| 91 | + gh release create ${{ github.ref_name }} --title "${{ github.ref_name }}" --notes '${{ needs.changelog.outputs.release_body }}' --prerelease |
| 92 | + else |
| 93 | + gh release create ${{ github.ref_name }} --title "${{ github.ref_name }}" --notes '${{ needs.changelog.outputs.release_body }}' |
| 94 | + fi |
| 95 | + env: |
| 96 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + |
| 98 | + - name: Setup Node.js for NPM |
| 99 | + uses: actions/setup-node@v4 |
| 100 | + with: |
| 101 | + node-version: "18" |
| 102 | + registry-url: "https://registry.npmjs.org" |
| 103 | + |
| 104 | + - name: Publish to NPM |
| 105 | + run: npm publish |
| 106 | + env: |
| 107 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments