diff options
author | Yorick Peterse <yorick@yorickpeterse.com> | 2021-04-27 15:05:07 +0300 |
---|---|---|
committer | Yorick Peterse <yorick@yorickpeterse.com> | 2021-04-27 15:13:08 +0300 |
commit | 5ca77983480861729d8768c5a22ff3ce9a77dabe (patch) | |
tree | 6925e8e3deedc5629cb4e9f951e44d2d0108af6a | |
parent | 67520d7b374eea77f7412600271a90193bdd2e8a (diff) |
Prepare for upcoming changelog workflow changes
This adds a configuration file for generating changelogs using the
GitLab API (done using Release Tools), as well as change Danger to
remind developers of these upcoming changes (similar to what we're doing
in gitlab-org/gitlab).
Omnibus, Pages and Helm are already using this new approach. Our current
plan is to also roll this out to remaining projects (GitLab Rails and
Gitaly) per May 22nd.
See https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/1564 for
more information.
-rw-r--r-- | .gitlab/changelog_config.yml | 38 | ||||
-rw-r--r-- | danger/changelog/Dangerfile | 58 |
2 files changed, 96 insertions, 0 deletions
diff --git a/.gitlab/changelog_config.yml b/.gitlab/changelog_config.yml new file mode 100644 index 000000000..7aa18cc8f --- /dev/null +++ b/.gitlab/changelog_config.yml @@ -0,0 +1,38 @@ +--- +# Settings for generating changelogs using the GitLab API. See +# https://docs.gitlab.com/ee/api/repositories.html#generate-changelog-data for +# more information. +categories: + added: Added + fixed: Fixed + changed: Changed + deprecated: Deprecated + removed: Removed + security: Security + performance: Performance + other: Other +template: | + {% if categories %} + {% each categories %} + ### {{ title }} ({% if single_change %}1 change{% else %}{{ count }} changes{% end %}) + + {% each entries %} + - [{{ title }}]({{ commit.reference }})\ + {% if author.contributor %} by {{ author.reference }}{% end %}\ + {% if commit.trailers.MR %}\ + ([merge request]({{ commit.trailers.MR }}))\ + {% else %}\ + {% if merge_request %}\ + ([merge request]({{ merge_request.reference }}))\ + {% end %}\ + {% end %}\ + {% if commit.trailers.EE %}\ + **GitLab Enterprise Edition**\ + {% end %} + + {% end %} + + {% end %} + {% else %} + No changes. + {% end %} diff --git a/danger/changelog/Dangerfile b/danger/changelog/Dangerfile index d2facce07..1a7029768 100644 --- a/danger/changelog/Dangerfile +++ b/danger/changelog/Dangerfile @@ -29,6 +29,28 @@ merge_request: %<mr_iid>s #{SEE_DOC} SUGGEST_COMMENT +CATEGORIES = YAML + .load_file(File.expand_path('../../.gitlab/changelog_config.yml', __dir__)) + .fetch('categories') + .keys + .freeze + +def check_changelog_trailer(commit) + trailer = commit.message.match(/^Changelog:\s*(?<category>.+)$/) + + return :missing if trailer.nil? || trailer[:category].nil? + + category = trailer[:category] + + return :valid if CATEGORIES.include?(category) + + self.fail( + "Commit #{commit.sha} uses an invalid changelog category: #{category}" + ) + + :invalid +end + def check_changelog(path) raw_file = File.read(path) yaml = YAML.safe_load(raw_file) @@ -75,4 +97,40 @@ elsif changelog_needed format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: mr_title, labels: presented_no_changelog_labels) end +if changelog_needed + checked = 0 + + git.commits.each do |commit| + case check_changelog_trailer(commit) + when :valid, :invalid + checked += 1 + end + end + + if checked == 0 + message <<~MSG + We are in the process of rolling out a new workflow for adding changelog entries. This new workflow uses Git commit subjects and Git trailers to generate changelogs. This new approach will soon replace the current YAML based approach. + + To ease the transition process, we recommend you start using both the old and new approach in parallel. This is not required at this time, but will make it easier to transition to the new approach in the future. To do so, pick the commit that should go in the changelog and add a `Changelog` trailer to it. For example: + + ``` + This is my commit's subject line + + This is the optional commit body. + + Changelog: added + ``` + + The value of the `Changelog` trailer should be one of the following: added, fixed, changed, deprecated, removed, security, performance, other. + + For more information, take a look at the following resources: + + - `https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/1564` + - https://docs.gitlab.com/ee/api/repositories.html#generate-changelog-data + + If you'd like to see the new approach in action, take a look at the commits in [the Omnibus repository](https://gitlab.com/gitlab-org/omnibus-gitlab/-/commits/master). + MSG + end +end + # vim: ft=ruby |