From d634a376bb21da6a53d8363c9bc54e94da3407a0 Mon Sep 17 00:00:00 2001 From: Vojtech Mares Date: Sun, 12 May 2024 12:06:27 +0200 Subject: [PATCH] ci: add find next semver tag and use to to create gitlab release and tag too --- .gitlab-ci.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8152031..3184608 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,12 +3,18 @@ default: stages: - build + - pre-release + - release build: stage: build variables: IMAGE: $CI_REGISTRY_IMAGE TAG: $CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA + rules: + - if: $CI_COMMIT_TAG + variables: + TAG: $CI_COMMIT_TAG before_script: - echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY - docker info @@ -16,3 +22,37 @@ build: - docker buildx create --name yggdrasil --use - docker buildx build --provenance=false --platform linux/amd64,linux/arm64 -t $IMAGE:$TAG --push . - docker manifest inspect $IMAGE:$TAG + +semver-tag: + stage: pre-release + image: ghcr.io/vojtechmares/container-images/release-tools:latest + rules: + - if: $CI_COMMIT_TAG + when: never + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + variables: + # Disable shallow cloning so that svu can diff between tags + GIT_DEPTH: 0 + script: + - echo "TAG=$(svu next)" >> release.env + artifacts: + reports: + dotenv: release.env + +release: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + needs: + - job: prepare_job + artifacts: true + rules: + - if: $CI_COMMIT_TAG + when: never + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + script: + - echo "Creating release for $TAG" + release: + name: 'Release $TAG' + description: 'Created using the release-cli' + tag_name: '$TAG' + ref: '$CI_COMMIT_SHA'