Provides next release version and release notes from git commit messages
1.8K
This script is to be used in CICD pipelines to provide new version number (bases on commit messages) and releses notes (also bases on commit messages).
Repository: https://github.com/stepin/git-parse-commits
Example usage for Gitlab:
create_changelog:
stage: "build"
image:
name: "stepin/git-parse-commits:latest"
entrypoint: [""]
variables:
GIT_DEPTH: "0"
script:
- git-parse-commits version
- CURRENT_VERSION="$(git-parse-commits currentVersion)"
- RELEASE_VERSION="$(git-parse-commits --tag-prefix 'v' releaseVersion)"
- echo "RELEASE_VERSION=$RELEASE_VERSION\nCURRENT_VERSION=$CURRENT_VERSION" > relNotes.env
- git-parse-commits --tag-prefix 'v' releaseNotes > releaseNotes.md
artifacts:
reports:
dotenv: relNotes.env
paths:
- releaseNotes.md
expire_in: 1 day
rules:
- if: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_REF_NAME == "main" && $CI_PIPELINE_SOURCE != "schedule"
- if: $CI_COMMIT_REF_NAME == "release/*" && $CI_PIPELINE_SOURCE != "schedule"
release:
stage: "release"
image:
name: "registry.gitlab.com/gitlab-org/release-cli:latest"
entrypoint: [""]
script:
- echo "Release $RELEASE_VERSION"
release:
tag_name: "$RELEASE_VERSION"
tag_message: "Release $RELEASE_VERSION"
description: "releaseNotes.md"
assets:
links:
- name: "Container Image $CI_COMMIT_TAG"
url: "https://$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA"
needs:
- "create_changelog"
rules:
- if: $CI_COMMIT_REF_NAME == "main" && $CI_PIPELINE_SOURCE != "schedule"
when: manual
allow_failure: true
- if: $CI_COMMIT_REF_NAME == "release/*" && $CI_PIPELINE_SOURCE != "schedule"
when: manual
allow_failure: true
(CURRENT_VERSION can be used for non-release builds)
docker run --rm -it stepin/git-parse-commits --help
usage: git-parse-commits [-h] [-j] [-t [TAG_PREFIX]] [-s [SCOPE]] [-i [INITIAL_REVISION]] [-l [LAST_REVISION]] [--tag]
{version,currentVersion,lastReleaseVersion,releaseVersion,releaseNotes} ...
Provides next release version and release notes from git commit messages.
positional arguments:
{version,currentVersion,lastReleaseVersion,releaseVersion,releaseNotes}
version Prints version of this tool
currentVersion Prints current version (useful for non-release builds)
lastReleaseVersion Prints version of last release
releaseVersion Prints version of next release from git commit messages
releaseNotes Prints release notes from git commit messages
options:
-h, --help show this help message and exit
-j, --json Output in json format
-t [TAG_PREFIX], --tag-prefix [TAG_PREFIX]
prefix for tags (optional)
-s [SCOPE], --scope [SCOPE]
scope to filter release note items
-i [INITIAL_REVISION], --initial-revision [INITIAL_REVISION]
start range from next revision
-l [LAST_REVISION], --last-revision [LAST_REVISION]
stop on this revision
--tag add tag prefix to version (only if tag prefix is defined)
Several header lines are possible. We are living in a real world when sometimes several tasks are combined in one MR (like feature + several 1 line fixes or just several fixes). If you can create several test environments in parallel for QAs and other developers it's better to use individual MRs. If not -- you are in a good company, this repo is to help you.
Just use following options:
--initial-revision commit1 --last-revision commit2
Start to write compatible commit messages from now but full usages of this tool will be possible only since next release.
Simple monorepos are supported. Like if you have client, api, and worker components.
In this case use --scope=client and --tag-prefix=client options to get release notes
and version for client component. If next version is empty it means that according to git
commit messages nothing is changes for client and it should not be released.
git log --oneline --pretty="- %s" --no-merges
It's like https://www.conventionalcommits.org/en/v1.0.0/ but several header lines are supported. It's case for backend development when there is no possibility to create several test envs in parallel.
[header(s)]
[optional body]
[optional footer(s)]
There are 3 cases (first one is full, other 2 is with defaults):
type(scope): descriptiontype: descriptiondescriptiondefault scope it *: it means that this is change for all scopes when filter by scope is applied.
default type is feat
also - in the beginning of line is acceptable.
if description has "WIP" that line is skipped.
Valid examples:
anything, it will not be parsed
it's https://git-scm.com/docs/git-interpret-trailers format. I.e. key: value.
Special key is "BREAKING CHANGE": it will lease to increase of major digit in version.
Scope is any string with letters and numbers.
Special scope is '*': it means that change is applied to the full repo, not to particular scope. For example, license change or build system change.
Types allow us to group changes in release notes and understand how to increase version numbers.
Script has following configuration:
types:
- types: ["*"]
increase: minor
group: Features
- types: ["fix", "refactor", "docs", "perf"]
increase: patch
group: Fixes
- types: ["chore", "ci", "build", "style", "test"]
increase: patch
group: Other
- types: ["skip", "wip", "minor"]
increase: none
group: null
- types: ["BREAKING CHANGE"]
increase: major
group: Features
* type means default.
Recommendations:
feat, fix, chore, and skip typesWIP in description if you will add more commits for this topic for sure but I prefer skip approach! mark. Like feat!: new featureCurrently there is no way to change it using command line options. Just change it in source code.
It's non-commercial project. I will try to fix all reported bug (that I can reproduce) but without any short-time commitments.
It's better to provide MR/patch for new features. Most probably new features without code will not be implemented as for me this repo is feature complete.
Content type
Image
Digest
sha256:af2159753…
Size
326.5 MB
Last updated
over 1 year ago
docker pull stepin/git-parse-commits