forked from open-component-model/ocm
-
Notifications
You must be signed in to change notification settings - Fork 0
275 lines (248 loc) · 8.62 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
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
name: Release
on:
workflow_dispatch:
inputs:
release_candidate:
type: boolean
description: "Release Candidate"
required: false
default: false
create_branch:
type: boolean
description: "Create Release Branch"
required: false
default: false
prerelease:
type: string
description: "Release Candidate Name"
required: false
default: ""
jobs:
check:
name: Check Release Preconditions
runs-on: large_runner
permissions:
contents: write
id-token: write
repository-projects: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Job Settings
run: |
echo "Release Job Arguments"
if ${{ github.event.inputs.release_candidate }}; then
v="v$(go run $GITHUB_WORKSPACE/pkg/version/generate --no-dev print-rc-version ${{ github.event.inputs.prerelease }})"
if [ -n "${{ github.event.inputs.prerelease }}" ]; then
echo "Candidate: $v"
else
echo "Candidate: $v (taken from source)"
fi
else
v="v$(go run $GITHUB_WORKSPACE/pkg/version/generate print-version)"
echo "Final Release: $v"
if ${{ github.event.inputs.create_branch }}; then
echo "with release branch creation"
else
echo "without release branch creation"
fi
fi
- name: Set Base Version
run: |
BASE_VERSION=v$(go run $GITHUB_WORKSPACE/pkg/version/generate print-version)
echo "BASE_VERSION=$BASE_VERSION" >> $GITHUB_ENV
- name: Set Pre-Release Version
if: inputs.release_candidate == true
run: |
RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/pkg/version/generate --no-dev print-rc-version ${{ github.event.inputs.prerelease }})
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
- name: Set Version
if: inputs.release_candidate == false
run: |
RELEASE_VERSION=${{env.BASE_VERSION}}
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
- name: Check Tag
run: |
set -e
if git ls-remote --exit-code origin refs/tags/${{ env.RELEASE_VERSION }} ; then
>&2 echo "tag ${{ env.RELEASE_VERSION }} already exists"
exit 1
fi
- name: Check Branch
if: inputs.release_candidate == false && inputs.create_branch
run: |
set -e
if git ls-remote --exit-code origin refs/heads/releases/${{ env.RELEASE_VERSION }} ; then
>&2 echo "branch releases/${{ env.RELEASE_VERSION }} already exists"
exit 1
fi
- name: Get Draft Release Notes
id: release-notes
uses: cardinalby/git-get-release-action@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
draft: true
releaseName: ${{ env.BASE_VERSION }}
lint-and-test:
name: Lint and Unit Tests
uses: ./.github/workflows/lint_and_test.yaml
needs: check
permissions:
contents: read
pull-requests: read
components:
name: Component CTF Builds
uses: ./.github/workflows/components.yaml
needs: check
permissions:
contents: read
pull-requests: read
release:
needs:
- lint-and-test
- components
name: Release Build
runs-on: large_runner
permissions:
contents: write
id-token: write
packages: write
steps:
- name: Self Hosted Runner Post Job Cleanup Action
uses: TooMuch4U/[email protected]
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.OCMBOT_APP_ID }}
private_key: ${{ secrets.OCMBOT_PRIV_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.generate_token.outputs.token }}
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: '${{ github.workspace }}/go.mod'
- name: Setup Syft
uses: anchore/sbom-action/download-syft@e8d2a6937ecead383dfe75190d104edd1f9c5751 # v0.16.0
- name: Setup Cosign
uses: sigstore/[email protected]
- name: Setup git config
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<41898282+github-actions[bot]@users.noreply.github.com>"
- name: Cache go-build and mod
uses: actions/cache@v4
with:
path: |
~/.cache/go-build/
~/go/pkg/mod/
key: go-${{ hashFiles('go.sum') }}
restore-keys: |
go-
- name: Set Base Version
run: |
BASE_VERSION=v$(go run $GITHUB_WORKSPACE/pkg/version/generate print-version)
echo "BASE_VERSION=$BASE_VERSION" >> $GITHUB_ENV
- name: Set Pre-Release Version
if: inputs.release_candidate == true
run: |
RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/pkg/version/generate --no-dev print-rc-version ${{ github.event.inputs.prerelease }})
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
echo "release name is $RELEASE_VERSION"
- name: Set Version
if: inputs.release_candidate == false
run: |
RELEASE_VERSION=${{env.BASE_VERSION}}
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
echo "release name is $RELEASE_VERSION"
- name: Get Draft Release Notes
id: release-notes
uses: cardinalby/git-get-release-action@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
draft: true
releaseName: ${{ env.BASE_VERSION }}
- name: Update Release Notes File
env:
RELEASE_NOTES: ${{ steps.release-notes.outputs.body }}
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
if git ls-remote --exit-code origin refs/tags/${{ env.RELEASE_VERSION }}; then
>&2 echo "tag ${{ env.RELEASE_VERSION }} already exists"
exit 2
fi
v="${{env.RELEASE_VERSION}}"
f="docs/releasenotes/$v.md"
if [ ! -f "$f" ]; then
echo "Release ${{ env.RELEASE_VERSION }}" > "$f"
echo "$RELEASE_NOTES" | tail -n +2 >> "$f"
echo "RELEASE_NOTES_FILE=$f" >> $GITHUB_ENV
git add "$f"
git commit -m "ReleaseNotes for $RELEASE_VERSION"
git push origin ${GITHUB_REF#refs/heads/}
else
echo "Using release notes file $f from code base"
fi
- name: Create and Push Release
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
# git checkout --detach HEAD
echo -n "${RELEASE_VERSION#v}" > VERSION
git add VERSION
git commit -m "Release $RELEASE_VERSION"
msg="Release ${{ env.RELEASE_VERSION }}"
git tag --annotate --message "${msg}" ${{ env.RELEASE_VERSION }}
git push origin ${{ env.RELEASE_VERSION }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean --timeout 60m --skip-validate --config=./.goreleaser.yaml --release-notes=${{ env.RELEASE_NOTES_FILE }}
env:
GITHUBORG: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
GORELEASER_CURRENT_TAG: ${{ env.RELEASE_VERSION }}
- name: Push OCM Components
env:
GITHUBORG: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: make plain-push
- name: Create Release Branch
if: inputs.release_candidate == false && inputs.create_branch
run: |
n="releases/${{env.RELEASE_VERSION}}"
git checkout -b "$n"
v="$(go run ./pkg/version/generate bump-patch)"
echo "$v" > VERSION
git add VERSION
git commit -m "Prepare Development of v$v"
git push origin "$n"
- name: Bump Version File
if: inputs.release_candidate == false
run: |
set -e
git checkout ${GITHUB_REF#refs/heads/}
v="$(go run ./pkg/version/generate bump-version)"
echo "$v" > VERSION
git add VERSION
git commit -m "Update version file to $v"
git push origin ${GITHUB_REF#refs/heads/}
echo "Next branch version is $v"
- name: Publish Release Event
if: inputs.release_candidate == false
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ steps.generate_token.outputs.token }}
repository: open-component-model/ocm-website
event-type: ocm-cli-release
client-payload: '{"tag": "${{ env.RELEASE_VERSION }}"}'