Create tags/read versions from version files
Single-sourcing versions for releases can be quite tedious, enough that Python has an article for it: https://packaging.python.org/guides/single-sourcing-package-version/. A lot of the time a release will consist of committing a version file then manually tagging it in git (see for example: https://gitlab.com/gitlab-org/release-cli/-/network/v0.5.0), which can lead to human error.
I've had situations before where I had to do a quick release and in the end the tag didn't match my package version
One way to ensure consistency would be to read the tag for a release from a committed version file. This could be a simple solution or something more elaborate, e.g.:
# Simple: read all contents from a VERSION file as the tag, if present.
release:
tag_name: VERSION
description: CHANGELOG.md
# Complex: extract version regex from common packaging files
# python
release:
tag_name:
file: setup.py
pattern: '^\s+version=\"(.*)\",$'
description: CHANGELOG.md
# npm
release:
tag_name:
file: package.json
pattern: '^\s+\"version\": \"(.*)\",$'
description: CHANGELOG.md
# CMake (C++)
release:
tag_name:
file: CMakeLists.txt
pattern: '^project\(\w+ VERSION (.*)\)$'
description: CHANGELOG.md
This second example would require the same logic as image:
in the gitlab repo, where either a string or a hash can be passed (https://gitlab.com/gitlab-org/gitlab/-/blob/d6805f4fd9d0c73b23fd400bddc0900ae1c2885d/lib/gitlab/ci/build/image.rb#L26-36)
Here is a demo project of how this can be done currently, hacked with grep (I've added the different build systems/languages as an example): https://gitlab.com/nejch1/demo-tag-from-file/-/blob/master/.gitlab-ci.yml
Which creates these releases: https://gitlab.com/nejch1/demo-tag-from-file/-/releases. Obviously this needs to be coupled with proper rules, like except tags or manually triggered jobs etc.
However there are some open points here, for example versioning prefixes and suffixes (1.0.0 -> v1.0.0, 1.0.0 -> 1.0.0-rc1, build numbers etc). Also, if you extract this from a file only for tag_name
, what to do with name
? Usually these would have to support a prefix like "Release <tag_name>"
I'd be willing to work on this as it's quite similar to !67 (merged), but would like to discuss some of the open points first to see if this makes sense :) I think that at least the first option (read from a version file) would be an easy first step since it requires no changes in gitlab, only release-cli.