|
| 1 | +name: Publish package |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Code checks"] |
| 6 | + branches: |
| 7 | + - dev |
| 8 | + - master |
| 9 | + types: |
| 10 | + - completed |
| 11 | + |
| 12 | + # Allows you to run this workflow manually from the Actions tab |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +env: |
| 16 | + BUN_VERSION: 1.2.5 |
| 17 | + |
| 18 | +defaults: |
| 19 | + run: |
| 20 | + shell: bash |
| 21 | + working-directory: ./ # Ensure bun install runs in the correct working directory |
| 22 | + |
| 23 | +jobs: |
| 24 | + on-failure: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + if: ${{ github.event.workflow_run.conclusion == 'failure' }} |
| 27 | + steps: |
| 28 | + - name: Failed workflow |
| 29 | + run: | |
| 30 | + echo "Code checks workflow failed" |
| 31 | + exit 1 |
| 32 | +
|
| 33 | + setup: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Setup bun |
| 40 | + uses: oven-sh/setup-bun@v2 |
| 41 | + |
| 42 | + with: |
| 43 | + bun-version: ${{ env.BUN_VERSION }} |
| 44 | + |
| 45 | + # Install dependencies using Bun |
| 46 | + - name: Install dependencies |
| 47 | + run: bun install --frozen-lockfile |
| 48 | + |
| 49 | + # Cache node_modules |
| 50 | + - name: Cache node_modules |
| 51 | + uses: actions/cache@v3 |
| 52 | + with: |
| 53 | + path: node_modules |
| 54 | + key: ${{ hashFiles('**/bun.lock') }} |
| 55 | + |
| 56 | + publish: |
| 57 | + runs-on: ubuntu-latest |
| 58 | + needs: |
| 59 | + - setup |
| 60 | + |
| 61 | + permissions: |
| 62 | + contents: write # allow GITHUB_TOKEN to create release |
| 63 | + packages: write # allow GITHUB_TOKEN to publish packages |
| 64 | + id-token: write |
| 65 | + |
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v4 |
| 68 | + |
| 69 | + - name: Setup bun |
| 70 | + uses: oven-sh/setup-bun@v2 |
| 71 | + with: |
| 72 | + bun-version: ${{ env.BUN_VERSION }} |
| 73 | + |
| 74 | + - name: Restore cache |
| 75 | + uses: actions/cache@v3 |
| 76 | + with: |
| 77 | + path: node_modules |
| 78 | + key: ${{ hashFiles('**/bun.lock') }} |
| 79 | + |
| 80 | + - name: Set git user |
| 81 | + env: |
| 82 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 83 | + run: | |
| 84 | + git config --global user.name "GitHub Actions" |
| 85 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 86 | + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc |
| 87 | +
|
| 88 | + - name: Publish RC |
| 89 | + if: github.ref == 'refs/heads/dev' |
| 90 | + env: |
| 91 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 92 | + run: bunx changelogen --publishTag rc --prerelease --nameSuffix rc --push |
| 93 | + |
| 94 | + - name: Publish |
| 95 | + if: github.ref == 'refs/heads/master' |
| 96 | + env: |
| 97 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + run: bunx changelogen --release --publish --push |
0 commit comments