-
Notifications
You must be signed in to change notification settings - Fork 0
239 lines (216 loc) · 8.61 KB
/
main.yml
File metadata and controls
239 lines (216 loc) · 8.61 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
233
234
235
236
237
238
239
# main.yml
name: Build and Release operator
run-name: ${{ github.actor }} triggerd ${{ github.event_name }} -> ${{ github.ref_name }} ${{ github.event.head_commit.message }}${{ github.event.pull_request.title }}
on:
push:
branches:
- dev
- feature/**
- hotfix/**
- fix/**
- issue/**
paths-ignore:
- README.md
- CHANGELOG.md # Should never be edited anyway
- .gitignore
- .github/**
pull_request_target:
branches:
- main
types:
- closed
workflow_dispatch:
env:
IMAGE_REGISTRY: ghcr.io
OPERATOR_SDK_VERSION: v1.29.0
jobs:
prepare:
if: ${{ github.event_name == 'push' || github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
outputs:
IMAGE_TAG_BASE: ${{ steps.SET_IMAGE_TAG_BASE.outputs.IMAGE_TAG_BASE }}
OPERATOR_VERSION: ${{ steps.SET_OPERATOR_VERSION.outputs.OPERATOR_VERSION }}
OPERATOR_VERSION_STRICT: ${{ steps.SET_OPERATOR_VERSION.outputs.OPERATOR_VERSION_STRICT }}
IS_RELEASE: ${{ steps.SET_OPERATOR_VERSION.outputs.IS_RELEASE }}
CURRENT: ${{ steps.semver.outputs.current }}
NEXT: ${{ steps.semver.outputs.next }}
NEXT_STRICT: ${{ steps.semver.outputs.nextStrict }}
#RUN_BUILDAH: ${{ steps.filter.outputs.buildah }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Export Repo Name lowercase
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- name: Set IMAGE_TAG_BASE
id: SET_IMAGE_TAG_BASE
run: echo "IMAGE_TAG_BASE=${{ env.IMAGE_REGISTRY }}/${{ env.REPO }}" >>${GITHUB_OUTPUT}
- name: Get Next Version
id: semver
continue-on-error: false
uses: ietf-tools/semver-action@v1.5.1
with:
token: ${{ github.token }}
patchAll: true
# fall back to dev because we want to have a valid semver
branch: ${{ fromJSON('{"main":"main"}')[github.ref_name] || github.ref_name }}
noVersionBumpBehavior: current
- name: Set OPERATOR_VERSION
id: SET_OPERATOR_VERSION
uses: actions/github-script@v6
env:
NEXT: ${{ steps.semver.outputs.next }}
NEXT_STRICT: ${{ steps.semver.outputs.nextStrict }}
CURRENT: ${{ steps.semver.outputs.current }}
with:
result-encoding: string
script: |
const {
GITHUB_REF_NAME,
GITHUB_HEAD_REF,
NEXT,
NEXT_STRICT,
} = process.env
let REPLACED_BRANCH_NAME = (GITHUB_REF_NAME || GITHUB_HEAD_REF).replace(/[^a-zA-Z0-9]/g, '-')
// use semver if branch name is not a valid semver
let OPERATOR_VERSION = NEXT + "-" + REPLACED_BRANCH_NAME
let OPERATOR_VERSION_STRICT = NEXT_STRICT + "-" + REPLACED_BRANCH_NAME
// if run is triggerd on main use the next tag
if (REPLACED_BRANCH_NAME == 'main') {
OPERATOR_VERSION = NEXT
OPERATOR_VERSION_STRICT = NEXT_STRICT
core.setOutput('IS_RELEASE', true)
}
core.setOutput('OPERATOR_VERSION', OPERATOR_VERSION)
core.setOutput('OPERATOR_VERSION_STRICT', OPERATOR_VERSION_STRICT)
# - name: check paths
# uses: dorny/paths-filter@v2
# id: filter
# with:
# filters: |
# buildah:
# - 'hack/Dockerfile.buildah.k8s.rootless'
# buildah:
# needs: prepare
# if: ${{ needs.prepare.outputs.RUN_BUILDAH == 'true' }}
# runs-on: ubuntu-latest
# services:
# docker:
# image: docker:dind
# env:
# IMAGE_TAG_BASE: ${{ needs.prepare.outputs.IMAGE_TAG_BASE }}
# OPERATOR_VERSION: ${{ needs.prepare.outputs.OPERATOR_VERSION }}
# steps:
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
# - name: Login to Docker Hub
# uses: docker/login-action@v2
# with:
# registry: ${{ env.IMAGE_REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - name: Build and push
# uses: docker/build-push-action@v4
# with:
# context: "{{defaultContext}}:hack"
# platforms: linux/amd64,linux/arm64
# file: "Dockerfile.buildah.k8s.rootless"
# push: true
# tags: ${{ env.IMAGE_TAG_BASE }}-buildah:${{ env.OPERATOR_VERSION }},${{ env.IMAGE_TAG_BASE }}-buildah:latest
operator:
needs: prepare
if: ${{ github.event_name == 'push' || github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
services:
docker:
image: docker:dind
env:
OPERATOR_VERSION: ${{ needs.prepare.outputs.OPERATOR_VERSION }}
OPERATOR_VERSION_STRICT: ${{ needs.prepare.outputs.OPERATOR_VERSION_STRICT }}
VERSION: ${{ needs.prepare.outputs.OPERATOR_VERSION_STRICT }}
IMAGE_TAG_BASE: ${{ needs.prepare.outputs.IMAGE_TAG_BASE }}
IMG: "${{ needs.prepare.outputs.IMAGE_TAG_BASE }}:${{ needs.prepare.outputs.OPERATOR_VERSION }}"
BUNDLE_IMG: "${{ needs.prepare.outputs.IMAGE_TAG_BASE }}-bundle:${{ needs.prepare.outputs.OPERATOR_VERSION }}"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Install the operator-sdk CLI
- name: Install operator-sdk
uses: ./.github/actions/install_operator_sdk
with:
OPERATOR_SDK_VERSION: ${{ env.OPERATOR_SDK_VERSION }}
# Build the bundle image
- name: Build bundle
shell: bash
env:
DOCKER_BUILDKIT: "1" # Enable Docker Buildkit
PLATFORMS: linux/amd64,linux/arm64
run: |
echo "Building bundle"
make docker-buildx
make bundle bundle-buildx
# deploy:
# needs: [prepare, operator]
# runs-on: ubuntu-latest
release:
needs: [prepare, operator]
runs-on: ubuntu-latest
env:
OPERATOR_VERSION: ${{ needs.prepare.outputs.OPERATOR_VERSION }}
OPERATOR_VERSION_STRICT: ${{ needs.prepare.outputs.OPERATOR_VERSION_STRICT }}
IMAGE_TAG_BASE: ${{ needs.prepare.outputs.IMAGE_TAG_BASE }}
IMG: "${{ needs.prepare.outputs.IMAGE_TAG_BASE }}:${{ needs.prepare.outputs.OPERATOR_VERSION }}"
BUNDLE_IMG: "${{ needs.prepare.outputs.IMAGE_TAG_BASE }}-bundle:${{ needs.prepare.outputs.OPERATOR_VERSION }}"
CURRENT: ${{ needs.prepare.outputs.CURRENT }}
NEXT: ${{ needs.prepare.outputs.NEXT }}
NEXT_STRICT: ${{ needs.prepare.outputs.NEXT_STRICT }}
if: github.ref_name == 'main' && needs.prepare.outputs.IS_RELEASE == 'true'
permissions:
contents: write
steps:
- name: Update CHANGELOG
id: changelog
uses: requarks/changelog-action@v1.8.1
with:
token: ${{ github.token }}
# calculate the changelog from the last tag to the current dev state
fromTag: ${{ fromJSON('{"main":"main"}')[github.ref_name] || github.ref_name }}
toTag: ${{ env.CURRENT }}
# Create a new release on GitHub with the semantic OPERATOR_VERSION number
- name: Create Release
uses: ncipollo/release-action@v1.12.0
with:
allowUpdates: true
draft: true
makeLatest: true
name: "Release: ${{ env.OPERATOR_VERSION }}"
body: |
# Install or upgrade new operator version
```shell
operator-sdk run bundle ${{ env.IMAGE_TAG_BASE }}-bundle:${{ env.OPERATOR_VERSION }}
operator-sdk run bundle-upgrade ${{ env.IMAGE_TAG_BASE }}-bundle:${{ env.OPERATOR_VERSION }}
```
# Pull new images
```shell
docker pull ${{ env.IMAGE_TAG_BASE }}-bundle:${{ env.OPERATOR_VERSION }}
docker pull ${{ env.IMAGE_TAG_BASE }}:${{ env.OPERATOR_VERSION }}
```
# Changelog
${{ steps.changelog.outputs.changes }}
token: ${{ github.token }}
commit: ${{ github.sha }}
tag: ${{ env.OPERATOR_VERSION }}
generateReleaseNotes: true
- name: Commit CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }} [skip ci]'
file_pattern: CHANGELOG.md