Skip to content

Commit d6d6db2

Browse files
committed
ci: main is always prepared for next release
1 parent a6a1198 commit d6d6db2

1 file changed

Lines changed: 68 additions & 4 deletions

File tree

.github/workflows/release.yml

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,22 +206,86 @@ jobs:
206206
- uses: actions/checkout@v5
207207
with:
208208
fetch-depth: 0
209+
210+
- name: Configure Git
211+
run: |
212+
git config user.name "GitHub Action"
213+
git config user.email "action@github.com"
214+
209215
- name: Fast-forward main
216+
id: ff-main
210217
run: |
211218
RELEASE_BRANCH="${GITHUB_REF_NAME}"
212219
git fetch origin main
213220
git fetch origin "$RELEASE_BRANCH"
214221
git checkout main
215222
if git merge --ff-only "origin/$RELEASE_BRANCH"; then
216-
git config user.name "GitHub Action"
217-
git config user.email "action@github.com"
218-
git push origin main
219223
echo "FAST_FORWARD=1" >> $GITHUB_ENV
224+
echo "fast_forward=true" >> $GITHUB_OUTPUT
220225
else
221226
echo "FAST_FORWARD=0" >> $GITHUB_ENV
227+
echo "fast_forward=false" >> $GITHUB_OUTPUT
228+
fi
229+
230+
- name: Update version for next release
231+
if: steps.ff-main.outputs.fast_forward == 'true'
232+
run: |
233+
# Extract current version from Cargo.toml
234+
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
235+
echo "Current version: $CURRENT_VERSION"
236+
237+
# Parse semantic version components
238+
if [[ $CURRENT_VERSION =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-.*)?$ ]]; then
239+
MAJOR="${BASH_REMATCH[1]}"
240+
MINOR="${BASH_REMATCH[2]}"
241+
PATCH="${BASH_REMATCH[3]}"
242+
PRERELEASE="${BASH_REMATCH[4]}"
243+
244+
# Determine next version based on release type
245+
# If this was a minor version bump (e.g., 0.0.10 -> 0.1.0),
246+
# set next as 0.2.0-rc for the next feature
247+
if [[ $PATCH -eq 0 && -z $PRERELEASE ]]; then
248+
# Clean release, bump minor and add -rc
249+
NEXT_MINOR=$((MINOR + 1))
250+
NEXT_VERSION="${MAJOR}.${NEXT_MINOR}.0-rc"
251+
elif [[ -n $PRERELEASE ]]; then
252+
# Already a prerelease, keep it or update
253+
NEXT_VERSION="$CURRENT_VERSION"
254+
else
255+
# Patch release, prepare next minor with -rc
256+
NEXT_MINOR=$((MINOR + 1))
257+
NEXT_VERSION="${MAJOR}.${NEXT_MINOR}.0-rc"
258+
fi
259+
260+
echo "Next version: $NEXT_VERSION"
261+
262+
# Update Cargo.toml with next version
263+
sed -i.bak "s/^version = \".*\"/version = \"$NEXT_VERSION\"/" Cargo.toml && rm Cargo.toml.bak
264+
265+
# Check if there are actual changes
266+
if git diff --quiet Cargo.toml; then
267+
echo "No version changes needed"
268+
echo "VERSION_UPDATED=false" >> $GITHUB_ENV
269+
else
270+
echo "Version updated to $NEXT_VERSION"
271+
echo "VERSION_UPDATED=true" >> $GITHUB_ENV
272+
echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_ENV
273+
fi
274+
else
275+
echo "Failed to parse version: $CURRENT_VERSION"
276+
exit 1
222277
fi
278+
279+
- name: Commit version update
280+
if: env.VERSION_UPDATED == 'true'
281+
run: |
282+
git add Cargo.toml
283+
git commit -m "chore: bump version to ${{ env.NEXT_VERSION }} [skip ci]"
284+
git push origin main
285+
echo "Version ${{ env.NEXT_VERSION }} committed to main branch"
286+
223287
- name: Create PR (non fast-forward)
224-
if: env.FAST_FORWARD == '0'
288+
if: steps.ff-main.outputs.fast_forward == 'false'
225289
env:
226290
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
227291
run: |

0 commit comments

Comments
 (0)