CI: Automate releases with a scheduled job
Introduce a new CI job in .gitlab-ci-release.yml to automate the
creation of project releases.
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>
This commit is contained in:
48
.gitlab-ci-release.yml
Normal file
48
.gitlab-ci-release.yml
Normal file
@@ -0,0 +1,48 @@
|
||||
# .gitlab-ci-release.yml
|
||||
|
||||
# This single job handles the creation of both final releases and release candidates.
|
||||
# It determines which type of release to create based on the date.
|
||||
release:create:
|
||||
stage: release
|
||||
# We use the official release-cli image provided by GitLab.
|
||||
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
||||
rules:
|
||||
# This job only runs on scheduled pipelines that target the 'master' branch.
|
||||
- if: '$CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_REF_NAME == "master"'
|
||||
script:
|
||||
- |
|
||||
echo "🚀 Checking release conditions for pipeline on branch '$CI_COMMIT_REF_NAME'..."
|
||||
# Use %-m, %-u, %-d to avoid issues with zero-padding (e.g., '08' being an invalid octal number).
|
||||
MONTH=$(date +%-m)
|
||||
DAY_OF_WEEK=$(date +%-u) # 1=Monday, 7=Sunday
|
||||
DAY_OF_MONTH=$(date +%-d)
|
||||
|
||||
# FINAL RELEASE: Occurs on the first Monday of an even-numbered month.
|
||||
# 1. The month is even (e.g., February, April...).
|
||||
# 2. The day of the week is Monday.
|
||||
# 3. The day is within the first 7 days of the month.
|
||||
if [ $((MONTH % 2)) -eq 0 ] && [ "$DAY_OF_WEEK" -eq 1 ] && [ "$DAY_OF_MONTH" -le 7 ]; then
|
||||
|
||||
# This is a Final Release
|
||||
TAG_NAME=$(date +%Y.%m)
|
||||
RELEASE_TITLE="Release $TAG_NAME"
|
||||
echo "✅ Conditions met for a Final Release. Creating tag: $TAG_NAME"
|
||||
|
||||
else
|
||||
|
||||
# This is a Release Candidate (RC)
|
||||
# RC index is calculated based on the day of the month:
|
||||
# Days 1-14 -> rc1, Days 15-28 -> rc2, etc.
|
||||
RC_INDEX=$(( (DAY_OF_MONTH - 1) / 14 + 1 ))
|
||||
TAG_NAME="$(date +%Y.%m)-rc${RC_INDEX}"
|
||||
RELEASE_TITLE="Release Candidate $TAG_NAME"
|
||||
echo "📝 Conditions met for a Release Candidate. Creating tag: $TAG_NAME"
|
||||
|
||||
fi
|
||||
|
||||
echo "Executing release-cli to create the release..."
|
||||
release-cli create \
|
||||
--name "$RELEASE_TITLE" \
|
||||
--tag-name "$TAG_NAME" \
|
||||
--description "Automated release created by GitLab CI. Based on commit $CI_COMMIT_SHORT_SHA on the '$CI_COMMIT_REF_NAME' branch." \
|
||||
--ref "$CI_COMMIT_SHA"
|
||||
@@ -1,5 +1,8 @@
|
||||
# SPDX-License-Identifier: GPL-2.0+
|
||||
|
||||
include:
|
||||
- local: '.gitlab-ci-release.yml'
|
||||
|
||||
variables:
|
||||
DEFAULT_TAG: ""
|
||||
MIRROR_DOCKER: docker.io
|
||||
@@ -24,6 +27,7 @@ stages:
|
||||
- test.py
|
||||
- sjg-lab
|
||||
- world build
|
||||
- release
|
||||
|
||||
.buildman_and_testpy_template: &buildman_and_testpy_dfn
|
||||
stage: test.py
|
||||
|
||||
Reference in New Issue
Block a user