|
1 | 1 | name: Release |
| 2 | + |
2 | 3 | on: |
3 | | - push: |
4 | | - branches: |
5 | | - - master |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + releaseType: |
| 7 | + description: 'Release type (patch, minor, major)' |
| 8 | + required: false |
| 9 | + default: 'auto' |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - auto |
| 13 | + - patch |
| 14 | + - minor |
| 15 | + - major |
| 16 | + dryRun: |
| 17 | + description: 'Dry run (no actual release)' |
| 18 | + required: false |
| 19 | + default: false |
| 20 | + type: boolean |
| 21 | + preRelease: |
| 22 | + description: 'Pre-release identifier (beta, alpha, rc, etc.)' |
| 23 | + required: false |
| 24 | + default: '' |
| 25 | + type: string |
| 26 | + repository_dispatch: |
| 27 | + types: [release-trigger] |
| 28 | + |
6 | 29 | jobs: |
7 | 30 | release: |
8 | 31 | name: Release |
9 | 32 | runs-on: ubuntu-latest |
| 33 | + strategy: |
| 34 | + matrix: |
| 35 | + node-version: [22] |
| 36 | + outputs: |
| 37 | + released: ${{ steps.release.outputs.released }} |
| 38 | + version: ${{ steps.extract-version.outputs.version }} |
10 | 39 | steps: |
11 | 40 | - name: Checkout |
12 | | - uses: actions/checkout@v2 |
| 41 | + uses: actions/checkout@v4 |
13 | 42 | with: |
14 | 43 | fetch-depth: 0 |
| 44 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
15 | 46 | - name: Setup Node |
16 | 47 | uses: actions/setup-node@v4 |
17 | 48 | with: |
18 | | - node-version: 22 |
19 | | - cache: 'npm' |
| 49 | + node-version: ${{ matrix.node-version }} |
| 50 | + cache: npm |
| 51 | + |
20 | 52 | - name: Setup Deno |
21 | 53 | uses: denolib/setup-deno@v2 |
22 | 54 | with: |
23 | | - deno-version: v1.x |
24 | | - - name: Install dependencies |
| 55 | + deno-version: v1.x |
| 56 | + |
| 57 | + - name: Validate trigger |
| 58 | + id: validate |
25 | 59 | run: | |
26 | | - npm install |
27 | | - npm run build --if-present |
| 60 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" || "${{ github.event_name }}" == "repository_dispatch" ]]; then |
| 61 | + echo "valid=true" >> "$GITHUB_OUTPUT" |
| 62 | + else |
| 63 | + echo "valid=false" >> "$GITHUB_OUTPUT" |
| 64 | + fi |
| 65 | +
|
| 66 | + - name: Install dependencies |
| 67 | + if: steps.validate.outputs.valid == 'true' |
| 68 | + run: npm install |
| 69 | + |
| 70 | + - name: Build |
| 71 | + if: steps.validate.outputs.valid == 'true' |
| 72 | + run: npm run build --if-present |
| 73 | + |
28 | 74 | - name: Run tests |
29 | | - run: | |
30 | | - npm run test |
| 75 | + if: steps.validate.outputs.valid == 'true' |
| 76 | + run: npm run test |
| 77 | + |
31 | 78 | - name: Release |
| 79 | + id: release |
| 80 | + if: steps.validate.outputs.valid == 'true' |
32 | 81 | env: |
33 | 82 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
34 | 83 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
35 | | - run: npx semantic-release |
| 84 | + RELEASE_TYPE: ${{ github.event.inputs.releaseType || 'auto' }} |
| 85 | + DRY_RUN: ${{ github.event.inputs.dryRun || 'false' }} |
| 86 | + PRE_RELEASE: ${{ github.event.inputs.preRelease || '' }} |
| 87 | + run: | |
| 88 | + EXTRA_ARGS="" |
| 89 | +
|
| 90 | + if [ "$DRY_RUN" = "true" ]; then |
| 91 | + echo "Running in dry-run mode" |
| 92 | + EXTRA_ARGS="--dry-run" |
| 93 | + fi |
| 94 | +
|
| 95 | + if [ -n "$PRE_RELEASE" ]; then |
| 96 | + echo "Running pre-release: $PRE_RELEASE" |
| 97 | + npx semantic-release --prerelease "$PRE_RELEASE" $EXTRA_ARGS |
| 98 | + EXIT_CODE=$? |
| 99 | + elif [ "$RELEASE_TYPE" = "auto" ]; then |
| 100 | + echo "Running auto release" |
| 101 | + npx semantic-release $EXTRA_ARGS |
| 102 | + EXIT_CODE=$? |
| 103 | + else |
| 104 | + echo "Running release with type: $RELEASE_TYPE" |
| 105 | + npx semantic-release --release-as "$RELEASE_TYPE" $EXTRA_ARGS |
| 106 | + EXIT_CODE=$? |
| 107 | + fi |
| 108 | +
|
| 109 | + if [ "$DRY_RUN" != "true" ] && [ $EXIT_CODE -eq 0 ]; then |
| 110 | + echo "released=true" >> "$GITHUB_OUTPUT" |
| 111 | + else |
| 112 | + echo "released=false" >> "$GITHUB_OUTPUT" |
| 113 | + fi |
| 114 | +
|
| 115 | + exit $EXIT_CODE |
| 116 | +
|
| 117 | + - name: Extract version |
| 118 | + id: extract-version |
| 119 | + if: steps.release.outputs.released == 'true' |
| 120 | + run: | |
| 121 | + VERSION=$(node -p "require('./package.json').version") |
| 122 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
0 commit comments