-
Notifications
You must be signed in to change notification settings - Fork 45
198 lines (170 loc) · 7.5 KB
/
release.yaml
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
name: "Release"
run-name: Release new ${{ inputs.version-type }} from ${{ github.ref_name }}
on:
workflow_dispatch:
inputs:
version-type:
description: "Version type"
required: true
type: choice
default: "alpha"
options:
- "alpha"
- "beta"
- "GA"
what-is-new:
description: "What's new: it should be a JSON-formatted list such as [\"feature 1\", \"feature 2\"]"
required: false
default: "[]"
type: string
jobs:
prepare-version:
runs-on: ubuntu-24.04
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.ACTIONS_APP_ID }}
private-key: ${{ secrets.ACTIONS_APP_PRIVATE_KEY }}
- name: Validate what's new
run: |
# We just check if handle this input using jq will not fail.
# If it does, the workflow will fail in a inconsistent way.
echo '${{ inputs.what-is-new }}' | jq -r '.[]'
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Install buildchain dependencies
run: |
python3 -m pip install -r buildchain/requirements.txt
- name: Install semver tool
run: |
curl --fail -LO https://raw.githubusercontent.com/fsaintjacques/semver-tool/3.4.0/src/semver
chmod +x ./semver
- name: Compose release tag
run: |
source VERSION
SHORT_VERSION="$VERSION_MAJOR.$VERSION_MINOR"
BASE_VERSION="$SHORT_VERSION.$VERSION_PATCH"
TAG="$BASE_VERSION"
if [ "${{ inputs.version-type }}" == "alpha" ] || [ "${{ inputs.version-type }}" == "beta" ] ; then
TAG="$TAG-${{ inputs.version-type }}"
TAG_QUERY="$TAG*"
elif [ "${{ inputs.version-type }}" == "GA" ]; then
TAG_QUERY="$TAG"
else
echo "Invalid release type: ${{ inputs.version-type }}"
exit 1
fi
LAST_MATCH_TAG=$(git tag -l --sort=-v:refname "$TAG_QUERY" | head -n 1)
if [ "${{ inputs.version-type }}" == "GA" ] && [ "$LAST_MATCH_TAG" != "" ]; then
echo "Release $LAST_MATCH_TAG already exists"
exit 1
fi
if [ "${{ inputs.version-type }}" == "alpha" ] || [ "${{ inputs.version-type }}" == "beta" ] ; then
SUFFIX_NUMBER="1"
if [ "$LAST_MATCH_TAG" != "" ]; then
SUFFIX_NUMBER=$(./semver get prerel $LAST_MATCH_TAG | cut -d'.' -f2)
SUFFIX_NUMBER=$((SUFFIX_NUMBER + 1))
fi
TAG="$TAG.$SUFFIX_NUMBER"
fi
echo "SHORT_VERSION=$SHORT_VERSION" >> $GITHUB_ENV
echo "PATCH_VERSION=$VERSION_PATCH" >> $GITHUB_ENV
echo "BASE_VERSION=$BASE_VERSION" >> $GITHUB_ENV
echo "RELEASE_TAG=$TAG" >> $GITHUB_ENV
echo "RELEASE_BRANCH=release/$TAG" >> $GITHUB_ENV
- name: Validate ${{ env.RELEASE_TAG }} tag
run: ./semver validate ${{ env.RELEASE_TAG }}
- name: Check if version ${{ env.BASE_VERSION }} is on the right branch
run: |
GIT_REMOTE=$(git remote)
BASE_BRANCH=$(git branch -a --list ${GIT_REMOTE}/development/${{ env.SHORT_VERSION }})
if ! git merge-base --is-ancestor HEAD ${BASE_BRANCH}; then
echo "Version commit is not included in base branch ${BASE_BRANCH}"
exit 1
fi
- name: Prepare branch
run: git checkout -b ${{ env.RELEASE_BRANCH }}
- name: Set the new version
run: |
if [ "${{ inputs.version-type }}" == "GA" ]; then
sed -i "s/## Release ${{ env.BASE_VERSION }} (in development)/## Release ${{ env.BASE_VERSION }}/" CHANGELOG.md
git add CHANGELOG.md
fi
if [ -z "${NEW_VERSION_SUFFIX}" ]; then
NEW_VERSION_SUFFIX=$(./semver get prerel ${{ env.RELEASE_TAG }})
[ -n "$NEW_VERSION_SUFFIX" ] && NEW_VERSION_SUFFIX="-$NEW_VERSION_SUFFIX"
fi
sed -i "s/VERSION_SUFFIX=.*/VERSION_SUFFIX=$NEW_VERSION_SUFFIX/" VERSION
git add VERSION
- name: Commit with requested version and push
run: |
git fsck
git gc
git config --global user.email ${{ github.actor }}@scality.com
git config --global user.name ${{ github.actor }}
git commit -m "Release ${{ env.RELEASE_TAG }}"
git push --set-upstream origin ${{ env.RELEASE_BRANCH }}
- name: Create and push `${{ env.RELEASE_TAG }}` tag
run: |
BODY=$(mktemp)
K8S_VERSION=$(python3 -c 'from buildchain.buildchain import versions; print(versions.K8S_VERSION)')
PATCH_MSG="MetalK8s ${{ env.RELEASE_TAG }} embeds Kubernetes $K8S_VERSION."
if [ "${{ env.PATCH_VERSION }}" != "0" ]; then
PATCH_MSG="MetalK8s ${{ env.RELEASE_TAG }} is a patch release (see [the main release ${{ env.SHORT_VERSION }}.0](https://github.com/scality/metalk8s/releases/${{ env.SHORT_VERSION }}.0))."
fi
cat > $BODY <<- EOM
MetalK8s ${{ env.RELEASE_TAG }}
===
$PATCH_MSG
Useful links
---
- [Documentation](https://metal-k8s.readthedocs.io/en/${{ env.RELEASE_TAG }})
- [Upgrade notes](https://metal-k8s.readthedocs.io/en/${{ env.RELEASE_TAG }}/operation/upgrade.html)
- [Changelog](https://github.com/scality/metalk8s/blob/${{ env.RELEASE_TAG }}/CHANGELOG.md)
EOM
if [ '${{ inputs.what-is-new }}' != '[]' ]; then
echo "What's new" >> $BODY
echo "===" >> $BODY
echo "" >> $BODY
while IFS= read -r line; do
echo "- $line" >> $BODY
done <<< $(echo '${{ inputs.what-is-new }}' | jq -r '.[]')
fi
git tag -a "${{ env.RELEASE_TAG }}" -F $BODY
git push origin ${{ env.RELEASE_TAG }}
- name: Prepare branch to merge ${{ env.RELEASE_TAG }} tag
run: |
git checkout -b release/merge-${{ env.RELEASE_TAG }}-tag origin/development/${{ env.SHORT_VERSION }}
git merge ${{ env.RELEASE_TAG }} --no-ff
VERSION_PATCH=${{ env.PATCH_VERSION }}
if [ "${{ inputs.version-type }}" == "GA" ]; then
VERSION_PATCH=$((VERSION_PATCH + 1))
sed -i "s/## Release ${{ env.BASE_VERSION }}/## Release ${{ env.SHORT_VERSION }}.$VERSION_PATCH (in development)\n\n## Release ${{ env.BASE_VERSION }}/" CHANGELOG.md
git add CHANGELOG.md
sed -i "s/VERSION_PATCH=.*/VERSION_PATCH=$VERSION_PATCH/" VERSION
fi
sed -i "s/VERSION_SUFFIX=.*/VERSION_SUFFIX=-dev/" VERSION
git add VERSION
git commit --amend --no-edit
git push --set-upstream origin release/merge-${{ env.RELEASE_TAG }}-tag
- name: Create pull request
uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: "release/merge-${{ env.RELEASE_TAG }}-tag",
base: "development/${{ env.SHORT_VERSION }}",
title: "Merge release tag for ${{ env.RELEASE_TAG }}"
});
await github.rest.issues.createComment({
issue_number: pr.data.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '/approve'
})