Skip to content

Commit c4bac29

Browse files
committed
Setup "prepare release" and "release" actions
The `rake vox:tag` task is error prone as it push by default, without an opportunity for a review, or updating a changelog. Rely on the shared actions to prepare release, do release. These expect a version number but this project is special as the current date is the version. Current tags are barely readable in the format YYYYMMDDX where X is a digit used to distinguish 2 releseas made the same day. With this change, we move to the format YYYY-MM-DD-X which we hope is more readable. It is basically a form of [CalVer](https://calver.org/). Because the UTC date is the same all over the world, and to avoid mistakes, we do not allow the user to specify it when preparing / doing releases. The only drawback that we can see is that we can have inconsistency if a release is prepared on one day, but the actual release happen the following day. It is not considered a critical thing since we already have similar date inconsistencies in CHANGELOGs from time to time for user facing projects, and this one is less problematic.
1 parent c89e302 commit c4bac29

File tree

5 files changed

+127
-39
lines changed

5 files changed

+127
-39
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: 'Prepare Release'
3+
4+
on:
5+
workflow_dispatch: {}
6+
7+
permissions: {}
8+
9+
jobs:
10+
get_next_release_version:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
version: ${{ steps.next_release.outputs.version }}
14+
steps:
15+
- name: Check out repo
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setup Ruby
21+
uses: ruby/setup-ruby@v1
22+
with:
23+
ruby-version: '3.3'
24+
bundler-cache: true
25+
26+
- name: Get next release version
27+
id: next_release
28+
run: |
29+
echo version=$(bundle exec rake vox:version:next) >> "$GITHUB_OUTPUT"
30+
31+
prepare_release:
32+
needs: get_next_release_version
33+
uses: OpenVoxProject/shared-actions/.github/workflows/prepare_release.yml@main
34+
with:
35+
allowed_owner: 'OpenVoxProject'
36+
version: ${{ needs.get_next_release_version.outputs.version }}
37+
secrets:
38+
github_pat: ${{ secrets.OPENVOXBOT_COMMIT_AND_PRS }}
39+
ssh_private_key: ${{ secrets.OPENVOXBOT_SSH_PRIVATE_KEY }}

.github/workflows/release.yml

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
11
---
2-
name: Gem Release
2+
name: 'Release'
33

44
on:
5-
push:
6-
tags:
7-
- '*'
5+
workflow_dispatch: {}
86

97
permissions: {}
108

119
jobs:
12-
create-github-release:
13-
# Prevent releases from forked repositories
14-
if: github.repository_owner == 'OpenVoxProject'
15-
name: Create GitHub release
16-
runs-on: ubuntu-24.04
17-
permissions:
18-
contents: write # clone repo and create release
10+
get_current_release_version:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
version: ${{ steps.current_release.outputs.version }}
1914
steps:
20-
- name: Create Release
21-
shell: bash
22-
env:
23-
GH_TOKEN: ${{ github.token }}
24-
run: gh release create --repo ${{ github.repository }} ${{ github.ref_name }} --generate-notes
15+
- name: Check out repo
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setup Ruby
21+
uses: ruby/setup-ruby@v1
22+
with:
23+
ruby-version: '3.3'
24+
bundler-cache: true
25+
26+
- name: Get current release version
27+
id: current_release
28+
run: |
29+
echo version=$(bundle exec rake vox:version:current) >> "$GITHUB_OUTPUT"
30+
31+
release:
32+
uses: OpenVoxProject/shared-actions/.github/workflows/release.yml@main
33+
needs: get_current_release_version
34+
with:
35+
allowed_owner: 'OpenVoxProject'
36+
version: ${{ needs.get_current_release_version.outputs.version }}
37+
secrets:
38+
github_pat: ${{ secrets.OPENVOXBOT_COMMIT_AND_PRS }}
39+
ssh_private_key: ${{ secrets.OPENVOXBOT_SSH_PRIVATE_KEY }}

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ group(:development, optional: true) do
2222
gem 'hashdiff', require: false
2323
end
2424

25+
group(:release, optional: true) do
26+
gem 'faraday-retry', '~> 2.1', require: false
27+
gem 'github_changelog_generator', '~> 1.16.4', require: false
28+
end
29+
2530
#gem 'rubocop', "~> 0.34.2"

tasks/tag.rake

Lines changed: 0 additions & 23 deletions
This file was deleted.

tasks/vox.rake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
def current_version
2+
@current_version ||= File.read(File.expand_path('../CHANGELOG.md', __dir__)).match(/^## \[([^\]]+)\]/) { |match| match[1] }
3+
rescue Errno::ENOENT
4+
puts 'Cannot find current version from CHANGELOG.md. Ignored'
5+
@current_version = ''
6+
end
7+
8+
def next_version
9+
today_prefix = Time.now.utc.strftime('%Y-%m-%d')
10+
11+
if current_version.start_with?(today_prefix)
12+
current_version.next
13+
else
14+
"#{today_prefix}-1"
15+
end
16+
end
17+
18+
desc 'Set the full version of the project'
19+
task 'vox:version:bump:full' do
20+
puts 'This project use the current date as version number. No bump needed.'
21+
end
22+
23+
desc 'Get the current version of the project'
24+
task 'vox:version:current' do
25+
puts current_version
26+
end
27+
28+
desc 'Get the next version of the project'
29+
task 'vox:version:next' do
30+
puts next_version
31+
end
32+
33+
begin
34+
require "github_changelog_generator/task"
35+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
36+
config.header = <<~HEADER.chomp
37+
# Changelog
38+
All notable changes to this project will be documented in this file.
39+
HEADER
40+
config.user = "openvoxproject"
41+
config.project = "puppet-runtime"
42+
config.exclude_labels = %w[dependencies duplicate question invalid wontfix wont-fix modulesync skip-changelog]
43+
config.since_tag = "202501080"
44+
config.future_release = next_version
45+
end
46+
rescue LoadError
47+
task :changelog do
48+
abort("Run `bundle install --with release` to install the `github_changelog_generator` gem.")
49+
end
50+
end
51+
52+
task 'release:prepare': :changelog

0 commit comments

Comments
 (0)