Skip to content

Commit 770d97c

Browse files
authored
ci: fix version numbering (#134)
1 parent 0243c6f commit 770d97c

File tree

1 file changed

+55
-39
lines changed

1 file changed

+55
-39
lines changed

.github/workflows/release.yml

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,36 @@ env:
1818
RUST_BACKTRACE: 1
1919

2020
jobs:
21-
# 1. First, run tests and linting as a quality gate.
21+
# 1. Determine version first before any other jobs
22+
version:
23+
name: Determine Version
24+
runs-on: ubuntu-latest
25+
outputs:
26+
version: ${{ steps.set-version.outputs.version }}
27+
steps:
28+
- uses: actions/checkout@v6
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Determine Version
33+
id: semver
34+
uses: PaulHatch/semantic-version@v5.4.0
35+
with:
36+
tag_prefix: "v"
37+
major_pattern: "BREAKING CHANGE:"
38+
minor_pattern: "feat:"
39+
version_format: "${major}.${minor}.${patch}"
40+
search_commit_body: true
41+
debug: true
42+
43+
- name: Set VERSION output
44+
id: set-version
45+
run: |
46+
VERSION="${{ steps.semver.outputs.version }}"
47+
echo "Calculated semantic version: $VERSION"
48+
echo "version=$VERSION" >> $GITHUB_OUTPUT
49+
50+
# 2. Run tests and linting as a quality gate.
2251
test:
2352
name: Test & Lint
2453
runs-on: ubuntu-latest
@@ -34,11 +63,11 @@ jobs:
3463
- name: Run tests
3564
run: cargo test --all --locked
3665

37-
# 2. Build all required binaries for different targets.
38-
# This job runs only after tests have passed.
66+
# 3. Build all required binaries with the correct version.
67+
# This job runs only after tests have passed and version is determined.
3968
build:
4069
name: Build Binaries
41-
needs: test
70+
needs: [version, test]
4271
runs-on: ${{ matrix.os }}
4372
strategy:
4473
matrix:
@@ -61,6 +90,17 @@ jobs:
6190
with:
6291
key: ${{ matrix.target }}
6392

93+
- name: Update Cargo.toml version before build
94+
run: |
95+
VERSION="${{ needs.version.outputs.version }}"
96+
echo "Building with version: $VERSION"
97+
# Update version in main Cargo.toml
98+
if [[ "$OSTYPE" == "darwin"* ]]; then
99+
sed -i '' "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml
100+
else
101+
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml
102+
fi
103+
64104
- name: Build main binary and plugins
65105
run: cargo build --release --target ${{ matrix.target }} --workspace
66106

@@ -83,11 +123,11 @@ jobs:
83123
target/${{ matrix.target }}/release/repos-health
84124
target/${{ matrix.target }}/release/repos-validate
85125
86-
# 3. Create the universal macOS binary from the previously built artifacts.
126+
# 4. Create the universal macOS binary from the previously built artifacts.
87127
# This job is very fast as it does not re-compile anything.
88128
package-universal:
89129
name: Package Universal macOS
90-
needs: build
130+
needs: [version, build]
91131
runs-on: macos-latest
92132
steps:
93133
- name: Download macOS arm64 artifacts
@@ -117,45 +157,22 @@ jobs:
117157
repos-health
118158
repos-validate
119159
120-
# 4. Determine version, create the GitHub Release, and upload all artifacts.
160+
# 5. Create the GitHub Release and upload all artifacts.
121161
# This is the final publishing step.
122162
publish:
123163
name: Publish Release
124-
needs: [build, package-universal]
164+
needs: [version, build, package-universal]
125165
runs-on: ubuntu-latest
126-
outputs:
127-
version: ${{ steps.set-version.outputs.version }}
128166
steps:
129167
- uses: actions/checkout@v6
130168
with:
131169
fetch-depth: 0
132170

133-
- name: Determine Version
134-
id: semver
135-
uses: PaulHatch/semantic-version@v5.4.0
136-
with:
137-
tag_prefix: "v"
138-
major_pattern: "BREAKING CHANGE:"
139-
minor_pattern: "feat:"
140-
version_format: "${major}.${minor}.${patch}"
141-
search_commit_body: true
142-
debug: true
143-
144-
- name: Set VERSION from semantic-version
145-
id: set-version
171+
- name: Set VERSION from version job
146172
run: |
147-
VERSION="${{ steps.semver.outputs.version }}"
148-
echo "Using semantic version: $VERSION"
173+
VERSION="${{ needs.version.outputs.version }}"
174+
echo "Publishing version: $VERSION"
149175
echo "VERSION=$VERSION" >> $GITHUB_ENV
150-
echo "version=$VERSION" >> $GITHUB_OUTPUT
151-
152-
- name: Update Cargo.toml version for release
153-
run: |
154-
# Update version in main Cargo.toml (remove -rc suffix)
155-
sed -i "s/^version = \".*\"/version = \"${{ env.VERSION }}\"/" Cargo.toml
156-
157-
# Update version in workspace members if they reference the main version
158-
find . -name "Cargo.toml" -not -path "./Cargo.toml" -exec sed -i "s/version = \".*-rc\"/version = \"${{ env.VERSION }}\"/" {} \;
159176
160177
- name: Download all build artifacts
161178
uses: actions/download-artifact@v6
@@ -204,11 +221,10 @@ jobs:
204221
files: |
205222
*.tar.gz
206223
207-
# 5. After a successful release, create a PR to merge the release branch
208-
# back into main and bump the version for the next development cycle.
224+
# 6. After a successful release, create a PR to bump version in main
209225
sync-main:
210226
name: Sync Back to Main
211-
needs: publish
227+
needs: [version, publish]
212228
runs-on: ubuntu-latest
213229
steps:
214230
- uses: actions/checkout@v6
@@ -224,8 +240,8 @@ jobs:
224240
- name: Create version bump branch from main
225241
id: versioning
226242
run: |
227-
RELEASE_VERSION=${{ needs.publish.outputs.version }}
228-
# Calculate next version (e.g., 0.1.0 -> 0.2.0-rc)
243+
RELEASE_VERSION=${{ needs.version.outputs.version }}
244+
# Calculate next version (e.g., 0.2.1 -> 0.3.0-rc)
229245
MAJOR=$(echo "$RELEASE_VERSION" | cut -d. -f1)
230246
MINOR=$(echo "$RELEASE_VERSION" | cut -d. -f2)
231247
NEXT_MINOR=$((MINOR + 1))

0 commit comments

Comments
 (0)