|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Build and Test"] |
| 6 | + types: [completed] |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +jobs: |
| 10 | + release: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 13 | + permissions: |
| 14 | + contents: write |
| 15 | + id-token: write |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - name: Get package version |
| 23 | + id: package |
| 24 | + run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT |
| 25 | + |
| 26 | + - name: Check if tag exists |
| 27 | + id: tag_check |
| 28 | + run: | |
| 29 | + if git rev-parse "v${{ steps.package.outputs.version }}" >/dev/null 2>&1; then |
| 30 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 31 | + else |
| 32 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 33 | + fi |
| 34 | +
|
| 35 | + - name: Check if version exists on npm |
| 36 | + id: npm_check |
| 37 | + run: | |
| 38 | + if npm view transliteration@${{ steps.package.outputs.version }} version >/dev/null 2>&1; then |
| 39 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 40 | + else |
| 41 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 42 | + fi |
| 43 | +
|
| 44 | + - name: Setup Bun |
| 45 | + if: steps.npm_check.outputs.exists == 'false' |
| 46 | + uses: oven-sh/setup-bun@v2 |
| 47 | + with: |
| 48 | + bun-version: latest |
| 49 | + |
| 50 | + - name: Setup Node.js for npm publish |
| 51 | + if: steps.npm_check.outputs.exists == 'false' |
| 52 | + uses: actions/setup-node@v4 |
| 53 | + with: |
| 54 | + node-version: '20' |
| 55 | + registry-url: 'https://registry.npmjs.org' |
| 56 | + |
| 57 | + - name: Update npm for OIDC support |
| 58 | + if: steps.npm_check.outputs.exists == 'false' |
| 59 | + run: npm install -g npm@latest |
| 60 | + |
| 61 | + - name: Install dependencies |
| 62 | + if: steps.npm_check.outputs.exists == 'false' |
| 63 | + run: bun install |
| 64 | + |
| 65 | + - name: Build |
| 66 | + if: steps.npm_check.outputs.exists == 'false' |
| 67 | + run: bun run build |
| 68 | + |
| 69 | + - name: Publish to npm |
| 70 | + if: steps.npm_check.outputs.exists == 'false' |
| 71 | + run: npm publish |
| 72 | + |
| 73 | + - name: Create and push tag |
| 74 | + if: steps.tag_check.outputs.exists == 'false' |
| 75 | + run: | |
| 76 | + git config user.name "github-actions[bot]" |
| 77 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 78 | + git tag -a "v${{ steps.package.outputs.version }}" -m "Release v${{ steps.package.outputs.version }}" |
| 79 | + git push origin "v${{ steps.package.outputs.version }}" |
| 80 | +
|
| 81 | + - name: Create GitHub Release |
| 82 | + if: steps.tag_check.outputs.exists == 'false' |
| 83 | + uses: softprops/action-gh-release@v2 |
| 84 | + with: |
| 85 | + tag_name: v${{ steps.package.outputs.version }} |
| 86 | + name: v${{ steps.package.outputs.version }} |
| 87 | + generate_release_notes: true |
| 88 | + env: |
| 89 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments