feat(git_release): Migrated from ansible-roles

Mibrated from
    commit: 295fe5b1db

After migration, updated for gitlab-ci.

Changes to be committed:
	new file:   gitlab_release/.gitlab-ci.yml
	new file:   gitlab_release/README.md
	new file:   gitlab_release/python-module/cz_nfc/cz_nfc.py
	new file:   gitlab_release/python-module/cz_nfc/setup.py
	new file:   gitlab_release/requirements.txt

issue #1
This commit is contained in:
2021-08-03 15:44:31 +09:30
parent 2a3266fb53
commit 6678a3dbab
5 changed files with 165 additions and 0 deletions

View File

@ -0,0 +1,49 @@
.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:$API_RO_GIT_WR@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:
- echo "your script here"
after_script:
- 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
- git tag -d $RELEASE_TAG
- 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 rev-parse $CI_COMMIT_BRANCH)
- echo "[DEBUG] RELEASE_TAG_SHA1[$RELEASE_TAG_SHA1]"
- git push
- release-cli create --name "Release $RELEASE_TAG" --tag-name "$RELEASE_TAG" --ref "$RELEASE_TAG_SHA1" --description "$RELEASE_CHANGELOG"
- 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

65
gitlab_release/README.md Normal file
View File

@ -0,0 +1,65 @@
# Gitlab Release
This job bumps the version, updates the changelog, creates a git tag and creates a gitlab release. The git tag and release title use [semantic versioning](https://semver.org/). for this job to function correctly a `.cz.yaml` is required in the root of the repository. this file contains the [commitizen](https://github.com/commitizen-tools/commitizen) config and the version details. This job runs on successful completion of previous jobs and only on `development` and `master` branches.
This job provides the following badge:
- None
## Dependencies
- None
## your .gitlab-ci.yml changes
To use this job add the following to your `.gitlab-ci.yml` file
``` yaml
stages:
- release
include:
- remote: https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/raw/development/gitlab_release/.gitlab-ci.yml
Gitlab Release:
extends:
- .gitlab_release
```
> if you wish to run any commands you can safely override `script` with your own commands. if these commands create any output that is not excluded in `.gitignore` they will be commited to the repository.
## CI/CD Variables required
| var name | Description |
|:----:|:----|
| API_RO_GIT_WR | *this must be a personal token that has write access to the repository* |
## Job Workflow
This CI job's workflow is:
1. updates the changelog from the commits
1. commit the changelog to git
1. adds a `git tag` to the changelog commit.
1. pushes the change back to the repo
1. creates a git release from the `git tag`
## Artifacts
- None
## License
To view the license for this folder and any sub-folders, refer [here](https://gitlab.com/nofusscomputing/projects/gitlab-ci)

View File

@ -0,0 +1,40 @@
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
from commitizen import git
from commitizen.cz.base import BaseCommitizen
class nfc_cz(BaseCommitizen):
bump_pattern = r"^(break|new|fix|hotfix|ci|docs)"
bump_map = {"break": "MAJOR", "new": "MINOR", "fix": "PATCH", "hotfix": "PATCH", "ci": "PATCH", "docs": "PATCH"}
changelog_pattern = "^(break|new|fix|hotfix|ci|docs)"
change_type_order = ["BREAKING CHANGE", "feat", "fix", "refactor", "perf", "docs", "ci"]
change_type_map = {
"feat": "Features",
"fix": "Bug Fixes",
"refactor": "Code Refactor",
"perf": "Performance improvements",
"docs": "Documentaton / Guides",
"ci": "Continious Integration"
}
commit_parser = r"^(?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE|ci|docs)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:\s(?P<message>.*)?"
def changelog_message_builder_hook(self, parsed_message: dict, commit: git.GitCommit) -> dict:
rev = commit.rev
m = parsed_message["message"]
parsed_message["message"] = f"{rev} - {m}"
return parsed_message
def questions(self) -> list:
raise NotImplementedError("Not Implemented yet")
def message(self, answers: dict) -> str:
raise NotImplementedError("Not Implemented yet")
discover_this = nfc_cz

View File

@ -0,0 +1,10 @@
from setuptools import setup
setup(
name='NFC commitizen Custom Bump Map and changelog',
version='0.1.0',
py_modules=['cz_nfc'],
license='MIT',
long_description='this is a long description',
install_requires=['commitizen']
)

View File

@ -0,0 +1 @@
commitizen