Skip to content

Commit 870056e

Browse files
committed
Create GitHub action to automate CodeFlare operator release
1 parent 360e01f commit 870056e

File tree

3 files changed

+103
-38
lines changed

3 files changed

+103
-38
lines changed

.github/workflows/tag-and-build.yml

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,48 @@ on:
77
version:
88
description: 'Tag to be used for operator image'
99
required: true
10-
default: '0.0.0-dev'
10+
default: 'v0.0.0-dev'
1111
replaces:
1212
description: 'The previous semantic version that this tag replaces.'
1313
required: true
14-
default: '0.0.0-dev'
14+
default: 'v0.0.0-dev'
15+
mcad-version:
16+
description: 'Published version of multi-cluster-app-dispatcher'
17+
required: true
18+
default: 'v0.0.0-dev'
19+
codeflare-sdk-version:
20+
description: 'Published version of CodeFlare-SDK'
21+
required: true
22+
default: 'v0.0.0-dev'
23+
instascale-version:
24+
description: 'Published version of InstaScale'
25+
required: true
26+
default: 'v0.0.0-dev'
27+
is-latest:
28+
description: 'Select if the built image should be tagged as latest'
29+
required: true
30+
type: boolean
31+
quay-organization:
32+
description: 'Quay organization used to push the built images to'
33+
required: true
34+
default: 'project-codeflare'
35+
community-operators-prod-fork-organization:
36+
description: 'Owner of forked community-operators-prod repository used to push bundle files to'
37+
required: true
38+
default: 'project-codeflare'
39+
community-operators-prod-organization:
40+
description: 'Owner of target community-operators-prod repository used to open a PR against'
41+
required: true
42+
default: 'redhat-openshift-ecosystem'
1543

1644
jobs:
1745
push:
1846
runs-on: ubuntu-latest
47+
48+
# Permission required to create a release
49+
permissions:
50+
contents: write
51+
1952
steps:
2053
- uses: actions/checkout@v3
2154

@@ -25,17 +58,6 @@ jobs:
2558
path: /cache
2659
key: ${{ runner.os }}-cache-${{ hashFiles('**/go.sum', '.pre-commit-config.yaml') }}
2760

28-
- name: Create tag
29-
uses: actions/github-script@v6
30-
with:
31-
script: |
32-
github.rest.git.createRef({
33-
owner: context.repo.owner,
34-
repo: context.repo.repo,
35-
ref: 'refs/tags/${{ github.event.inputs.version }}',
36-
sha: context.sha
37-
})
38-
3961
- name: Install operator-sdk
4062
run: make install-operator-sdk
4163

@@ -46,18 +68,54 @@ jobs:
4668
password: ${{ secrets.QUAY_TOKEN }}
4769
registry: quay.io
4870

49-
- name: Image Build
71+
- name: Image Build and Push
5072
run: |
5173
make build
52-
make bundle
53-
make image-build -e IMG=quay.io/project-codeflare/codeflare-operator:${SOURCE_TAG}
54-
podman tag quay.io/project-codeflare/codeflare-operator:${SOURCE_TAG} quay.io/project-codeflare/codeflare-operator:latest
74+
make image-build -e IMG=quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:${{ github.event.inputs.version }}
75+
make image-push -e IMG=quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:${{ github.event.inputs.version }}
76+
77+
- name: Image Push as latest tag
78+
if: ${{ inputs.is-latest }}
79+
run: |
80+
podman tag quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:${{ github.event.inputs.version }} quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:latest
81+
make image-push -e IMG=quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:latest
82+
83+
- name: Build bundle and create PR in OpenShift community operators repository
84+
run: |
85+
git config --global user.email "codeflare-ci@redhat.com"
86+
git config --global user.name "CodeFlare CI"
87+
make openshift-community-operator-release
5588
env:
56-
SOURCE_TAG: ${{ github.event.inputs.version }}
89+
VERSION: ${{ github.event.inputs.version }}
90+
PREVIOUS_VERSION: ${{ github.event.inputs.replaces }}
91+
INSTASCALE_VERSION: ${{ github.event.inputs.instascale-version }}
92+
GH_TOKEN: ${{ secrets.GH_PAT }}
93+
OPERATORS_REPO_FORK_ORG: ${{ github.event.inputs.community-operators-prod-fork-organization }}
94+
OPERATORS_REPO_ORG: ${{ github.event.inputs.community-operators-prod-organization }}
95+
96+
- name: Adjust Compatibility Matrix in readme
97+
run: |
98+
sed -i -E "s/(.*CodeFlare Operator.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.version }}\2/" README.md
99+
sed -i -E "s/(.*Multi-Cluster App Dispatcher.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.mcad-version }}\2/" README.md
100+
sed -i -E "s/(.*CodeFlare-SDK.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.codeflare-sdk-version }}\2/" README.md
101+
sed -i -E "s/(.*InstaScale.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.instascale-version }}\2/" README.md
102+
103+
- name: Adjust MCAD and InstaScale dependencies in the code
104+
run: |
105+
sed -i -E "s/(.*ref=).*/\1release-${{ github.event.inputs.mcad-version }}/" config/crd/mcad/kustomization.yaml
106+
sed -i -E "s|(.*quay.io/project-codeflare/mcad-controller:release-)v[0-9]+\.[0-9]+\.[0-9]+(.*)|\1${{ github.event.inputs.mcad-version }}\2|" config/internal/mcad/deployment.yaml.tmpl
107+
sed -i -E "s/(.*instascale-controller:)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.instascale-version }}\2/" controllers/testdata/instascale_test_results/case_1/deployment.yaml
108+
sed -i -E "s/(.*instascale-controller:)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.instascale-version }}\2/" controllers/testdata/instascale_test_results/case_2/deployment.yaml
109+
110+
- name: Commit readme changes back to repository
111+
uses: stefanzweifel/git-auto-commit-action@v4
112+
with:
113+
commit_message: Update dependency versions for release ${{ github.event.inputs.version }}
114+
file_pattern: 'README.md controllers/defaults.go *.yaml *.tmpl'
57115

58-
- name: Image Push
116+
- name: Creates a release in GitHub
59117
run: |
60-
make image-push -e IMG=quay.io/project-codeflare/codeflare-operator:${SOURCE_TAG}
61-
make image-push -e IMG=quay.io/project-codeflare/codeflare-operator:latest
118+
gh release create ${{ github.event.inputs.version }} --generate-notes
62119
env:
63-
SOURCE_TAG: ${{ github.event.inputs.version }}
120+
GITHUB_TOKEN: ${{ github.TOKEN }}
121+
shell: bash

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ For building and pushing a new version of the bundled operator image:
4444
- `make bundle-push -e IMAGE_TAG_BASE=<image-repo/image-name> VERSION=<new semver> PREVIOUS_VERSION=<semver to replace>`
4545

4646
To create a new openshift-community-operator-release:
47-
- `make openshift-community-operator-release -e IMAGE_TAG_BASE=<image-repo/image-name> VERSION=<new semver> PREVIOUS_VERSION=<semver to replace>`
47+
- `make openshift-community-operator-release -e IMAGE_TAG_BASE=<image-repo/image-name> VERSION=<new semver> PREVIOUS_VERSION=<semver to replace> GH_TOKEN=<GitHub token for pushing bundle content to forked repository>`
4848

4949
## Testing
5050
The CodeFlare Operator currently has unit tests and pre-commit checks

Makefile

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
# VERSION defines the project version for the bundle.
22
# Update this value when you upgrade the version of your project.
33
# To re-generate a bundle for another specific version without changing the standard setup, you can:
4-
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
5-
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
4+
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=v0.0.2)
5+
# - use environment variables to overwrite this value (e.g export VERSION=v0.0.2)
66
# best if we could detect this. If we cannot, we need to document it somewhere.
77
# then we can add a patch in the `PHONY: bundle`
8+
# BUNDLE_VERSION is declared as bundle versioning doesn't use semver
89

9-
PREVIOUS_VERSION ?= 0.0.0-dev
10-
VERSION ?= 0.0.0-dev
10+
PREVIOUS_VERSION ?= v0.0.0-dev
11+
VERSION ?= v0.0.0-dev
12+
BUNDLE_VERSION ?= $(VERSION:v%=%)
1113

1214
# INSTASCALE_VERSION defines the default version of the InstaScale controller
1315
INSTASCALE_VERSION ?= v0.0.4
1416

17+
# OPERATORS_REPO_ORG points to GitHub repository organization where bundle PR is opened against
18+
# OPERATORS_REPO_FORK_ORG points to GitHub repository fork organization where bundle build is pushed to
19+
OPERATORS_REPO_ORG ?= redhat-openshift-ecosystem
20+
OPERATORS_REPO_FORK_ORG ?= project-codeflare
21+
1522
# CHANNELS define the bundle channels used in the bundle.
1623
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
1724
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
@@ -46,10 +53,10 @@ INSTASCALE_IMAGE ?= $(IMAGE_ORG_BASE)/instascale-controller:$(INSTASCALE_VERSION
4653

4754
# BUNDLE_IMG defines the image:tag used for the bundle.
4855
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
49-
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
56+
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:$(VERSION)
5057

5158
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
52-
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
59+
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(BUNDLE_VERSION) $(BUNDLE_METADATA_OPTS)
5360

5461
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
5562
# You can enable this value if you would like to use SHA Based Digests
@@ -60,7 +67,7 @@ ifeq ($(USE_IMAGE_DIGESTS), true)
6067
endif
6168

6269
# Image URL to use all building/pushing image targets
63-
IMG ?= ${IMAGE_TAG_BASE}:v${VERSION}
70+
IMG ?= ${IMAGE_TAG_BASE}:${VERSION}
6471
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
6572
ENVTEST_K8S_VERSION = 1.24.2
6673

@@ -239,7 +246,7 @@ bundle: defaults manifests kustomize install-operator-sdk ## Generate bundle man
239246
$(OPERATOR_SDK) generate kustomize manifests -q
240247
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
241248
cd config/manifests && $(KUSTOMIZE) edit add patch --patch '[{"op":"add", "path":"/metadata/annotations/containerImage", "value": "$(IMG)" }]' --kind ClusterServiceVersion
242-
cd config/manifests && $(KUSTOMIZE) edit add patch --patch '[{"op":"add", "path":"/spec/replaces", "value": "codeflare-operator.v$(PREVIOUS_VERSION)" }]' --kind ClusterServiceVersion
249+
cd config/manifests && $(KUSTOMIZE) edit add patch --patch '[{"op":"add", "path":"/spec/replaces", "value": "codeflare-operator.$(PREVIOUS_VERSION)" }]' --kind ClusterServiceVersion
243250
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
244251
$(MAKE) validate-bundle
245252
git restore config/*
@@ -252,13 +259,13 @@ bundle-build: bundle ## Build the bundle image.
252259
bundle-push: ## Push the bundle image.
253260
$(MAKE) image-push IMG=$(BUNDLE_IMG)
254261

255-
.PHONY: openshift-community-operator-releases
262+
.PHONY: openshift-community-operator-release
256263
openshift-community-operator-release: install-gh-cli bundle ## build bundle and create PR in OpenShift community operators repository
257-
gh repo clone git@github.com:project-codeflare/community-operators-prod.git
258-
cd community-operators-prod && git pull upstream main && git push origin main
259-
cp -r bundle community-operators-prod/operators/codeflare-operator/$(VERSION)
260-
cd community-operators-prod && git checkout -b codeflare-release-$(VERSION) && git add operators/codeflare-operator/$(VERSION)/* && git commit -s -m "add bundle manifests codeflare version $(VERSION)" && git push origin codeflare-release-$(VERSION)
261-
gh pr create --repo redhat-openshift-ecosystem/community-operators-prod --title "CodeFlare $(VERSION)" --body "New release of codeflare operator" --head project-codeflare:codeflare-release-$(VERSION) --base main
264+
git clone https://$(GH_TOKEN)@github.com/$(OPERATORS_REPO_FORK_ORG)/community-operators-prod.git
265+
cd community-operators-prod && git remote add upstream https://github.com/$(OPERATORS_REPO_ORG)/community-operators-prod.git && git pull upstream main && git push origin main
266+
cp -r bundle community-operators-prod/operators/codeflare-operator/$(BUNDLE_VERSION)
267+
cd community-operators-prod && git checkout -b codeflare-release-$(BUNDLE_VERSION) && git add operators/codeflare-operator/$(BUNDLE_VERSION)/* && git commit -m "add bundle manifests codeflare version $(BUNDLE_VERSION)" && git push origin codeflare-release-$(BUNDLE_VERSION)
268+
gh pr create --repo $(OPERATORS_REPO_FORK_ORG)/community-operators-prod --title "CodeFlare $(BUNDLE_VERSION)" --body "New release of codeflare operator" --head $(OPERATORS_REPO_ORG):codeflare-release-$(BUNDLE_VERSION) --base main
262269
rm -rf community-operators-prod
263270

264271
.PHONY: opm
@@ -283,7 +290,7 @@ endif
283290
BUNDLE_IMGS ?= $(BUNDLE_IMG)
284291

285292
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
286-
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
293+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:$(VERSION)
287294

288295
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
289296
ifneq ($(origin CATALOG_BASE_IMG), undefined)

0 commit comments

Comments
 (0)