-
Notifications
You must be signed in to change notification settings - Fork 39
241 lines (204 loc) · 7.28 KB
/
release.yml
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
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
permissions:
contents: write # publishing releases
env:
PROJECT_DIR: falcon-operator
IMAGE_NAME: falcon-operator
IMAGE_TAG: latest
IMAGE_REGISTRY: quay.io
IMAGE_NAMESPACE: crowdstrike
RELEASE_TAG: ${{ github.ref_name }}
jobs:
bump_release:
runs-on: ubuntu-latest
steps:
- name: Checkout full repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgpgme-dev libbtrfs-dev libdevmapper-dev
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Get Event branch
id: event_branch
run: |
BASEREF=${{ github.event.base_ref }}
REFBRANCH=${BASEREF#refs/heads/}
echo "REFBRANCH=${REFBRANCH}" >> $GITHUB_ENV
echo $REFBRANCH
- name: Checkout tagged branch
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ env.REFBRANCH }}
- name: Configure Git
id: config_git
run: |
git config user.name github-actions
git config user.email [email protected]
VERSION=${{ env.RELEASE_TAG }}
NEWVERSION=${VERSION:1}
echo "NEWVERSION=${NEWVERSION}" >> $GITHUB_ENV
- name: Generate Changelog
id: changelog
run: |
release=${{ env.NEWVERSION }}
cl=CHANGELOG.md
today=$(date +%F)
header=$(head -n7 ${cl})
older=$(tail -n+7 ${cl})
# get all commits on head since the latest tag
changes=$(git log --no-merges --pretty=format:"- %s" $(git describe --tags --abbrev=0 HEAD^)..HEAD)
echo "${header}" > ${cl}
echo "" >> ${cl}
echo "## [${release}] - ${today}" >> ${cl}
echo "" >> ${cl}
echo "### Changed" >> ${cl}
echo "" >> ${cl}
echo "${changes}" >> ${cl}
echo "${older}" >> ${cl}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Update release changes
id: git_commit
run: |
OLDVERSION=$(grep ^VERSION Makefile | awk '{print $NF}')
sed -i "s/$OLDVERSION/${{ env.NEWVERSION }}/g" -i Makefile
mkdir -p $HOME/go/bin
export PATH=$HOME/go/bin:$PATH
make operator-sdk
make manifests bundle non-olm IMG=${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.NEWVERSION }}
git add -u
git commit -m "Bumping to version ${{ env.NEWVERSION }}"
git push
git tag -f "${GITHUB_REF#refs/tags/}"
git push origin "${GITHUB_REF#refs/tags/}" --force
create_release:
runs-on: ubuntu-latest
needs: bump_release
steps:
- name: Checkout full repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Event branch
id: event_branch
run: |
BASEREF=${{ github.event.base_ref }}
REFBRANCH=${BASEREF#refs/heads/}
echo "REFBRANCH=${REFBRANCH}" >> $GITHUB_ENV
git checkout $REFBRANCH
- name: Getting latest release version and version setup
id: latest_version
run: |
if ! gh api repos/$GITHUB_REPOSITORY/releases/latest -q .tag_name > /dev/null 2>&1 ; then
LATESTREL="v0.0.0"
else
LATESTREL=$(gh api repos/$GITHUB_REPOSITORY/releases/latest -q .tag_name)
fi
echo "LATESTRELEASE=${LATESTREL}" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Generate Notes
id: notes
run: |
echo "tag-name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
gh api repos/$GITHUB_REPOSITORY/releases/generate-notes \
-f tag_name="${GITHUB_REF#refs/tags/}" \
-f target_commitish=${{ env.REFBRANCH }} \
-q .body > NOTES.md
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Create release
id: create_release
if: env.LATESTRELEASE != env.RELEASE_TAG
run: |
gh api repos/$GITHUB_REPOSITORY/releases \
-f tag_name="${GITHUB_REF#refs/tags/}" \
-f target_commitish=${{ env.REFBRANCH }} \
-f name="${GITHUB_REF#refs/tags/}" \
-F generate_release_notes=true
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Updating release
id: update_release
if: env.LATESTRELEASE == env.RELEASE_TAG
run: |
gh release edit "${GITHUB_REF#refs/tags/}" \
--title ${GITHUB_REF#refs/tags/} \
--tag ${GITHUB_REF#refs/tags/} \
--target ${{ env.REFBRANCH }} \
--notes-file NOTES.md
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Upload release assets
id: upload_manifest
run: |
gh release upload "${GITHUB_REF#refs/tags/}" deploy/falcon-operator.yaml
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
build-multiarch-operator:
name: Build multi-architecture image
needs: create_release
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go-version: [1.21.x]
steps:
- name: Install qemu dependency
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
id: go
# Checkout falcon-operator github repository
- name: Checkout falcon-operator project
uses: actions/checkout@v4
- name: Create proper tag version
id: set_version
run: |
VERSION=${{ env.RELEASE_TAG }}
IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
echo "VERSION=${VERSION:1}" >> $GITHUB_ENV
echo "IMAGE_REPOSITORY=${IMAGE_REPOSITORY}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ secrets.REGISTRY_LOGIN }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Setup Cross Compile Dockerfile
run: sed -e '1 s/\(^FROM\)/FROM --platform=$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- name: Build and push
id: build_image_multiarch
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.cross
platforms: linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
push: true
tags: |
${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ env.VERSION }}
build-args: |
VERSION=${{ env.VERSION }}
- name: Check manifest
run: |
docker buildx imagetools inspect ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ env.VERSION }}