-
Notifications
You must be signed in to change notification settings - Fork 9
194 lines (170 loc) · 6.78 KB
/
release.yml
File metadata and controls
194 lines (170 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: 'Release'
on:
workflow_call:
inputs:
version:
description: 'Version to be released.'
required: true
type: string
base-branch:
description: 'The branch that will be used as the origin for the release branch (defaults to repo default branch).'
required: false
default: ''
type: string
prerelease:
description: 'Mark this release as a prerelease'
required: false
default: false
type: boolean
include_changelog_in_release:
description: 'Include content from CHANGELOG.md in the release notes'
required: false
default: false
type: boolean
bump_to_rc_after_release:
description: 'Bump version to next RC after release (for semver repos)'
required: false
default: false
type: boolean
secrets:
github_pat:
# Provide a fine-grained token with the following repository permissions:
# * Contents: Read and write
# * Metadata: Read-only (mandatory, default)
# * Pull requests: Read and write
description: 'The token used to interact with GitHub'
required: true
ssh_private_key:
description: 'The SSH private key used to sign commits and tags.'
required: true
env:
GIT_AUTHOR_NAME: OpenVoxProjectBot
GIT_AUTHOR_EMAIL: 215568489+OpenVoxProjectBot@users.noreply.github.com
GIT_COMMITTER_NAME: OpenVoxProjectBot
GIT_COMMITTER_EMAIL: 215568489+OpenVoxProjectBot@users.noreply.github.com
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
BUNDLE_WITH: release
jobs:
release:
name: 'Release'
environment: release
runs-on: ubuntu-24.04
if: github.repository_owner == 'OpenVoxProject'
steps:
- name: Validate version format
run: |
# Agent/Server look like 8.23.0-1 or just 8.23.0
# puppet-runtime looks like 2025.09.08.1
if ! echo "${{ inputs.version }}" | grep -qE '^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(-[[:alnum:].]+)?$|^[[:digit:]]{4}\.[[:digit:]]{2}\.[[:digit:]]{2}\.[[:digit:]]+$'; then
echo "::error::Version '${{ inputs.version }}' does not match expected format (semver like 8.23.0 or calver like 2025.09.08.1)"
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ inputs.base-branch }}
fetch-depth: 0
token: ${{ secrets.github_pat }}
- name: Setup Ruby
if: inputs.bump_to_rc_after_release || inputs.include_changelog_in_release
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true
- name: Add SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.ssh_private_key }}" > ~/.ssh/github_actions
chmod 600 ~/.ssh/github_actions
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add ~/.ssh/github_actions
- name: Setup git
run: |
git config --global user.email "$GIT_AUTHOR_EMAIL"
git config --global user.name "$GIT_AUTHOR_NAME"
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/github_actions
git config --global commit.gpgsign true
git config --global tag.gpgsign true
- name: Check tag doesn't already exist
run: |
if git rev-parse "${{ inputs.version }}" >/dev/null 2>&1; then
echo "::error::Tag '${{ inputs.version }}' already exists!"
exit 1
fi
- name: Extract release notes from CHANGELOG.md
id: extract_notes
if: inputs.include_changelog_in_release
run: |
ruby << 'EOF'
version = "${{ inputs.version }}"
unless File.exist?('CHANGELOG.md')
warn "::warning::No CHANGELOG.md found, release will use auto-generated notes only"
File.write(ENV['GITHUB_OUTPUT'], "has_notes=false\n", mode: 'a')
exit 0
end
changelog = File.read('CHANGELOG.md')
# Match ## [VERSION]...\n then capture everything until the next ## [ or end of file
match = changelog.match(/^## \[#{Regexp.escape(version)}\][^\n]*\n(?<notes>.+?)(?=^## \[|\z)/m)
unless match
warn "::warning::Could not find version #{version} in CHANGELOG.md, release will use auto-generated notes only"
File.write(ENV['GITHUB_OUTPUT'], "has_notes=false\n", mode: 'a')
exit 0
end
notes = match[:notes].strip
if notes.empty?
warn "::warning::Version #{version} section is empty, release will use auto-generated notes only"
File.write(ENV['GITHUB_OUTPUT'], "has_notes=false\n", mode: 'a')
exit 0
end
File.write('release_notes.md', notes)
File.write(ENV['GITHUB_OUTPUT'], "has_notes=true\n", mode: 'a')
puts "Extracted release notes for version #{version}"
EOF
- name: Create signed tag
run: |
git tag -s -m "Release ${{ inputs.version }}" "${{ inputs.version }}"
git push origin "${{ inputs.version }}"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.github_pat }}
run: |
RELEASE_ARGS=(
"${{ inputs.version }}"
--title "${{ inputs.version }}"
--generate-notes
)
if [ "${{ inputs.prerelease }}" = "true" ]; then
RELEASE_ARGS+=(--prerelease)
fi
if [ "${{ steps.extract_notes.outputs.has_notes }}" = "true" ]; then
RELEASE_ARGS+=(--notes-file release_notes.md)
fi
gh release create "${RELEASE_ARGS[@]}"
- name: Compute the next RC version
id: future_version
if: inputs.bump_to_rc_after_release
run: |
ruby << EOF >> "$GITHUB_OUTPUT"
c = "${{ inputs.version }}".split(".")
next_version = if c[-1] =~ /\A(\d+-rc)(\d+)\z/
c[-1] = "#{\$1}#{\$2.succ}"
c.join(".")
else
c[2].succ!
c[0..2].join(".") + "-rc0"
end
puts "version=#{next_version}"
EOF
- name: Bump version to avoid confusion with code older than the tag
if: inputs.bump_to_rc_after_release
run: |
bundle exec rake vox:version:bump:full[${{ steps.future_version.outputs.version }}]
- name: Commit version bump
if: inputs.bump_to_rc_after_release
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_user_name: ${{ env.GIT_COMMITTER_NAME }}
commit_user_email: ${{ env.GIT_COMMITTER_EMAIL }}
commit_author: '${{ env.GIT_AUTHOR_NAME }} <${{ env.GIT_AUTHOR_EMAIL }}>'
commit_message: "Bump version to ${{ steps.future_version.outputs.version }}"