@@ -2,8 +2,6 @@ name: Release
22
33on :
44 push :
5- tags :
6- - ' v*'
75 branches :
86 - master
97
@@ -37,40 +35,45 @@ jobs:
3735 - name : Check documentation
3836 run : bun run check-docs
3937
40- check -version :
38+ determine -version :
4139 runs-on : ubuntu-latest
4240 outputs :
43- should_release : ${{ steps.check .outputs.should_release }}
44- version : ${{ steps.check .outputs.version }}
41+ version : ${{ steps.version .outputs.version }}
42+ tag : ${{ steps.version .outputs.tag }}
4543 steps :
4644 - name : Checkout
4745 uses : actions/checkout@v4
46+ with :
47+ fetch-depth : 0
4848
49- - name : Check if release needed
50- id : check
51- env :
52- GH_TOKEN : ${{ github.token }}
49+ - name : Determine next version
50+ id : version
5351 run : |
54- if [[ "${{ github.ref_type }}" == "tag" ]]; then
55- echo "Triggered by tag push, proceeding with release"
56- echo "should_release=true" >> "$GITHUB_OUTPUT"
57- echo "version=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
52+ # Get the latest version tag (e.g., v0.2.0)
53+ LATEST_TAG=$(git tag --list 'v*' --sort=-version:refname | head -n 1)
54+
55+ if [ -z "$LATEST_TAG" ]; then
56+ # No tags exist — use package.json version as the starting point
57+ CURRENT=$(jq -r .version package.json)
58+ echo "No existing tags found, using package.json version: $CURRENT"
5859 else
59- VERSION="v$(jq -r .version package.json)"
60- echo "Version from package.json: $VERSION"
61- if gh release view "$VERSION" --repo "${{ github.repository }}" >/dev/null 2>&1; then
62- echo "Release $VERSION already exists, skipping"
63- echo "should_release=false" >> "$GITHUB_OUTPUT"
64- else
65- echo "No release found for $VERSION, proceeding"
66- echo "should_release=true" >> "$GITHUB_OUTPUT"
67- fi
68- echo "version=$VERSION" >> "$GITHUB_OUTPUT"
60+ # Strip the leading 'v'
61+ CURRENT="${LATEST_TAG#v}"
62+ echo "Latest tag: $LATEST_TAG (version: $CURRENT)"
6963 fi
7064
65+ # Bump patch version: split on dots, increment the last segment
66+ IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
67+ NEXT_PATCH=$((PATCH + 1))
68+ NEXT_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}"
69+ NEXT_TAG="v${NEXT_VERSION}"
70+
71+ echo "Next version: $NEXT_VERSION (tag: $NEXT_TAG)"
72+ echo "version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
73+ echo "tag=$NEXT_TAG" >> "$GITHUB_OUTPUT"
74+
7175 build :
72- needs : [ci, check-version]
73- if : needs.check-version.outputs.should_release == 'true'
76+ needs : [ci, determine-version]
7477 strategy :
7578 matrix :
7679 include :
@@ -101,6 +104,11 @@ jobs:
101104 - name : Install dependencies
102105 run : bun install
103106
107+ - name : Stamp version in package.json
108+ run : |
109+ jq '.version = "${{ needs.determine-version.outputs.version }}"' package.json > package.json.tmp
110+ mv package.json.tmp package.json
111+
104112 - name : Build binary
105113 run : bun build ./bin/recs.ts --compile --target=${{ matrix.target }} --outfile=${{ matrix.artifact }}
106114
@@ -111,21 +119,17 @@ jobs:
111119 path : ${{ matrix.artifact }}
112120
113121 release :
114- needs : [check-version, build]
115- if : needs.check-version.outputs.should_release == 'true'
122+ needs : [determine-version, build]
116123 runs-on : ubuntu-latest
117124
118125 steps :
119126 - name : Checkout
120127 uses : actions/checkout@v4
121128
122- - name : Create tag for version
123- if : github.ref_type != 'tag'
124- env :
125- GH_TOKEN : ${{ github.token }}
129+ - name : Create tag
126130 run : |
127- git tag "${{ needs.check -version.outputs.version }}"
128- git push origin "${{ needs.check -version.outputs.version }}"
131+ git tag "${{ needs.determine -version.outputs.tag }}"
132+ git push origin "${{ needs.determine -version.outputs.tag }}"
129133
130134 - name : Download all artifacts
131135 uses : actions/download-artifact@v4
@@ -135,7 +139,8 @@ jobs:
135139 - name : Create GitHub Release
136140 uses : softprops/action-gh-release@v2
137141 with :
138- tag_name : ${{ needs.check-version.outputs.version }}
142+ tag_name : ${{ needs.determine-version.outputs.tag }}
143+ name : ${{ needs.determine-version.outputs.tag }}
139144 generate_release_notes : true
140145 files : |
141146 artifacts/recs-linux-x64/recs-linux-x64
0 commit comments