gitlab-ci.yml: automatically tag the repository

Automatically tag the repository when we bump
the version of container image.

Related-to: TOR-1942

Signed-off-by: Dejan Jesenko <dejan.jesenko@toradex.com>
This commit is contained in:
Dejan Jesenko 2022-02-10 11:25:25 +01:00
parent 98853d997c
commit e16f45cee3

View File

@ -27,6 +27,7 @@ services:
stages:
- lint
- repository tagging
- build-rt-tests
- build-rt-tests-multiarch
- deploy
@ -130,6 +131,29 @@ lint_dockerfile:
# - DL3029 (do not use --platform flag with FROM)
- hadolint */Dockerfile --failure-threshold warning --info DL3008 --info DL3029
# Make sure to create access token in "Settings/Access Tokens" section with "write_repository" scope selected.
# Then in "Settings/CI/CD/" section add a variable with key "GIT_TOKEN" and a value of the access token. Also mask the variable.
tag:
stage: repository tagging
needs: []
before_script:
- if [ -z ${GIT_TOKEN} ]; then echo "Missing variable GIT_TOKEN." && exit 1; fi
- TAGS="rt-tests-${RT_TESTS_MAJOR}.${RT_TESTS_MINOR}.${RT_TESTS_PATCH} stress_tests-${RT_TESTS_MAJOR}.${RT_TESTS_MINOR}.${RT_TESTS_PATCH}"
script:
- apk update && apk add git
- git remote set-url origin https://gitlab-ci-token:${GIT_TOKEN}@${CI_REPOSITORY_URL#*@}
- for TAG in ${TAGS};
do
if git ls-remote --tags origin | grep ${TAG} > /dev/null; then
echo "${TAG} tag already exists.";
else
echo "Tagging repository with ${TAG} tag.";
git tag --delete ${TAG} > /dev/null 2>&1 || true;
git tag ${TAG};
git push -o ci.skip origin ${TAG};
fi
done
# Enable experimental features in Docker client (experimental feature are needed for manifest)
.do_docker_experimental: &do_docker_experimental
- mkdir -p $HOME/.docker