Skip to content

Commit 6183bf3

Browse files
authored
Merge pull request #36 from OpenVoxProject/release-actions
2 parents 95f98d0 + c29f102 commit 6183bf3

File tree

5 files changed

+163
-39
lines changed

5 files changed

+163
-39
lines changed

.github/workflows/prepare_release.yml

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: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
class Version
2+
attr_reader :date, :x, :raw
3+
4+
def initialize(v)
5+
@raw = v
6+
7+
if (m = v.match(%r{\A(?<date>\d{4}-\d{2}-\d{2})-(?<x>\d+)\z}))
8+
@date = m['date']
9+
@x = m['x'].to_i
10+
else
11+
@date = nil
12+
@x = 1
13+
end
14+
end
15+
16+
def self.load_from_changelog
17+
changelog = File.expand_path('../CHANGELOG.md', __dir__)
18+
version = File.read(changelog).match(/^## \[([^\]]+)\]/) { |match| match[1] }
19+
new(version)
20+
rescue Errno::ENOENT
21+
new('')
22+
end
23+
24+
def to_s
25+
if malformed?
26+
raw
27+
else
28+
"#{date}-#{x}"
29+
end
30+
end
31+
32+
def next!
33+
if date == today
34+
@x += 1
35+
else
36+
@date = today
37+
@x = 1
38+
end
39+
40+
self
41+
end
42+
43+
private
44+
45+
def malformed?
46+
date.nil?
47+
end
48+
49+
def today
50+
Time.now.strftime('%Y-%m-%d')
51+
end
52+
end
53+
54+
desc 'Set the full version of the project'
55+
task 'vox:version:bump:full' do
56+
puts 'This project use the current date as version number. No bump needed.'
57+
end
58+
59+
desc 'Get the current version of the project'
60+
task 'vox:version:current' do
61+
puts Version.load_from_changelog
62+
end
63+
64+
desc 'Get the next version of the project'
65+
task 'vox:version:next' do
66+
puts Version.load_from_changelog.next!
67+
end
68+
69+
begin
70+
require "github_changelog_generator/task"
71+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
72+
config.header = <<~HEADER.chomp
73+
# Changelog
74+
All notable changes to this project will be documented in this file.
75+
HEADER
76+
config.user = "openvoxproject"
77+
config.project = "puppet-runtime"
78+
config.exclude_labels = %w[dependencies duplicate question invalid wontfix wont-fix modulesync skip-changelog]
79+
config.since_tag = "202501080"
80+
config.future_release = Version.load_from_changelog.next!.to_s
81+
end
82+
rescue LoadError
83+
task :changelog do
84+
abort("Run `bundle install --with release` to install the `github_changelog_generator` gem.")
85+
end
86+
end
87+
88+
task 'release:prepare': :changelog

0 commit comments

Comments
 (0)