Replace shell-based date calculations with comprehensive Python script that provides: - Proper RC numbering counting backwards from final release dates - Dead period detection for dates too early in the cycle - Automated documentation updates with commit tracking - Better error handling and testing coverage - Shell variable output for CI integration The new Python-based approach replaces fragile shell arithmetic with robust datetime calculations and includes comprehensive test coverage. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <sjg@chromium.org)
103 lines
4.0 KiB
YAML
103 lines
4.0 KiB
YAML
# .gitlab-ci-release.yml
|
|
|
|
version:update_and_commit:
|
|
stage: version_bump
|
|
image: alpine:3.18
|
|
rules:
|
|
# Run only on scheduled pipelines targeting the 'master' branch.
|
|
- if: '$CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_REF_NAME == "master"'
|
|
script:
|
|
- |
|
|
echo "Determining release type and updating Makefile..."
|
|
|
|
apk add --no-cache git python3
|
|
git config --global user.name "GitLab CI"
|
|
git config --global user.email "gitlab-ci@${CI_SERVER_HOST}"
|
|
|
|
# Use Python script to calculate release version and set shell variables
|
|
# Sets: IS_FINAL, VERSION, YEAR, MONTH, RC_NUMBER (RCs only),
|
|
# WEEKS_UNTIL_FINAL (RCs only)
|
|
# Or: IS_DEAD_PERIOD, WEEKS_UNTIL_FINAL, NEXT_RELEASE_YEAR,
|
|
# NEXT_RELEASE_MONTH (dead period)
|
|
eval $(python3 scripts/release_version.py)
|
|
|
|
# Check if we're in a dead period (too early for any RC)
|
|
if [ "$IS_DEAD_PERIOD" = "true" ]; then
|
|
echo "📅 Dead period: $WEEKS_UNTIL_FINAL weeks until next release cycle begins"
|
|
echo "Next release will be $NEXT_RELEASE_YEAR.$NEXT_RELEASE_MONTH"
|
|
echo "No version bump needed - exiting"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Release calculated: VERSION=$VERSION, IS_FINAL=$IS_FINAL"
|
|
|
|
if [ "$IS_FINAL" = "true" ]; then
|
|
COMMIT_MESSAGE="chore: Bump version for final release $VERSION"
|
|
echo "✅ This is a Final Release: $VERSION"
|
|
else
|
|
COMMIT_MESSAGE="chore: Bump version for release candidate $VERSION"
|
|
echo "✅ This is a Release Candidate: $VERSION ($WEEKS_UNTIL_FINAL weeks until release)"
|
|
fi
|
|
|
|
# Update Makefile using Python script
|
|
if python3 scripts/release_version.py --update-makefile; then
|
|
echo "Makefile updated for version $VERSION"
|
|
else
|
|
echo "Makefile is already up-to-date for version $VERSION."
|
|
exit 0
|
|
fi
|
|
|
|
echo "Pushing version bump to master branch..."
|
|
git add Makefile
|
|
git commit -m "$COMMIT_MESSAGE"
|
|
|
|
# Get the commit SHA that will be created
|
|
COMMIT_SHA=$(git rev-parse HEAD)
|
|
echo "Version bump commit SHA: $COMMIT_SHA"
|
|
|
|
git push "https://gitlab-ci-token:${GIT_WRITE_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" HEAD:master
|
|
|
|
# Update release documentation with the commit SHA
|
|
echo "Updating release documentation..."
|
|
if python3 scripts/release_version.py --update-release-docs --commit-sha "$COMMIT_SHA"; then
|
|
echo "Release documentation updated for version $VERSION"
|
|
git add doc/develop/concept_releases.rst
|
|
git commit -m "docs: Add $VERSION to release history"
|
|
git push "https://gitlab-ci-token:${GIT_WRITE_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" HEAD:master
|
|
else
|
|
echo "Release documentation already up-to-date or no changes needed"
|
|
fi
|
|
|
|
release:create_tag:
|
|
stage: release
|
|
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
|
rules:
|
|
- if: '$CI_COMMIT_BRANCH == "master" && $CI_COMMIT_MESSAGE =~ /^chore: Bump version for/'
|
|
script:
|
|
- |
|
|
echo "🚀 Release commit detected. Creating GitLab Release..."
|
|
|
|
TAG_NAME=$(echo "$CI_COMMIT_MESSAGE" | awk '{print $NF}')
|
|
RELEASE_TITLE=$(echo "$CI_COMMIT_MESSAGE" | sed -e 's/chore: Bump version for/Release/' -e "s/$TAG_NAME//")
|
|
|
|
echo "Extracted Tag Name: $TAG_NAME"
|
|
echo "Generated Release Title: $RELEASE_TITLE"
|
|
|
|
release-cli create \
|
|
--name "$RELEASE_TITLE" \
|
|
--tag-name "$TAG_NAME" \
|
|
--description "Automated release created by GitLab CI for commit $CI_COMMIT_SHORT_SHA." \
|
|
--ref "$CI_COMMIT_SHA"
|
|
|
|
echo "🔧 Creating secondary 'c'-prefixed tag..."
|
|
apk add --no-cache git
|
|
git config --global user.name "GitLab CI"
|
|
git config --global user.email "gitlab-ci@${CI_SERVER_HOST}"
|
|
|
|
C_TAG_NAME="c${TAG_NAME}"
|
|
echo "Secondary tag name is: $C_TAG_NAME"
|
|
|
|
git tag "$C_TAG_NAME" "$CI_COMMIT_SHA"
|
|
git push "https://gitlab-ci-token:${GIT_WRITE_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" "$C_TAG_NAME"
|
|
echo "✅ Successfully pushed secondary tag."
|