Skip to content

Commit 67d4ca8

Browse files
author
Igor Stepin
committed
minor: better readme
1 parent e0a0e8c commit 67d4ca8

File tree

1 file changed

+132
-36
lines changed

1 file changed

+132
-36
lines changed

README.md

+132-36
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,33 @@
33

44
## Intro
55

6-
When we create release in Gitea / Gitlab / Github we need to fill 3 fields:
6+
When we create release in Gitea / Gitlab / Github we need to fill 4 fields:
77
- Release name
88
- Tag name
99
- Release description
1010
- Tag commit message
1111

12+
For releases there are 2 main cases: pre-releases and releases.
13+
1214
Yes, it's not that hard to fill it every time automatically but it anyway takes time,
13-
and it's error-prone process.
15+
and it's an error-prone process.
1416

15-
So, this script is introduced to automate this process. Some key points:
17+
So, this script is introduced to automate this task. Some key points:
1618
- Human decides what will be in release note but decision point is moved to MR merge time (when
1719
we specify MR commit message)
1820
- Human decides when release should happen (start manual job)
19-
- If something is not working it's still possible to create release from UI without these CI job
21+
- If something is not working it's still possible to create release from UI without these CI jobs
22+
23+
24+
## Features
25+
26+
- Detects version of current (old) release, next release or pre-release from tags and tag descriptions.
27+
- Creates release notes in Markdown and plain-text formats
28+
- Supports multiline conventional commits (multiple lines to changelog from 1 commit)
29+
- Supports semver tags (like `1.2.3` or `1.2.3-my-pre-release.1`)
30+
- Supports monorepo tags (tags with prefixes like `componentX-1.2.3`)
31+
- Supports tag prefixes like `v`
32+
- JSON output for easier automation
2033

2134

2235
## Details
@@ -26,72 +39,145 @@ This script is to be used in CICD pipelines to provide new version number
2639

2740
Docker image: [stepin/git-parse-commits:latest](https://hub.docker.com/r/stepin/git-parse-commits)
2841

29-
Example how to use with Docker:
42+
### Example how to use with Docker
3043

3144
```shell
32-
docker run --rm -it -v "${PWD}:/git" -w /git --user "$(id -u)" stepin/git-parse-commits:2.2.2 releaseVersion
33-
docker run --rm -it -v "${PWD}:/git" -w /git --user "$(id -u)" stepin/git-parse-commits:2.2.2 releaseNotes
34-
docker run --rm -it -v "${PWD}:/git" -w /git --user "$(id -u)" stepin/git-parse-commits:2.2.2 releaseNotes --short
45+
# it can be used as version for pre-preleases
46+
docker run --rm -it -v "${PWD}:/git" -w /git --user "$(id -u)" stepin/git-parse-commits:2.3.0 currentVersion
47+
# it can be used as version for releases
48+
docker run --rm -it -v "${PWD}:/git" -w /git --user "$(id -u)" stepin/git-parse-commits:2.3.0 releaseVersion
49+
# it's for plain-text release notes
50+
docker run --rm -it -v "${PWD}:/git" -w /git --user "$(id -u)" stepin/git-parse-commits:2.3.0 releaseNotes --short
51+
# it's for Markdown release notes
52+
docker run --rm -it -v "${PWD}:/git" -w /git --user "$(id -u)" stepin/git-parse-commits:2.3.0 releaseNotes
3553
```
3654

37-
Example usage for Gitlab:
55+
### Example usage for Gitlab
3856

3957
```yaml
4058
create_changelog:
4159
stage: "build"
4260
image:
43-
name: "stepin/git-parse-commits:2.2.2"
44-
entrypoint: [""]
61+
name: "stepin/git-parse-commits:2.3.0"
62+
entrypoint: [ "" ]
4563
variables:
4664
GIT_DEPTH: "0"
4765
script:
48-
- git-parse-commits version
66+
- if $(git rev-parse --is-shallow-repository); then git fetch --unshallow ; fi
4967
- CURRENT_VERSION="$(git-parse-commits currentVersion)"
5068
- RELEASE_VERSION="$(git-parse-commits releaseVersion)"
5169
- echo "RELEASE_VERSION=$RELEASE_VERSION" >> relNotes.env
5270
- echo "CURRENT_VERSION=$CURRENT_VERSION" >> relNotes.env
5371
- cat relNotes.env
54-
- git-parse-commits releaseNotes > releaseNotes.md
55-
- git-parse-commits releaseNotes --short > gitTagCommitMessage.txt
72+
- git-parse-commits releaseNotes | tee releaseNotes.md
73+
- git-parse-commits releaseNotes --short | tee releaseNotes.txt
5674
artifacts:
5775
reports:
5876
dotenv: relNotes.env
5977
paths:
6078
- releaseNotes.md
61-
- gitTagCommitMessage.txt
79+
- releaseNotes.txt
6280
expire_in: 1 day
6381
rules:
6482
- if: $CI_MERGE_REQUEST_IID
6583
- if: $CI_COMMIT_REF_NAME == "main" && $CI_PIPELINE_SOURCE != "schedule"
6684
- if: $CI_COMMIT_REF_NAME == "release/*" && $CI_PIPELINE_SOURCE != "schedule"
85+
- if: $CI_COMMIT_TAG =~ /^\d+\.\d+\.\d+$/
86+
needs: [ ]
87+
88+
create_changelog_prerelease:
89+
stage: "build"
90+
image:
91+
name: "stepin/git-parse-commits:2.3.0"
92+
entrypoint: [ "" ]
93+
variables:
94+
GIT_DEPTH: "0"
95+
script:
96+
- if $(git rev-parse --is-shallow-repository); then git fetch --unshallow ; fi
97+
- CURRENT_VERSION="$(git-parse-commits -pre currentVersion)"
98+
- RELEASE_VERSION="$(git-parse-commits -pre releaseVersion)"
99+
- echo "RELEASE_VERSION=$RELEASE_VERSION" >> relNotes.env
100+
- echo "CURRENT_VERSION=$CURRENT_VERSION" >> relNotes.env
101+
- cat relNotes.env
102+
- git-parse-commits -pre releaseNotes | tee releaseNotes.md
103+
- git-parse-commits -pre releaseNotes --short | tee releaseNotes.txt
104+
artifacts:
105+
reports:
106+
dotenv: relNotes.env
107+
paths:
108+
- releaseNotes.md
109+
- releaseNotes.txt
110+
expire_in: 1 day
111+
rules:
112+
- if: $CI_COMMIT_TAG =~ /^\d+\.\d+\.\d+-.*/
113+
needs: [ ]
67114

68115
release:
69116
stage: "release"
70117
image:
71-
name: "registry.gitlab.com/gitlab-org/release-cli:latest"
72-
entrypoint: [""]
118+
name: registry.gitlab.com/gitlab-org/cli:latest
119+
entrypoint: [ "" ]
120+
before_script:
121+
- git config --global user.email "${GITLAB_USER_EMAIL}"
122+
- git config --global user.name "${GITLAB_USER_NAME}"
123+
- git remote remove tag-origin || true
124+
- git remote add tag-origin "https://MY_TOKEN_NAME:$MY_TAGS_PUSH_TOKEN@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
125+
- glab auth login --job-token $CI_JOB_TOKEN --hostname $CI_SERVER_HOST --api-protocol $CI_SERVER_PROTOCOL
73126
script:
74-
- echo "Release $RELEASE_VERSION"
75-
release:
76-
tag_name: "$RELEASE_VERSION"
77-
tag_message: "gitTagCommitMessage.txt"
78-
description: "releaseNotes.md"
79-
assets:
80-
links:
81-
- name: "Container Image $CI_COMMIT_TAG"
82-
url: "https://$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA"
127+
- echo "Release $RELEASE_VERSION"
128+
- git tag -F releaseNotes.txt "$RELEASE_VERSION"
129+
- git push tag-origin tag "$RELEASE_VERSION"
130+
- |
131+
glab release create "$RELEASE_VERSION" --name "Pre-release $RELEASE_VERSION" \
132+
--ref "$CI_COMMIT_SHA" \
133+
--notes-file "releaseNotes.md"
134+
rules:
135+
- if: $CI_COMMIT_REF_NAME == "main" && $CI_PIPELINE_SOURCE != "schedule"
136+
when: manual
137+
allow_failure: true
138+
- if: $CI_COMMIT_REF_NAME == "release/*" && $CI_PIPELINE_SOURCE != "schedule"
139+
when: manual
140+
allow_failure: true
141+
- if: $CI_MERGE_REQUEST_IID
142+
when: manual
143+
allow_failure: true
83144
needs:
84-
- "create_changelog"
145+
- "create_changelog"
146+
147+
pre_release:
148+
stage: "release"
149+
image:
150+
name: registry.gitlab.com/gitlab-org/cli:latest
151+
entrypoint: [ "" ]
152+
before_script:
153+
- git config --global user.email "${GITLAB_USER_EMAIL}"
154+
- git config --global user.name "${GITLAB_USER_NAME}"
155+
- git remote remove tag-origin || true
156+
- git remote add tag-origin "https://MY_TOKEN_NAME:$MY_TAGS_PUSH_TOKEN@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
157+
- glab auth login --job-token $CI_JOB_TOKEN --hostname $CI_SERVER_HOST --api-protocol $CI_SERVER_PROTOCOL
158+
script:
159+
- echo "Release $CURRENT_VERSION"
160+
- git tag -F releaseNotes.txt "$CURRENT_VERSION"
161+
- git push tag-origin tag "$CURRENT_VERSION"
162+
- |
163+
glab release create "$CURRENT_VERSION" --name "Pre-release $CURRENT_VERSION" \
164+
--ref "$CI_COMMIT_SHA" \
165+
--notes-file "releaseNotes.md"
85166
rules:
86-
- if: $CI_COMMIT_REF_NAME == "main" && $CI_PIPELINE_SOURCE != "schedule"
87-
when: manual
88-
allow_failure: true
89-
- if: $CI_COMMIT_REF_NAME == "release/*" && $CI_PIPELINE_SOURCE != "schedule"
90-
when: manual
91-
allow_failure: true
167+
- if: $CI_MERGE_REQUEST_IID
168+
when: manual
169+
allow_failure: true
170+
needs:
171+
- "create_changelog"
92172
```
93173
(CURRENT_VERSION can be used for non-release builds)
94174
175+
Gitlab don't support multiline variables in dotenv. Also, `release` keyword and `release-cli`
176+
doesn't support file as input for `tag_message` (only as input for `description`). So, it means
177+
that `release` keyword can't be used in practice for our case. As workaround, there is
178+
`releaseNotes --one-line` that produces only 1 line and can be used for `tag_message` but in this
179+
case release notes will be only in release page in Gitlab but not in tag message in Git.
180+
95181

96182
## Help
97183

@@ -109,6 +195,7 @@ Options:
109195
-s, --scope=<text> Scope to filter release note items
110196
-i, --initial-revision=<text> Start range from next revision
111197
-l, --last-revision=<text> Stop on this revision
198+
-pre, --allow-pre-releases Don't drop pre-release tags
112199
-h, --help Show this message and exit
113200

114201
Commands:
@@ -141,9 +228,13 @@ it's better to use individual MRs. If not -- you are in a good company, this rep
141228
142229
### How it differs from https://github.com/git-chglog/git-chglog ?
143230
144-
- multiple header lines support
231+
- multiple header lines support for single commit
145232
- release version calculation
146233
234+
### How it differs from https://github.com/choffmeister/git-describe-semver ?
235+
236+
- release notes are produced, not only versions
237+
147238
### How to get release notes between 2 commits?
148239
149240
Just use following options:
@@ -167,8 +258,8 @@ commit messages nothing is changes for client and it should not be released.
167258
168259
### When this tool is not suitable?
169260
170-
- multiple components with complext dependencies: this tools can be used for version and release notes but it will not release or skip them in some dependency tree. In this case tools like https://lerna.js.org/ can be used.
171-
- 1 MR per task is used. In this case change log can be generated using following command:
261+
- multiple components with complex dependencies: this tools can be used for version and release notes, but it will not release or skip them in some dependency tree. In this case tools like https://lerna.js.org/ can be used.
262+
- 1 MR per task is always used. In this case change log can be generated using following command:
172263
173264
```bash
174265
git log --oneline --pretty="- %s" --no-merges
@@ -261,6 +352,11 @@ It's better to provide MR/patch for new features. Most probably new features
261352
without code will not be implemented as for me this repo is feature complete.
262353

263354

355+
## Known issues
356+
357+
`lastReleaseVersion` don't work properly if repo has only 1 commit. As it's a rare case
358+
it's not a priority to fix.
359+
264360
## Development
265361

266362
Feel free to send MRs/patches.

0 commit comments

Comments
 (0)