Skip to content

Commit 8a340cb

Browse files
committed
Create GitHub action to automate CodeFlare operator release
1 parent 73db60f commit 8a340cb

File tree

3 files changed

+104
-38
lines changed

3 files changed

+104
-38
lines changed

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

Lines changed: 81 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,55 @@ 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 "[email protected]"
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+
MCAD_VERSION: ${{ github.event.inputs.mcad-version }}
93+
GH_TOKEN: ${{ secrets.GH_PAT }}
94+
OPERATORS_REPO_FORK_ORG: ${{ github.event.inputs.community-operators-prod-fork-organization }}
95+
OPERATORS_REPO_ORG: ${{ github.event.inputs.community-operators-prod-organization }}
96+
97+
- name: Adjust Compatibility Matrix in readme
98+
run: |
99+
sed -i -E "s/(.*CodeFlare Operator.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.version }}\2/" README.md
100+
sed -i -E "s/(.*Multi-Cluster App Dispatcher.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.mcad-version }}\2/" README.md
101+
sed -i -E "s/(.*CodeFlare-SDK.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.codeflare-sdk-version }}\2/" README.md
102+
sed -i -E "s/(.*InstaScale.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.instascale-version }}\2/" README.md
103+
104+
- name: Adjust MCAD and InstaScale dependencies in the code
105+
run: |
106+
sed -i -E "s/(.*ref=).*/\1release-${{ github.event.inputs.mcad-version }}/" config/crd/mcad/kustomization.yaml
107+
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
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_1/deployment.yaml
109+
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
110+
111+
- name: Commit readme changes back to repository
112+
uses: stefanzweifel/git-auto-commit-action@v4
113+
with:
114+
commit_message: Update dependency versions for release ${{ github.event.inputs.version }}
115+
file_pattern: 'README.md controllers/defaults.go *.yaml *.tmpl'
57116

58-
- name: Image Push
117+
- name: Creates a release in GitHub
59118
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
119+
gh release create ${{ github.event.inputs.version }} --generate-notes
62120
env:
63-
SOURCE_TAG: ${{ github.event.inputs.version }}
121+
GITHUB_TOKEN: ${{ github.TOKEN }}
122+
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,13 +1,15 @@
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
@@ -19,6 +21,11 @@ MCAD_REF ?= release-${MCAD_VERSION}
1921
MCAD_REPO ?= github.com/project-codeflare/multi-cluster-app-dispatcher
2022
MCAD_CRD ?= ${MCAD_REPO}/config/crd?ref=${MCAD_REF}
2123

24+
# OPERATORS_REPO_ORG points to GitHub repository organization where bundle PR is opened against
25+
# OPERATORS_REPO_FORK_ORG points to GitHub repository fork organization where bundle build is pushed to
26+
OPERATORS_REPO_ORG ?= redhat-openshift-ecosystem
27+
OPERATORS_REPO_FORK_ORG ?= project-codeflare
28+
2229
# CHANNELS define the bundle channels used in the bundle.
2330
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
2431
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
@@ -53,10 +60,10 @@ INSTASCALE_IMAGE ?= $(IMAGE_ORG_BASE)/instascale-controller:$(INSTASCALE_VERSION
5360

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

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

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

6976
# Image URL to use all building/pushing image targets
70-
IMG ?= ${IMAGE_TAG_BASE}:v${VERSION}
77+
IMG ?= ${IMAGE_TAG_BASE}:${VERSION}
7178
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
7279
ENVTEST_K8S_VERSION = 1.24.2
7380

@@ -308,7 +315,7 @@ bundle: defaults manifests kustomize install-operator-sdk ## Generate bundle man
308315
$(KUSTOMIZE) fn run config/crd/mcad --image gcr.io/kpt-fn/apply-setters:v0.2.0 -- MCAD_CRD=$(MCAD_CRD)
309316
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
310317
cd config/manifests && $(KUSTOMIZE) edit add patch --patch '[{"op":"add", "path":"/metadata/annotations/containerImage", "value": "$(IMG)" }]' --kind ClusterServiceVersion
311-
cd config/manifests && $(KUSTOMIZE) edit add patch --patch '[{"op":"add", "path":"/spec/replaces", "value": "codeflare-operator.v$(PREVIOUS_VERSION)" }]' --kind ClusterServiceVersion
318+
cd config/manifests && $(KUSTOMIZE) edit add patch --patch '[{"op":"add", "path":"/spec/replaces", "value": "codeflare-operator.$(PREVIOUS_VERSION)" }]' --kind ClusterServiceVersion
312319
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
313320
$(MAKE) validate-bundle
314321
git restore config/*
@@ -321,13 +328,13 @@ bundle-build: bundle ## Build the bundle image.
321328
bundle-push: ## Push the bundle image.
322329
$(MAKE) image-push IMG=$(BUNDLE_IMG)
323330

324-
.PHONY: openshift-community-operator-releases
331+
.PHONY: openshift-community-operator-release
325332
openshift-community-operator-release: install-gh-cli bundle ## build bundle and create PR in OpenShift community operators repository
326-
gh repo clone git@github.com:project-codeflare/community-operators-prod.git
327-
cd community-operators-prod && git pull upstream main && git push origin main
328-
cp -r bundle community-operators-prod/operators/codeflare-operator/$(VERSION)
329-
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)
330-
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
333+
git clone https://$(GH_TOKEN)@github.com/$(OPERATORS_REPO_FORK_ORG)/community-operators-prod.git
334+
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
335+
cp -r bundle community-operators-prod/operators/codeflare-operator/$(BUNDLE_VERSION)
336+
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)
337+
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
331338
rm -rf community-operators-prod
332339

333340
.PHONY: opm
@@ -352,7 +359,7 @@ endif
352359
BUNDLE_IMGS ?= $(BUNDLE_IMG)
353360

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

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

0 commit comments

Comments
 (0)