Files
gitlab-ci/gitlab_release/.gitlab-ci.yml
Jon Lockwood f76cabeeb0 fix(gitlab_release): Adjust release workflow
Previous release workflow only allowed version increment of RC on development brnach.

adjust to the following workflow:
    master branch: automatically increment the version
    development branch: option to manually increment version (RC increment only)

!2
2021-08-07 14:31:19 +09:30

56 lines
3.2 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 development $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 development
- RELEASE_VERSION_CURRENT=$(cz -n cz_nfc version --project)
script:
- "$MY_COMMAND"
- if [ "$CI_COMMIT_BRANCH" == "development" ] ; then RELEASE_CHANGELOG=$(cz -n cz_nfc bump --changelog --changelog-to-stdout --prerelease rc); else RELEASE_CHANGELOG=$(cz -n cz_nfc bump --changelog --changelog-to-stdout); fi
- 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
- if [ "$CI_COMMIT_BRANCH" == "master" ] ; then git checkout master; fi
- if [ "$CI_COMMIT_BRANCH" == "master" ] ; then git push --set-upstream origin master; fi
- if [ "$CI_COMMIT_BRANCH" == "master" ] ; then git merge --no-ff development; fi
- if [ "$CI_COMMIT_BRANCH" == "master" ] ; then git push origin master; fi
after_script:
- rm -Rf repo
rules:
- if: "$CI_COMMIT_AUTHOR =='NFC CI <CI@nfc-gitlab>'"
when: never
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
allow_failure: false
- if: '$CI_COMMIT_BRANCH == "development"'
when: manual
allow_failure: true
- when: never