-
Notifications
You must be signed in to change notification settings - Fork 0
232 lines (203 loc) · 7.62 KB
/
release.yml
File metadata and controls
232 lines (203 loc) · 7.62 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
name: Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (without v prefix, e.g. 1.2.3)'
required: true
type: string
env:
RELEASE_VERSION: ${{ github.event_name == 'workflow_dispatch' && format('v{0}', github.event.inputs.version) || github.ref_name }}
IMG: ghcr.io/openvirtualcluster/openvirtualcluster-operator:${{ github.event_name == 'workflow_dispatch' && format('v{0}', github.event.inputs.version) || github.ref_name }}
jobs:
validate-version:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
outputs:
is_valid: ${{ steps.validate.outputs.is_valid }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate version
id: validate
run: |
INPUT_VERSION="${{ github.event.inputs.version }}"
# Check if version is a valid semver (X.Y.Z format)
if ! [[ $INPUT_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must be in format X.Y.Z (e.g. 1.2.3)"
echo "is_valid=false" >> $GITHUB_OUTPUT
exit 1
fi
# Get all existing tags
git fetch --tags
# Check if tag already exists
if git tag | grep -q "^v$INPUT_VERSION$"; then
echo "Error: Version v$INPUT_VERSION already exists"
echo "is_valid=false" >> $GITHUB_OUTPUT
exit 1
fi
# Find latest version
LATEST_TAG=$(git tag -l "v*.*.*" | sort -V | tail -n 1)
if [ -z "$LATEST_TAG" ]; then
echo "No previous versions found. This will be the first release."
echo "is_valid=true" >> $GITHUB_OUTPUT
exit 0
fi
LATEST_VERSION=${LATEST_TAG#v}
# Split versions into components
IFS='.' read -r LATEST_MAJOR LATEST_MINOR LATEST_PATCH <<< "$LATEST_VERSION"
IFS='.' read -r INPUT_MAJOR INPUT_MINOR INPUT_PATCH <<< "$INPUT_VERSION"
# Convert to integers for comparison
LATEST_MAJOR=$((10#$LATEST_MAJOR))
LATEST_MINOR=$((10#$LATEST_MINOR))
LATEST_PATCH=$((10#$LATEST_PATCH))
INPUT_MAJOR=$((10#$INPUT_MAJOR))
INPUT_MINOR=$((10#$INPUT_MINOR))
INPUT_PATCH=$((10#$INPUT_PATCH))
# Validate version is newer
if [ $INPUT_MAJOR -gt $LATEST_MAJOR ]; then
# Major version bump is valid
echo "Valid major version bump: $LATEST_VERSION -> $INPUT_VERSION"
echo "is_valid=true" >> $GITHUB_OUTPUT
elif [ $INPUT_MAJOR -eq $LATEST_MAJOR ] && [ $INPUT_MINOR -gt $LATEST_MINOR ]; then
# Minor version bump is valid
echo "Valid minor version bump: $LATEST_VERSION -> $INPUT_VERSION"
echo "is_valid=true" >> $GITHUB_OUTPUT
elif [ $INPUT_MAJOR -eq $LATEST_MAJOR ] && [ $INPUT_MINOR -eq $LATEST_MINOR ] && [ $INPUT_PATCH -gt $LATEST_PATCH ]; then
# Patch version bump is valid
echo "Valid patch version bump: $LATEST_VERSION -> $INPUT_VERSION"
echo "is_valid=true" >> $GITHUB_OUTPUT
else
echo "Error: Version $INPUT_VERSION is not newer than the latest version $LATEST_VERSION"
echo "New version must increment major, minor, or patch number"
echo "is_valid=false" >> $GITHUB_OUTPUT
exit 1
fi
build-and-push:
needs: [validate-version]
if: github.event_name != 'workflow_dispatch' || needs.validate-version.outputs.is_valid == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract version
id: get_version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
fi
- name: Build and push multi-platform image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.IMG }}
labels: |
org.opencontainers.image.title=openvirtualcluster-operator
org.opencontainers.image.description=OpenVirtualCluster Operator
org.opencontainers.image.version=${{ steps.get_version.outputs.VERSION }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
release:
needs: [build-and-push]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create directory for changelog config
run: mkdir -p .github/workflows/changelog_builder
- name: Create changelog config
run: |
cat > .github/workflows/changelog_builder/config.json << EOF
{
"categories": [
{
"title": "## 🚀 Features",
"labels": ["feature", "enhancement"]
},
{
"title": "## 🐛 Fixes",
"labels": ["fix", "bugfix", "bug"]
},
{
"title": "## 📝 Documentation",
"labels": ["documentation"]
},
{
"title": "## 🧰 Maintenance",
"labels": ["chore", "maintenance"]
}
],
"ignore_labels": ["ignore"],
"sort": "ASC",
"template": "${{CHANGELOG}}"
}
EOF
- name: "Build Changelog"
id: github_release
uses: mikepenz/release-changelog-builder-action@v3
with:
configuration: ".github/workflows/changelog_builder/config.json"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ env.RELEASE_VERSION }}
name: ${{ env.RELEASE_VERSION }}
body: ${{ steps.github_release.outputs.changelog }}
generate_release_notes: true
build-installer:
needs: [build-and-push]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Build installer
run: |
make build-installer
env:
IMG: ${{ env.IMG }}
- name: Upload installer artifact
uses: actions/upload-artifact@v3
with:
name: installer
path: dist/install.yaml
- name: Upload installer to release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ env.RELEASE_VERSION }}
files: dist/install.yaml