Files
gitlab-ci/gitlab_release/.gitlab-ci.yml
Jon Lockwood 7a69685b53 refactor(gitlab_release): Dont conduct any release, git push or tag delete if the version was not bumped
Without this change the job would have failed due to no actual changes being made and the logic attemping to make the same existing changes.
2021-08-04 11:29:22 +09:30

50 lines
2.7 KiB
YAML

.gitlab_release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
before_script:
- if [ "0$JOB_ROOT_DIR" == "0" ]; then ROOT_DIR=gitlab-ci; else ROOT_DIR=$JOB_ROOT_DIR ; fi
- echo "[DEBUG] ROOT_DIR[$ROOT_DIR]"
- mkdir -p "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME"
- mkdir -p "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests"
- apk update
- apk add git
- apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
- python -m ensurepip && ln -sf pip3 /usr/bin/pip
- pip install --upgrade pip
- pip install -r $ROOT_DIR/gitlab_release/requirements.txt
- pip install $ROOT_DIR/gitlab_release/python-module/cz_nfc/.
- 'CLONE_URL="https://gitlab-ci-token:$GIT_COMMIT_TOKEN@gitlab.com/$CI_PROJECT_PATH.git"'
- echo "[DEBUG] CLONE_URL[$CLONE_URL]"
- git clone -b $CI_COMMIT_BRANCH $CLONE_URL repo
- cd repo
- git branch
- git config --global user.email "CI@nfc-gitlab"
- git config --global user.name "NFC CI"
- git push --set-upstream origin $CI_COMMIT_BRANCH
- RELEASE_VERSION_CURRENT=$(cz -n cz_nfc version --project)
script:
- "$MY_COMMAND"
- RELEASE_CHANGELOG=$(cz -n cz_nfc bump --changelog --changelog-to-stdout)
- RELEASE_VERSION_NEW=$(cz -n cz_nfc version --project)
- RELEASE_TAG=v$RELEASE_VERSION_NEW
- if [ "0$RELEASE_VERSION_CURRENT" == "0$RELEASE_VERSION_NEW" ]; then echo "[DEBUG] No tag to delete, version was not bumped"; else git tag -d $RELEASE_TAG; fi
- echo "[DEBUG] RELEASE_VERSION_CURRENT[$RELEASE_VERSION_CURRENT]"
- echo "[DEBUG] RELEASE_CHANGELOG[$RELEASE_CHANGELOG]"
- echo "[DEBUG] RELEASE_VERSION_NEW[$RELEASE_VERSION_NEW]"
- echo "[DEBUG] RELEASE_TAG[$RELEASE_TAG]"
- RELEASE_TAG_SHA1=$(git log -n1 --format=format:"%H")
- echo "[DEBUG] RELEASE_TAG_SHA1[$RELEASE_TAG_SHA1]"
- if [ "0$RELEASE_VERSION_CURRENT" == "0$RELEASE_VERSION_NEW" ]; then echo "[DEBUG] No push will be conducted, version was not bumped"; else git push; fi
- if [ "0$RELEASE_VERSION_CURRENT" == "0$RELEASE_VERSION_NEW" ]; then echo "[DEBUG] No release will be created, version was not bumped"; else release-cli create --name "Release $RELEASE_TAG" --tag-name "$RELEASE_TAG" --ref "$RELEASE_TAG_SHA1" --description "$RELEASE_CHANGELOG"; fi
after_script:
- rm -Rf repo
rules:
- if: "$CI_COMMIT_AUTHOR =='NFC CI <CI@nfc-gitlab>'"
when: never
- if: '$CI_COMMIT_BRANCH == "development"'
- if: '$TRIGGER_RELEASE == "True" && $CI_COMMIT_BRANCH == "development"'
when: on_success
allow_failure: false
- when: never