|
1 | 1 | name: Release |
| 2 | + |
2 | 3 | on: |
3 | | - push: |
4 | | - branches: |
5 | | - - master |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + dryRun: |
| 7 | + description: 'Dry run (no actual release)' |
| 8 | + required: false |
| 9 | + default: false |
| 10 | + type: boolean |
| 11 | + repository_dispatch: |
| 12 | + types: [release-trigger] |
| 13 | + |
6 | 14 | jobs: |
7 | 15 | release: |
8 | 16 | name: Release |
9 | 17 | runs-on: ubuntu-latest |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + node-version: [22] |
| 21 | + outputs: |
| 22 | + released: ${{ steps.release.outputs.released }} |
| 23 | + version: ${{ steps.extract-version.outputs.version }} |
10 | 24 | steps: |
11 | 25 | - name: Checkout |
12 | | - uses: actions/checkout@v2 |
| 26 | + uses: actions/checkout@v4 |
13 | 27 | with: |
14 | 28 | fetch-depth: 0 |
| 29 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + |
15 | 31 | - name: Setup Node |
16 | 32 | uses: actions/setup-node@v4 |
17 | 33 | with: |
18 | | - node-version: 22 |
19 | | - cache: 'npm' |
| 34 | + node-version: ${{ matrix.node-version }} |
| 35 | + cache: npm |
| 36 | + |
20 | 37 | - name: Setup Deno |
21 | 38 | uses: denolib/setup-deno@v2 |
22 | 39 | with: |
23 | | - deno-version: v1.x |
24 | | - - name: Install dependencies |
| 40 | + deno-version: v1.x |
| 41 | + |
| 42 | + - name: Validate trigger |
| 43 | + id: validate |
25 | 44 | run: | |
26 | | - npm install |
27 | | - npm run build --if-present |
| 45 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" || "${{ github.event_name }}" == "repository_dispatch" ]]; then |
| 46 | + echo "valid=true" >> "$GITHUB_OUTPUT" |
| 47 | + else |
| 48 | + echo "valid=false" >> "$GITHUB_OUTPUT" |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Install dependencies |
| 52 | + if: steps.validate.outputs.valid == 'true' |
| 53 | + run: npm install |
| 54 | + |
| 55 | + - name: Build |
| 56 | + if: steps.validate.outputs.valid == 'true' |
| 57 | + run: npm run build --if-present |
| 58 | + |
28 | 59 | - name: Run tests |
29 | | - run: | |
30 | | - npm run test |
| 60 | + if: steps.validate.outputs.valid == 'true' |
| 61 | + run: npm run test |
| 62 | + |
31 | 63 | - name: Release |
| 64 | + id: release |
| 65 | + if: steps.validate.outputs.valid == 'true' |
32 | 66 | env: |
33 | 67 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
34 | 68 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
35 | | - run: npx semantic-release |
| 69 | + DRY_RUN: ${{ github.event.inputs.dryRun || 'false' }} |
| 70 | + run: | |
| 71 | + node - <<'NODE' |
| 72 | + import fs from 'node:fs'; |
| 73 | +
|
| 74 | + (async () => { |
| 75 | + try { |
| 76 | + const { default: semanticRelease } = await import('semantic-release'); |
| 77 | + const result = await semanticRelease({ |
| 78 | + dryRun: process.env.DRY_RUN === 'true', |
| 79 | + }); |
| 80 | +
|
| 81 | + if (!result || process.env.DRY_RUN === 'true') { |
| 82 | + fs.appendFileSync(process.env.GITHUB_OUTPUT, 'released=false\n'); |
| 83 | + process.exit(0); |
| 84 | + } |
| 85 | +
|
| 86 | + fs.appendFileSync(process.env.GITHUB_OUTPUT, 'released=true\n'); |
| 87 | + fs.appendFileSync(process.env.GITHUB_OUTPUT, `version=${result.nextRelease.version}\n`); |
| 88 | + } catch (error) { |
| 89 | + console.error(error); |
| 90 | + process.exit(1); |
| 91 | + } |
| 92 | + })(); |
| 93 | + NODE |
| 94 | +
|
| 95 | + - name: Extract version |
| 96 | + id: extract-version |
| 97 | + if: steps.release.outputs.released == 'true' |
| 98 | + run: | |
| 99 | + VERSION=$(node -p "require('./package.json').version") |
| 100 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
0 commit comments