|
1 |
| -name: Build and Release |
| 1 | +name: Build and release |
2 | 2 |
|
3 | 3 | on:
|
| 4 | + push: |
| 5 | + branches: [master] |
4 | 6 | workflow_dispatch:
|
5 | 7 | inputs:
|
6 | 8 | tag:
|
|
9 | 11 |
|
10 | 12 | jobs:
|
11 | 13 | release:
|
12 |
| - name: Create Release |
13 | 14 | runs-on: ubuntu-latest
|
14 | 15 | steps:
|
15 |
| - - name: Checkout code |
16 |
| - |
| 16 | + |
17 | 17 | with:
|
18 | 18 | fetch-depth: 0
|
19 |
| - - name: Set up Node.js |
20 |
| - |
| 19 | + |
21 | 20 | with:
|
22 | 21 | node-version: '20'
|
23 |
| - - name: Install dependencies |
24 |
| - run: npm install |
25 |
| - - name: Build with ncc |
26 |
| - run: npm run build |
27 |
| - - name: Zip build artifacts |
28 |
| - run: zip -r build-${{ github.event.inputs.tag }}.zip index.js |
29 |
| - - name: Create tag |
| 22 | + - run: npm install |
| 23 | + - name: Bump version in package.json if needed |
| 24 | + if: github.event_name == 'workflow_dispatch' |
30 | 25 | run: |
|
| 26 | + TAG=${{ github.event.inputs.tag }} |
| 27 | + VER=${TAG#v} |
| 28 | + npm version $VER --no-git-tag-version |
31 | 29 | git config user.name "github-actions[bot]"
|
32 | 30 | git config user.email "github-actions[bot]@users.noreply.github.com"
|
33 |
| - rm -rf src |
| 31 | + git add package.json package-lock.json |
| 32 | + git commit -m "chore: bump to v${VER}" |
| 33 | + git push origin HEAD |
| 34 | + - id: get_version |
| 35 | + run: | |
| 36 | + VERSION=$(node -p "require('./package.json').version") |
| 37 | + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 38 | + - name: Check if tag already exists |
| 39 | + id: tag_check |
| 40 | + run: | |
| 41 | + T=v${{ steps.get_version.outputs.VERSION }} |
| 42 | + if git rev-parse "$T" >/dev/null 2>&1; then |
| 43 | + echo "skip=true" >> $GITHUB_OUTPUT |
| 44 | + else |
| 45 | + echo "skip=false" >> $GITHUB_OUTPUT |
| 46 | + fi |
| 47 | + - if: steps.tag_check.outputs.skip == 'false' |
| 48 | + name: Build and zip |
| 49 | + run: | |
| 50 | + npm run build |
| 51 | + zip -r build-v${{ steps.get_version.outputs.VERSION }}.zip index.js |
| 52 | + - if: steps.tag_check.outputs.skip == 'false' |
| 53 | + name: Create tag with only build output |
| 54 | + run: | |
| 55 | + git config user.name "github-actions[bot]" |
| 56 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 57 | + TAG=v${{ steps.get_version.outputs.VERSION }} |
| 58 | + TMP_BRANCH=release-tmp-$TAG |
| 59 | + git checkout -b $TMP_BRANCH |
| 60 | + git rm -rf src |
34 | 61 | git add -f index.js
|
35 |
| - git add -u |
36 |
| - git commit -m "Build for release ${{ github.event.inputs.tag }}" |
37 |
| - git tag ${{ github.event.inputs.tag }} |
38 |
| - git push origin ${{ github.event.inputs.tag }} |
39 |
| - - name: Create GitHub release |
40 |
| - id: create_release |
| 62 | + git reset HEAD package.json package-lock.json |
| 63 | + git commit -m "build: release $TAG" |
| 64 | + git tag $TAG |
| 65 | + git push origin $TAG |
| 66 | + git checkout master |
| 67 | + git branch -D $TMP_BRANCH |
| 68 | + - if: steps.tag_check.outputs.skip == 'false' |
| 69 | + name: Create GitHub release |
41 | 70 |
|
42 | 71 | with:
|
43 |
| - tag_name: ${{ github.event.inputs.tag }} |
| 72 | + tag_name: v${{ steps.get_version.outputs.VERSION }} |
44 | 73 | generate_release_notes: true
|
| 74 | + files: build-v${{ steps.get_version.outputs.VERSION }}.zip |
0 commit comments