Commit 9cd3d261 authored by Yorick Peterse's avatar Yorick Peterse

Ignore pre-release tags when generating changelogs

When generating a changelog without specifying the `to` argument, we use
the tag of the last release. If a project has any pre-release tags, such
as GitLab itself, we would end up using such a tag. But this is
undesired, as changelogs are usually only updated for stable releases
(as is the case for GitLab for example).

To solve this, we no longer consider pre-release tags. This means that
in the above example we'd instead use the tag of the last stable
release, as one would expect.

This fixes https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/1574
parent 218571ef
...@@ -37,6 +37,11 @@ module Repositories ...@@ -37,6 +37,11 @@ module Repositories
next unless matches next unless matches
# When using this class for generating changelog data for a range of
# commits, we want to compare against the tag of the last _stable_
# release; not some random RC that came after that.
next if matches[:prerelease]
version = matches[:version] version = matches[:version]
tags[version] = tag tags[version] = tag
versions << version versions << version
......
---
title: Ignore prerelease tags when generating changelogs
merge_request: 55065
author:
type: changed
...@@ -311,9 +311,9 @@ Supported attributes: ...@@ -311,9 +311,9 @@ Supported attributes:
| `message` | string | no | The commit message to produce when committing the changes, defaults to `Add changelog for version X` where X is the value of the `version` argument. | | `message` | string | no | The commit message to produce when committing the changes, defaults to `Add changelog for version X` where X is the value of the `version` argument. |
If the `from` attribute is unspecified, GitLab uses the Git tag of the last If the `from` attribute is unspecified, GitLab uses the Git tag of the last
version that came before the version specified in the `version` attribute. For stable version that came before the version specified in the `version`
this to work, your project must create Git tags for versions using one of the attribute. For this to work, your project must create Git tags for versions
following formats: using one of the following formats:
- `vX.Y.Z` - `vX.Y.Z`
- `X.Y.Z` - `X.Y.Z`
...@@ -322,12 +322,14 @@ Where `X.Y.Z` is a version that follows [semantic ...@@ -322,12 +322,14 @@ Where `X.Y.Z` is a version that follows [semantic
versioning](https://semver.org/). For example, consider a project with the versioning](https://semver.org/). For example, consider a project with the
following tags: following tags:
- v1.0.0-pre1
- v1.0.0 - v1.0.0
- v1.1.0 - v1.1.0
- v2.0.0 - v2.0.0
If the `version` attribute is `2.1.0`, GitLab uses tag v2.0.0. And when the If the `version` attribute is `2.1.0`, GitLab uses tag v2.0.0. And when the
version is `1.1.1`, or `1.2.0`, GitLab uses tag v1.1.0. version is `1.1.1`, or `1.2.0`, GitLab uses tag v1.1.0. The tag `v1.0.0-pre1` is
never used, because it's a pre-release tag, and pre-release tags are ignored.
If `from` is unspecified and no tag to use is found, the API produces an error. If `from` is unspecified and no tag to use is found, the API produces an error.
To solve such an error, you must explicitly specify a value for the `from` To solve such an error, you must explicitly specify a value for the `from`
......
...@@ -13,18 +13,19 @@ RSpec.describe Repositories::PreviousTagFinder do ...@@ -13,18 +13,19 @@ RSpec.describe Repositories::PreviousTagFinder do
tag2 = double(:tag2, name: 'v1.1.0') tag2 = double(:tag2, name: 'v1.1.0')
tag3 = double(:tag3, name: 'v2.0.0') tag3 = double(:tag3, name: 'v2.0.0')
tag4 = double(:tag4, name: '0.9.0') tag4 = double(:tag4, name: '0.9.0')
tag5 = double(:tag4, name: 'v0.8.0-pre1') tag5 = double(:tag5, name: 'v0.8.0-pre1')
tag6 = double(:tag6, name: 'v0.7.0')
allow(project.repository) allow(project.repository)
.to receive(:tags) .to receive(:tags)
.and_return([tag1, tag3, tag2, tag4, tag5]) .and_return([tag1, tag3, tag2, tag4, tag5, tag6])
expect(finder.execute('2.1.0')).to eq(tag3) expect(finder.execute('2.1.0')).to eq(tag3)
expect(finder.execute('2.0.0')).to eq(tag2) expect(finder.execute('2.0.0')).to eq(tag2)
expect(finder.execute('1.5.0')).to eq(tag2) expect(finder.execute('1.5.0')).to eq(tag2)
expect(finder.execute('1.0.1')).to eq(tag1) expect(finder.execute('1.0.1')).to eq(tag1)
expect(finder.execute('1.0.0')).to eq(tag4) expect(finder.execute('1.0.0')).to eq(tag4)
expect(finder.execute('0.9.0')).to eq(tag5) expect(finder.execute('0.9.0')).to eq(tag6)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment