|
1 | | - |
2 | 1 | name: Create release |
3 | 2 |
|
4 | 3 | on: |
5 | 4 | push: |
6 | | - branches: |
7 | | - - master |
8 | 5 | tags: |
9 | | - - '*.*.*' |
| 6 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
| 7 | + - '[0-9]+.[0-9]+.[0-9]+' |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
10 | 11 |
|
11 | 12 | jobs: |
12 | | - build: |
| 13 | + release: |
13 | 14 | runs-on: ubuntu-latest |
14 | 15 |
|
15 | 16 | steps: |
16 | | - - uses: actions/checkout@v2 |
| 17 | + - name: Resolve version from tag |
| 18 | + id: version |
| 19 | + run: | |
| 20 | + VERSION="${GITHUB_REF_NAME#v}" |
| 21 | + TAG="${GITHUB_REF_NAME}" |
| 22 | + if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 23 | + echo "Tag must be a semver version (for example v1.2.3 or 1.2.3)." |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 27 | + echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
| 28 | +
|
| 29 | + - uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + ref: ${{ github.ref }} |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - name: Bump package.json and move tag onto that commit |
| 35 | + run: | |
| 36 | + VERSION="${{ steps.version.outputs.version }}" |
| 37 | + TAG="${{ steps.version.outputs.tag }}" |
| 38 | +
|
| 39 | + git fetch origin master |
| 40 | +
|
| 41 | + if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/master)" ]; then |
| 42 | + echo "Tag must point to the current tip of master." |
| 43 | + echo "Push master first, then tag that commit and push the tag." |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +
|
| 47 | + git config user.name "github-actions[bot]" |
| 48 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 49 | +
|
| 50 | + CURRENT="$(jq -r '.version' package.json)" |
| 51 | + if [ "$CURRENT" = "$VERSION" ]; then |
| 52 | + echo "package.json already at $VERSION" |
| 53 | + else |
| 54 | + jq --arg version "$VERSION" '.version = $version' package.json > package.json.tmp |
| 55 | + mv package.json.tmp package.json |
| 56 | + git add package.json |
| 57 | + git commit -m "chore: release $TAG [skip ci]" |
| 58 | + fi |
| 59 | +
|
| 60 | + git tag -f "$TAG" |
| 61 | + git push origin HEAD:master |
| 62 | + git push origin "refs/tags/$TAG" --force |
17 | 63 |
|
18 | | - - name: Zip Folder |
19 | | - run: zip -r ${{ github.event.repository.name }}.zip . |
| 64 | + - name: Create package archive |
| 65 | + run: | |
| 66 | + zip -r "${{ github.event.repository.name }}.zip" . \ |
| 67 | + -x "*.git*" \ |
| 68 | + -x ".github/*" \ |
| 69 | + -x ".cursorignore" \ |
| 70 | + -x "Tests/*" |
20 | 71 |
|
21 | | - - name: Release |
22 | | - uses: softprops/action-gh-release@v1 |
23 | | - if: startsWith(github.ref, 'refs/tags/') |
| 72 | + - name: Create GitHub Release |
| 73 | + uses: softprops/action-gh-release@v2 |
24 | 74 | with: |
| 75 | + tag_name: ${{ steps.version.outputs.tag }} |
25 | 76 | files: ${{ github.event.repository.name }}.zip |
26 | | - env: |
27 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + generate_release_notes: true |
0 commit comments