Skip to content

Commit b470a43

Browse files
authored
Merge pull request #150 from minrk/sortable-versions
Add `useChartVersion` and change appended version suffix (now like `1.2.3-0.dev.git.3.h123`)
2 parents d4900b0 + 885dd63 commit b470a43

File tree

6 files changed

+442
-148
lines changed

6 files changed

+442
-148
lines changed

README.md

Lines changed: 104 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,27 @@ Chartpress will infer chart versions and image tags using a few key pieces of
2525
information.
2626

2727
1. `tag`: If not directly set by `--tag`, it will be inferred from most recent
28-
commit that is tagged in the _current branch_, or be set to 0.0.1 if no
29-
commit is tagged.
28+
commit that is tagged in the _current branch_
29+
(as determined by `git describe`)
30+
or be set to 0.0.1 if no commit is tagged.
3031
1. If the `tag` has a leading `v` but is otherwise a valid
31-
[SemVer2](https://semver.org) version, it will be stripped from Chart.yaml
32+
[SemVer2](https://semver.org) version, the `v` will be stripped from Chart.yaml
3233
before its set as Helm 3 requires Helm chart versions to be SemVer2
3334
compliant.
3435
1. The latest commit modifying content in a _relevant path_ since `tag`.
35-
1. `n`: The latest commit's distance to the tagged commit, described as 3 or
36-
more numbers, prefixed with n.
37-
1. `h`: The latest commit's abbreviated hash. which is often 7-8 characters,
38-
prefixed with h.
39-
1. If `tag` (like `0.10.0` or `0.10.0-beta.1`) contains a `-`, a `tag.n.h`
40-
format will be used instead of a `tag-n.h` format to be SemVer 2 compliant.
36+
1. `n`: The number of commits since the latest tagged commit on the branch, as an integer.
37+
1. `hash`: The latest commit's abbreviated hash, which is often 7-8 characters,
38+
prefixed with `h`.
39+
1. If `tag` (like `0.10.0` or `0.10.0-beta.1`) contains a `-`, a `tag.git.n.hash`
40+
format will be used, and otherwise a `tag-0.dev.git.n.hash` format will be used.
4141
1. If `--long` is specified or not. If `--long` is specified, tagged commits
42-
will be written out with the `n.h` part appended to it, looking something
43-
like `n000.gabcd123`
42+
will always be written out with the `.git.n.hash` part appended to it, looking something
43+
like `1.0.0-0.dev.git.0.habcd123`
44+
45+
When producing a development version (with `.git.n.hash` on the end),
46+
The _base_ version can come from one of two places,
47+
depending on your configuration.
48+
See [Controlling development version](#controlling-development-versions-in-chart.yaml) for more info.
4449

4550
### Examples chart versions and image tags
4651

@@ -49,13 +54,13 @@ order that could come from using chartpress.
4954

5055
```
5156
0.8.0
52-
0.8.0-n004.hasdf123
53-
0.8.0-n010.hsdfg234
57+
0.8.0-0.dev.git.4.hasdf123
58+
0.8.0-0.dev.git.10.hsdfg234
5459
0.9.0-beta.1
55-
0.9.0-beta.1.n001.hdfgh345
56-
0.9.0-beta.1.n005.hfghj456
60+
0.9.0-beta.1.git.1.hdfgh345
61+
0.9.0-beta.1.git.5.hfghj456
5762
0.9.0-beta.2
58-
0.9.0-beta.2.n001.hghjk567
63+
0.9.0-beta.2.git.1.hghjk567
5964
0.9.0-beta.3
6065
0.9.0
6166
```
@@ -167,6 +172,12 @@ charts:
167172
# --reset flag. It defaults to "0.0.1-set.by.chartpress". This is a valid
168173
# SemVer 2 version, which is required for a helm lint command to succeed.
169174
resetVersion: 1.2.3
175+
# Use the version in Chart.yaml for the base version,
176+
# instead of the latest tag from `git describe`
177+
# This gives you more control over development version tags
178+
# and lets you ensure prerelease tags are always sorted in the right order
179+
useChartVersion: true
180+
170181
# The git repo whose gh-pages contains the charts. This can be a local
171182
# path such as "." as well but if matching <organization>/<repo> will be
172183
# assumed to be a separate GitHub repository.
@@ -228,6 +239,83 @@ charts:
228239
- linux/arm64
229240
```
230241
242+
### Controlling development versions in Chart.yaml
243+
244+
Like some "package version in version control" tools,
245+
you don't need to manage versions at all in chartpress except by tagging commits.
246+
247+
However, relying only on tags results in "development versions" (versions published from commits after a release)
248+
having somewhat confusing prerelease versions.
249+
250+
After publishing e.g. `1.2.3`, the next version will be `1.2.3-0.dev.git.1.habc`.
251+
According to Semantic Versioning,
252+
this is a "pre release" (good, it should be excluded from default installation),
253+
but it means it comes _before_ 1.2.3 (wrong! it's 1 commit _newer_ than 1.2.3).
254+
This is because prereleases should be defined relative to the _next_ release,
255+
not the _last_ release. But git tags only store the _last_ release!
256+
257+
Chartpress 2.0 adds an option `chart.useChartVersion`,
258+
which changes the base version to use when setting the chart version.
259+
Instead of using the version of the last tag found via `git describe`,
260+
it uses the version found in Chart.yaml.
261+
262+
The main benefits of this are:
263+
264+
1. ensuring that published prerelease versions show up in the right order, and
265+
2. giving you control over the version of a prerelease chart (is it 2.0.0-0.dev or 1.3.1-0.dev?)
266+
267+
Instead of publishing the sequence:
268+
269+
- 1.2.3
270+
- 1.2.3-0.dev.git.1.habc (later than 1.2.3, but sorts _before_ 1.2.3!)
271+
272+
You can publish
273+
274+
- 1.2.3
275+
- 1.3.0-0.dev.git.1.habc (prerelease based on the _next_ version, not _last_)
276+
277+
where chartpress will use the version in your Chart.yaml as the base version,
278+
instead of the last tag on the branch.
279+
280+
This takes some extra configuration, and steps in your release process
281+
to update the version in your Chart.yaml.
282+
283+
1. You must set `useChartVersion: true` in your chartpress.yaml:
284+
285+
```yaml
286+
charts:
287+
- name: mychart
288+
useChartVersion: true
289+
```
290+
291+
2. You must control the version in Chart.yaml, especially after making a release.
292+
293+
A release process would generally look like this:
294+
295+
```bash
296+
V=1.2.3
297+
chartpress --reset --tag "$V"
298+
git commit -am "release $V"
299+
git tag -am "release $V" "$V"
300+
git push --atomic --follow-tags
301+
302+
# back to development
303+
NEXT_V=1.3.0-0.dev
304+
chartpress --reset --tag "$NEXT_V"
305+
git commit -am "Back to $NEXT_V"
306+
git push --atomic
307+
```
308+
309+
Any prerelease fields (such as `-0.dev` above, or `-alpha.1`)
310+
will be left as-is, with the `.git.n.hash` suffix added.
311+
312+
If the version in Chart.yaml is not a prerelease,
313+
a prelease version will be constructed with `-0.dev.git.n.hash`.
314+
315+
When you use this configuration,
316+
`chartpress --reset` strips the `.git...` suffix from the chart version,
317+
ignoring the `resetVersion` config.
318+
231319
## Caveats
232320

233321
### Shallow clones

0 commit comments

Comments
 (0)