-
Notifications
You must be signed in to change notification settings - Fork 0
343 lines (295 loc) · 12 KB
/
release.yml
File metadata and controls
343 lines (295 loc) · 12 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
name: Build and Release
on:
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
default: 'bugfix'
type: choice
options:
- bugfix # Increment patch (x.y.Z)
- feature # Increment minor (x.Y.0)
- major # Increment major (X.0.0)
env:
PROJECT_NAME: cmk-oposs_isam_gpon
permissions:
contents: write
jobs:
# Check if we're on the main branch
check-branch:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check branch
run: |
echo "::group::Branch verification"
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$CURRENT_BRANCH" != "main" ]]; then
echo "::error title=Wrong Branch::Release can only be run from the main branch. Current branch: $CURRENT_BRANCH"
echo "::notice::Please switch to the main branch and try again."
echo "Release attempted from non-main branch: $CURRENT_BRANCH" >> $GITHUB_STEP_SUMMARY
exit 1
fi
echo "::notice title=Branch Check Passed::Running on main branch, proceeding with release."
echo "✅ Branch verification passed - running on main branch" >> $GITHUB_STEP_SUMMARY
echo "::endgroup::"
create-tag:
runs-on: ubuntu-latest
needs: check-branch
outputs:
version: ${{ steps.generate_version.outputs.version }}
version_no_v: ${{ steps.generate_version.outputs.version_no_v }}
release_date: ${{ steps.generate_version.outputs.release_date }}
steps:
- name: Checkout code with history
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate new version
id: generate_version
run: |
set -euo pipefail
echo "::group::Version generation"
# Get the latest tag from git
git fetch --tags
LATEST_TAG=$(git describe --tags --match 'v[0-9]*.[0-9]*.[0-9]*' --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"
# Parse the latest tag to get major, minor, and patch
MAJOR=$(echo $LATEST_TAG | sed -E 's/v([0-9]+)\.([0-9]+)\.([0-9]+).*/\1/')
MINOR=$(echo $LATEST_TAG | sed -E 's/v([0-9]+)\.([0-9]+)\.([0-9]+).*/\2/')
PATCH=$(echo $LATEST_TAG | sed -E 's/v([0-9]+)\.([0-9]+)\.([0-9]+).*/\3/')
echo "Current version: $MAJOR.$MINOR.$PATCH"
# Increment based on release type
case "${{ github.event.inputs.release_type }}" in
major)
MAJOR=$((MAJOR+1))
MINOR=0
PATCH=0
;;
feature)
MINOR=$((MINOR+1))
PATCH=0
;;
bugfix)
PATCH=$((PATCH+1))
;;
esac
# Generate new version
NEW_VERSION="v$MAJOR.$MINOR.$PATCH"
echo "::notice title=New Version::New version will be: $NEW_VERSION (from $LATEST_TAG)"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
# Also create a version without the v prefix for CHANGES.md
echo "version_no_v=$MAJOR.$MINOR.$PATCH" >> $GITHUB_OUTPUT
# Get current date in YYYY-MM-DD format
RELEASE_DATE=$(date +%Y-%m-%d)
echo "release_date=$RELEASE_DATE" >> $GITHUB_OUTPUT
# Add version info to job summary
echo "## Version Information" >> $GITHUB_STEP_SUMMARY
echo "- **Previous version:** $LATEST_TAG" >> $GITHUB_STEP_SUMMARY
echo "- **New version:** $NEW_VERSION" >> $GITHUB_STEP_SUMMARY
echo "- **Release type:** ${{ github.event.inputs.release_type }}" >> $GITHUB_STEP_SUMMARY
echo "- **Release date:** $RELEASE_DATE" >> $GITHUB_STEP_SUMMARY
echo "::endgroup::"
- name: Update CHANGES.md
env:
VERSION_NO_V: ${{ steps.generate_version.outputs.version_no_v }}
RELEASE_DATE: ${{ steps.generate_version.outputs.release_date }}
run: |
set -euo pipefail
echo "::group::Updating CHANGES.md"
# Use Perl to update CHANGES.md
perl -i -e '
use strict;
use warnings;
# Read the file content
my $content = do { local $/; <> };
# Extract the Unreleased section
my ($before, $unreleased_section, $after) =
$content =~ /^(.*?)(## \[Unreleased\].*?)(?=^## \d|\Z)(.*)/ms;
# Initialize variables for sections
my $has_new = 0;
my $has_changed = 0;
my $has_fixed = 0;
my $new_content = "";
my $changed_content = "";
my $fixed_content = "";
# Extract content for each section if it exists
if ($unreleased_section =~ /### New(.*?)(?=^###|\Z)/ms) {
my $section = $1;
$section =~ s/^\s+|\s+$//g;
if ($section) {
$has_new = 1;
$new_content = $section;
}
}
if ($unreleased_section =~ /### Changed(.*?)(?=^###|\Z)/ms) {
my $section = $1;
$section =~ s/^\s+|\s+$//g;
if ($section) {
$has_changed = 1;
$changed_content = $section;
}
}
if ($unreleased_section =~ /### Fixed(.*?)(?=^###|\Z)/ms) {
my $section = $1;
$section =~ s/^\s+|\s+$//g;
if ($section) {
$has_fixed = 1;
$fixed_content = $section;
}
}
# Build new Unreleased section
my $new_unreleased = "## [Unreleased]\n\n".
"### New\n\n### Changed\n\n### Fixed\n\n";
# Build version section with only non-empty sections
my $version_section = "## $ENV{VERSION_NO_V} - $ENV{RELEASE_DATE}\n";
if ($has_new) {
$version_section .= "### New\n$new_content\n\n";
}
if ($has_changed) {
$version_section .= "### Changed\n$changed_content\n\n";
}
if ($has_fixed) {
$version_section .= "### Fixed\n$fixed_content\n\n";
}
# Put it all together
print $before . $new_unreleased . $version_section . $after;
' CHANGES.md
echo "Updated CHANGES.md for version ${VERSION_NO_V}"
echo "::endgroup::"
- name: Commit and Create tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
echo "::group::Creating tag and pushing changes"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
VERSION="${{ steps.generate_version.outputs.version }}"
# Commit CHANGES.md update
git add CHANGES.md
git commit -m "Update CHANGES.md for release ${VERSION}"
echo "::notice title=Commit Created::Created commit with CHANGES.md updates"
# Create and push tag
git tag -a ${VERSION} -m "Release ${VERSION}"
echo "::notice title=Tag Created::Created tag ${VERSION}"
git push origin main
git push origin ${VERSION}
echo "::notice title=Changes Pushed::Pushed changes and tag to repository"
echo "::endgroup::"
build:
needs: create-tag
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.create-tag.outputs.version }}
- name: Build MKP Package
id: build_package
uses: oposs/mkp-builder@v2
with:
version: ${{ needs.create-tag.outputs.version_no_v }}
verbose: 'true'
- name: Add build info to summary
env:
VERSION: ${{ needs.create-tag.outputs.version }}
PACKAGE_FILE: ${{ steps.build_package.outputs.package-file }}
PACKAGE_NAME: ${{ steps.build_package.outputs.package-name }}
PACKAGE_SIZE: ${{ steps.build_package.outputs.package-size }}
run: |
echo "## Build Information" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${VERSION}" >> $GITHUB_STEP_SUMMARY
echo "- **Package:** ${PACKAGE_FILE}" >> $GITHUB_STEP_SUMMARY
echo "- **Package Name:** ${PACKAGE_NAME}" >> $GITHUB_STEP_SUMMARY
echo "- **Size:** ${PACKAGE_SIZE}" >> $GITHUB_STEP_SUMMARY
# Verify package structure
echo "- **Package contents:**" >> $GITHUB_STEP_SUMMARY
tar -tzf "${PACKAGE_FILE}" | while read -r file; do
echo " - $file" >> $GITHUB_STEP_SUMMARY
done
- name: Upload MKP artifact
uses: actions/upload-artifact@v4
with:
name: mkp-package
path: ${{ steps.build_package.outputs.package-file }}
retention-days: 90
create-release:
needs: [build, create-tag]
runs-on: ubuntu-latest
steps:
- name: Checkout code for release notes
uses: actions/checkout@v4
with:
ref: ${{ needs.create-tag.outputs.version }}
- name: Download MKP artifact
uses: actions/download-artifact@v4
with:
name: mkp-package
path: ./
- name: List artifacts
run: |
echo "::group::Listing artifacts"
echo "Downloaded MKP files:"
ls -la *.mkp
echo "::endgroup::"
- name: Extract release notes
id: extract_release_notes
run: |
set -e
echo "::group::Extracting release notes"
# Extract version number without 'v' prefix for CHANGES.md
VERSION_NO_V=$(echo "${{ needs.create-tag.outputs.version }}" | sed 's/^v//')
echo "Looking for version: ${VERSION_NO_V}"
# Use Perl to extract the relevant section - much more reliable than bash/awk
perl -e '
# Get version from first argument
my $version = $ARGV[0];
# Read the entire CHANGES.md file
undef $/;
my $content = <STDIN>;
# Use a regex to find the section for our version
if ($content =~ /## \Q$version\E[^\n]*\n(.*?)(?=\n## [0-9]|$)/s) {
my $section = $1;
# Trim leading/trailing whitespace
$section =~ s/^\s+|\s+$//g;
print $section;
} else {
# Not found, create minimal content
print "CheckMK MKP package release version $version\n";
warn "WARNING: Could not find version $version in CHANGES.md\n";
}
' "$VERSION_NO_V" < CHANGES.md > release_notes_final.md
# Show the result
echo "Release notes extracted to release_notes_final.md:"
cat release_notes_final.md
echo "::endgroup::"
- name: Set version without v prefix
id: set_version_without_v
run: |
TAG=${{ needs.create-tag.outputs.version }}
echo "VERSION=${TAG#v}" >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.create-tag.outputs.version }}
name: Release ${{ env.VERSION }}
draft: false
prerelease: false
body_path: release_notes_final.md
fail_on_unmatched_files: true
files: "*.mkp"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate release summary
run: |
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${{ needs.create-tag.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Release Date:** ${{ needs.create-tag.outputs.release_date }}" >> $GITHUB_STEP_SUMMARY
echo "- **Release URL:** ${{ steps.create_release.outputs.url }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Release Notes" >> $GITHUB_STEP_SUMMARY
cat release_notes_final.md >> $GITHUB_STEP_SUMMARY