-
Notifications
You must be signed in to change notification settings - Fork 913
195 lines (166 loc) · 6.63 KB
/
govmomi-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
# Copyright (c) 2021 VMware, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Release
on:
workflow_dispatch:
inputs:
tag:
description: 'Create release using this non-existing semantic tag for the specified ref'
required: true
type: string
default: 'v0.99.0'
dryrun:
description: 'Dry Run (verify workflow without pushing a release)'
type: boolean
required: false
default: true
jobs:
release:
name: Create Release
runs-on: ubuntu-20.04
timeout-minutes: 60
outputs:
latesttag: ${{ steps.tag.outputs.islatest }}
steps:
- name: Docker Login
run: docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # for CHANGELOG
ref: ${{ github.ref }} # branch provided on dispatch
- name: Validate branch and tag
run: |
# do not allow release on main branch
if [[ ${{ github.ref }} == refs/heads/main ]]; then
echo "::error:: release must be done on a release branch"
exit 1
fi
# check it starts with "v"
if [[ ${{ inputs.tag }} != v* ]]; then
echo "::error:: tag must have a \"v\" prefix"
exit 1
fi
# check it does not exist
if [[ $(git tag -l ${{ inputs.tag }} ) ]]; then
echo "::error:: tag already exists"
exit 1
fi
# set tag environment variable
echo "TAG=${{ inputs.tag }}" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Update version.go
run: |
# strip semantic v
export GOVMOMI_VERSION=${TAG#"v"}
sed -i "s/ClientVersion =.*/ClientVersion = \"$GOVMOMI_VERSION\"/" internal/version/version.go
git --no-pager diff internal/version/version.go
# configure author
# https://github.community/t/github-actions-bot-email-address/17204/6
git config --local user.email 41898282+github-actions[bot]@users.noreply.github.com
git config --local user.name "GitHub Action"
# commit changes
git add internal/version/version.go
git commit -s -m "chore: Update version.go for ${TAG}"
- name: Create tag
id: tag
run: |
# create new tag
git tag -a ${TAG} -m "Release ${TAG}"
# find latest tag sorted by semver ref
LATEST=$(git tag --sort=v:refname | tail -1)
# check whether the new tag is also the latest
if [[ $LATEST == $TAG ]]; then
echo "islatest=true >> $GITHUB_OUTPUT"
else
echo "islatest=false >> $GITHUB_OUTPUT"
fi
- name: Push changes and tag to release branch
if: ${{ !inputs.dryrun }}
run: |
git push --atomic --follow-tags origin ${{ github.ref }}
- name: Create RELEASE CHANGELOG
env:
IMAGE: quay.io/git-chglog/git-chglog
# https://quay.io/repository/git-chglog/git-chglog from tag v0.14.2
IMAGE_SHA: 998e89dab8dd8284cfff5f8cfb9e9af41fe3fcd4671f2e86a180e453c20959e3
run: |
# generate CHANGELOG for this Github release tag only
docker run --rm -v $PWD:/workdir ${IMAGE}@sha256:${IMAGE_SHA} -o RELEASE_CHANGELOG.md --sort semver --tag-filter-pattern '^v[0-9]+' ${TAG}
- name: Archive CHANGELOG
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: CHANGELOG
path: |
./RELEASE_CHANGELOG.md
retention-days: 14
- name: Simulate Release without pushing Artifacts
if: ${{ inputs.dryrun }}
uses: goreleaser/goreleaser-action@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: latest
args: release --snapshot --clean --release-notes RELEASE_CHANGELOG.md
- name: Create Release and build/push Artifacts
if: ${{ !inputs.dryrun }}
uses: goreleaser/goreleaser-action@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: latest
args: release --clean --release-notes RELEASE_CHANGELOG.md # will push artefacts and container images
pull-request:
needs: release
name: Create CHANGELOG.md PR
runs-on: ubuntu-20.04
continue-on-error: true
# only update CHANGELOG for latest semver tag
if: ${{ !inputs.dryrun && needs.release.outputs.latesttag == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# for changelog
fetch-depth: 0
ref: "main"
- name: Create CHANGELOG.md commit
env:
IMAGE: quay.io/git-chglog/git-chglog
# https://quay.io/repository/git-chglog/git-chglog from tag v0.14.2
IMAGE_SHA: 998e89dab8dd8284cfff5f8cfb9e9af41fe3fcd4671f2e86a180e453c20959e3
run: |
# update CHANGELOG
docker run --rm -v $PWD:/workdir ${IMAGE}@sha256:${IMAGE_SHA} -o CHANGELOG.md --sort semver --tag-filter-pattern '^v[0-9]+' -t .chglog/CHANGELOG.tpl.md
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v7
with:
commit-message: "Update CHANGELOG for ${{ inputs.tag }}"
delete-branch: true
title: "Update CHANGELOG for ${{ inputs.tag }}"
signoff: true
draft: false
body: |
### Update CHANGELOG.md for new release.
> **Note**
> Due to a [limitation](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#triggering-further-workflow-runs) in Github Actions please **close and immediately reopen** this PR to trigger the required workflow checks before merging.
- name: Pull Request Information
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"