From 24a56728bcabd1a0dc3994b7733562386d36b61e Mon Sep 17 00:00:00 2001 From: Gin Derick Magno <gmagno@stratpoint.com> Date: Tue, 27 Jun 2023 07:20:16 +0000 Subject: [PATCH] Update .gitlab-ci.yaml --- .gitlab-ci.yaml | 76 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yaml b/.gitlab-ci.yaml index be5a59f..3b32748 100644 --- a/.gitlab-ci.yaml +++ b/.gitlab-ci.yaml @@ -1,13 +1,75 @@ +image: node + stages: + - check_build - build + - set_tag + +build: + stage: build + script: + - npm install + only: + - /^koda-chm-.*-stg$/ + - /^koda-chm-.*-dev$/ -variables: - VERSION: "1.0.0" +.setup: + before_script: + - LATEST_BUILD="$(tail -n 1 build.log)" + - ENVIRONMENT=$(echo "$CI_COMMIT_REF_NAME" | awk -F '-' '{print $NF}') + - PROJECT_NAME="${LATEST_BUILD%%-*}" + - PROJECT_NAME_WITH_ENV="${LATEST_BUILD%%-*}.$ENVIRONMENT" + - FORMATTED_PROJECT_NAME="${PROJECT_NAME_WITH_ENV//./-}" + - echo $FORMATTED_PROJECT_NAME + - CURRENT_DATE=$(date +%Y.%m.%d) + - VERSION=$(echo "$LATEST_BUILD" | awk -F '-' '{print $NF}') + - NEW_VERSION="${VERSION%.*}.$((${VERSION##*.} + 1))" + - NEW_BUILD="${PROJECT_NAME_WITH_ENV}-${CURRENT_DATE}-${NEW_VERSION}" + - NEW_BUILD_LOG="${PROJECT_NAME}-${CURRENT_DATE}-${NEW_VERSION}" -build_job: - stage: build +check_build: + extends: .setup + stage: check_build + script: + - if [[ "$CI_COMMIT_REF_NAME" != "$FORMATTED_PROJECT_NAME" ]]; then exit 1; fi + only: + - /^koda-chm-.*-stg$/ + - /^koda-chm-.*-dev$/ + + +.tag: + extends: .setup + stage: set_tag + + +set-tag-dev: + extends: .tag + script: + - | + echo "$NEW_BUILD_LOG" | tee -a build.log + git status + git fetch --tags + echo "$CI_COMMIT_REF_NAME" + git add build.log + # "[ci skip]" and "-o ci-skip" prevent a CI trigger loop + git commit -m "[ci skip] updated build $NEW_BUILD" + git push -o ci-skip https://oauth2:$ACCESS_TOKEN@gitlab.com/test-group1430/runner-testing.git HEAD:$CI_COMMIT_REF_NAME + #Tag commit (can be used without commiting files) + git tag "$NEW_BUILD" + git push --tags https://oauth2:$ACCESS_TOKEN@gitlab.com/test-group1430/runner-testing.git HEAD:$CI_COMMIT_REF_NAME + only: + - /^koda-chm-.*-dev$/ + +set-tag-stg: + extends: .tag script: - - echo "Building version $VERSION" - - make build + - | + git status + git fetch --tags + echo "$CI_COMMIT_REF_NAME" + #Tag commit (can be used without commiting files) + git tag "$NEW_BUILD" + git push --tags https://oauth2:$ACCESS_TOKEN@gitlab.com/test-group1430/runner-testing.git HEAD:$CI_COMMIT_REF_NAME + only: - - main # Run the job only for the master branch (customize as needed) + - /^koda-chm-.*-stg$/ -- GitLab