Introduce a new CI job in .gitlab-ci-release.yml to automate the
creation of project releases.
This change implements two new jobs in .gitlab-ci-release.yml:
1. A version:bump job that runs on a schedule. On the first Monday of an
even-numbered month, it automatically updates the VERSION and PATCHLEVEL
in the Makefile and pushes the change to the master branch.
2. A release:create job that is triggered by the version bump commit. It
creates the final GitLab Release and corresponding Git tag on the commit
containing the updated Makefile.
This ensures that the repository's version is correctly updated and
committed just before the official release tag is applied, creating a
clean and reliable release history.
This single job, designed to run on a schedule, contains logic to:
- create a final release (e.g. 2025.08) on the first Monday of an
even-numbered month.
- create a release candidate (e.g. 2025.07-rc1) on all other
scheduled days.
This uses official release-cli to create both the git tag and the
corresponding GitLab Release entry automatically.
Signed-off-by: Simon Glass <sjg@chromium.org>
74 lines
2.9 KiB
YAML
74 lines
2.9 KiB
YAML
# .gitlab-ci-release.yml
|
|
|
|
# Job to automatically update the version in the Makefile and push a commit.
|
|
# This runs on a schedule and only acts when a final release is due.
|
|
version:bump:
|
|
stage: version_bump
|
|
image: alpine:3.18 # A small image with git and bash
|
|
rules:
|
|
# Run only on scheduled pipelines targeting the 'master' branch.
|
|
- if: '$CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_REF_NAME == "master"'
|
|
script:
|
|
- |
|
|
echo "Checking if a final release is scheduled today..."
|
|
MONTH=$(date +%-m)
|
|
DAY_OF_WEEK=$(date +%-u)
|
|
DAY_OF_MONTH=$(date +%-d)
|
|
|
|
# Only proceed on the first Monday of an even-numbered month.
|
|
if ! { [ $((MONTH % 2)) -eq 0 ] && [ "$DAY_OF_WEEK" -eq 1 ] && [ "$DAY_OF_MONTH" -le 7 ]; }; then
|
|
echo "Not a final release day. Nothing to do."
|
|
exit 0
|
|
fi
|
|
|
|
echo "✅ Final release day detected. Updating Makefile..."
|
|
|
|
# Set up Git
|
|
apk add --no-cache git
|
|
git config --global user.name "GitLab CI"
|
|
git config --global user.email "gitlab-ci@${CI_SERVER_HOST}"
|
|
|
|
# Set the new version details
|
|
NEW_VERSION=$(date +%Y)
|
|
NEW_PATCHLEVEL=$(printf "%02d" $MONTH)
|
|
|
|
# Use sed to update the Makefile
|
|
sed -i "s/^VERSION = .*/VERSION = $NEW_VERSION/" Makefile
|
|
sed -i "s/^PATCHLEVEL = .*/PATCHLEVEL = $NEW_PATCHLEVEL/" Makefile
|
|
sed -i "s/^SUBLEVEL = .*/SUBLEVEL =/" Makefile
|
|
sed -i "s/^EXTRAVERSION = .*/EXTRAVERSION =/" Makefile
|
|
|
|
# If there are no changes, exit.
|
|
if git diff --quiet Makefile; then
|
|
echo "Makefile is already up-to-date."
|
|
exit 0
|
|
fi
|
|
|
|
# Commit and push the changes
|
|
echo "Pushing version bump to master branch..."
|
|
git add Makefile
|
|
COMMIT_MESSAGE="chore: Bump version to $NEW_VERSION.$NEW_PATCHLEVEL"
|
|
git commit -m "$COMMIT_MESSAGE"
|
|
# The GIT_WRITE_TOKEN is a variable you need to create (see setup below)
|
|
git push "https://gitlab-ci-token:${GIT_WRITE_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" HEAD:master
|
|
|
|
# Job to create the release. This job now triggers from the commit pushed by the 'version:bump' job.
|
|
release:create:
|
|
stage: release
|
|
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
|
rules:
|
|
# Run only on commits to master with a specific commit message.
|
|
- if: '$CI_COMMIT_BRANCH == "master" && $CI_COMMIT_MESSAGE =~ /^chore: Bump version to/'
|
|
script:
|
|
- |
|
|
echo "🚀 Release commit detected. Creating GitLab Release..."
|
|
# Extract the tag name directly from the commit message (e.g., "2025.08")
|
|
TAG_NAME=$(echo "$CI_COMMIT_MESSAGE" | sed -n 's/chore: Bump version to //p')
|
|
RELEASE_TITLE="Release $TAG_NAME"
|
|
|
|
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"
|