CMake/.gitlab/ci/cmake_version_update.sh
Brad King 1f3eb6c4d4 ci: update copyright year as part of CMake Nightly Date Stamp
Extend commit 0f82d07266 (ci: add job to update CMake Nightly Date
Stamp, 2024-12-17) to update the year range in `Copyright.txt` on
January 1 so we don't have to update it manually once per year.
Our `CMake.Copyright` test verifies that these match.
2024-12-18 09:04:14 -05:00

47 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
if test "$CI_COMMIT_REF_NAME" != "master"; then
echo "The version update may run only on the 'master' branch."
exit 1
fi
# A project-specific access token must be provided by
# the pipeline schedule under which this job runs.
if test -z "$CMAKE_CI_GIT_ACCESS_TOKEN"; then
echo "No CMAKE_CI_GIT_ACCESS_TOKEN is available."
exit 1
fi
git config user.name "${CMAKE_CI_AUTHOR_NAME-Kitware Robot}"
git config user.email "${CMAKE_CI_AUTHOR_EMAIL-kwrobot@kitware.com}"
git remote add upstream "https://oauth2:$CMAKE_CI_GIT_ACCESS_TOKEN@gitlab.kitware.com/$CI_PROJECT_PATH.git"
# Repeat a few times in case we lose a race.
n=6
for try in $(seq $n); do
git fetch upstream "$CI_COMMIT_REF_NAME"
git reset -q --hard FETCH_HEAD
Source/CMakeVersion.bash
git update-index -q --ignore-missing --refresh
modified=$(git diff-index --name-only HEAD -- "Source/CMakeVersion.cmake" "Copyright.txt")
if test -n "$modified"; then
echo "version changed"
git add -u
git commit -m "CMake Nightly Date Stamp"
if git push --push-option=ci.skip upstream "HEAD:$CI_COMMIT_REF_NAME"; then
exit 0
else
echo "Try #$try failed to fast-forward."
fi
else
echo "version unchanged"
exit 0
fi
sleep 30
done
# Give up after failing too many times.
exit 1