Skip to content

Commit 954e70c

Browse files
committed
Create GitHub action to automate CodeFlare operator release
1 parent 9a7746b commit 954e70c

File tree

4 files changed

+139
-54
lines changed

4 files changed

+139
-54
lines changed

Diff for: .github/workflows/tag-and-build.yml

+108-22
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,75 @@ 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-stable:
28+
description: 'Select if the built image should be tagged as stable'
29+
required: true
30+
type: boolean
31+
branch:
32+
description: 'Branch to be used for tag and release'
33+
required: true
34+
default: 'main'
35+
quay-organization:
36+
description: 'Quay organization used to push the built images to'
37+
required: true
38+
default: 'project-codeflare'
39+
community-operators-prod-fork-organization:
40+
description: 'Owner of forked community-operators-prod repository used to push bundle files to'
41+
required: true
42+
default: 'project-codeflare'
43+
community-operators-prod-organization:
44+
description: 'Owner of target community-operators-prod repository used to open a PR against'
45+
required: true
46+
default: 'redhat-openshift-ecosystem'
1547

1648
jobs:
1749
push:
1850
runs-on: ubuntu-latest
51+
52+
# Permission required to create a release
53+
permissions:
54+
contents: write
55+
1956
steps:
2057
- uses: actions/checkout@v3
58+
with:
59+
ref: "${{ github.event.inputs.branch }}"
60+
61+
- name: Verify that release doesn't exist yet
62+
shell: bash {0}
63+
run: |
64+
gh release view ${{ github.event.inputs.version }}
65+
status=$?
66+
if [[ $status -eq 0 ]]; then
67+
echo "Release ${{ github.event.inputs.version }} already exists."
68+
exit 1
69+
fi
70+
env:
71+
GITHUB_TOKEN: ${{ github.TOKEN }}
2172

2273
- name: Activate cache
2374
uses: actions/cache@v3
2475
with:
2576
path: /cache
2677
key: ${{ runner.os }}-cache-${{ hashFiles('**/go.sum', '.pre-commit-config.yaml') }}
2778

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-
3979
- name: Install operator-sdk
4080
run: make install-operator-sdk
4181

@@ -46,18 +86,64 @@ jobs:
4686
password: ${{ secrets.QUAY_TOKEN }}
4787
registry: quay.io
4888

49-
- name: Image Build
89+
- name: Image Build and Push
5090
run: |
5191
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
92+
make image-build -e IMG=quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:${{ github.event.inputs.version }}
93+
make image-push -e IMG=quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:${{ github.event.inputs.version }}
94+
95+
- name: Image Push as stable tag
96+
if: ${{ inputs.is-stable }}
97+
run: |
98+
podman tag quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:${{ github.event.inputs.version }} quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:stable
99+
make image-push -e IMG=quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:stable
100+
101+
- name: Build bundle and create PR in OpenShift community operators repository
102+
run: |
103+
git config --global user.email "[email protected]"
104+
git config --global user.name "CodeFlare CI"
105+
make openshift-community-operator-release
55106
env:
56-
SOURCE_TAG: ${{ github.event.inputs.version }}
107+
VERSION: ${{ github.event.inputs.version }}
108+
PREVIOUS_VERSION: ${{ github.event.inputs.replaces }}
109+
INSTASCALE_VERSION: ${{ github.event.inputs.instascale-version }}
110+
MCAD_VERSION: ${{ github.event.inputs.mcad-version }}
111+
GH_TOKEN: ${{ secrets.GH_PAT }}
112+
IMAGE_ORG_BASE: quay.io/${{ github.event.inputs.quay-organization }}
113+
OPERATORS_REPO_FORK_ORG: ${{ github.event.inputs.community-operators-prod-fork-organization }}
114+
OPERATORS_REPO_ORG: ${{ github.event.inputs.community-operators-prod-organization }}
115+
116+
- name: Adjust Compatibility Matrix in readme
117+
run: |
118+
sed -i -E "s/(.*CodeFlare Operator.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.version }}\2/" README.md
119+
sed -i -E "s/(.*Multi-Cluster App Dispatcher.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.mcad-version }}\2/" README.md
120+
sed -i -E "s/(.*CodeFlare-SDK.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.codeflare-sdk-version }}\2/" README.md
121+
sed -i -E "s/(.*InstaScale.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.instascale-version }}\2/" README.md
122+
123+
- name: Adjust MCAD and InstaScale dependencies in the code
124+
run: |
125+
sed -i -E "s/(.*MCAD_VERSION \?= )v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.mcad-version }}\2/" Makefile
126+
sed -i -E "s/(.*INSTASCALE_VERSION \?= )v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.instascale-version }}\2/" Makefile
127+
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
128+
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
129+
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
130+
131+
- name: Commit readme changes back to repository
132+
uses: stefanzweifel/git-auto-commit-action@v4
133+
with:
134+
commit_message: Update dependency versions for release ${{ github.event.inputs.version }}
135+
file_pattern: 'README.md controllers/defaults.go *.yaml *.tmpl Makefile'
136+
branch: "${{ github.event.inputs.branch }}"
57137

58-
- name: Image Push
138+
- name: Creates a release in GitHub
59139
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
140+
gh release create ${{ github.event.inputs.version }} --target ${{ github.event.inputs.branch }} --generate-notes
141+
# Edit notes to add there compatibility matrix
142+
sed --null-data -E "s/(.*<\!-- Compatibility Matrix start -->)(.*)(<\!-- Compatibility Matrix end -->.*)/\2/" README.md > release-notes.md
143+
echo "" >> release-notes.md
144+
echo "$(gh release view --json body --jq .body)" >> release-notes.md
145+
gh release edit ${{ github.event.inputs.version }} --notes-file release-notes.md
146+
rm release-notes.md
62147
env:
63-
SOURCE_TAG: ${{ github.event.inputs.version }}
148+
GITHUB_TOKEN: ${{ github.TOKEN }}
149+
shell: bash

Diff for: CONTRIBUTING.md

+1-1
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

Diff for: Makefile

+22-15
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)

Diff for: README.md

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# codeflare-operator
22
Operator for installation and lifecycle management of CodeFlare distributed workload stack, starting with MCAD and InstaScale
33

4+
<!-- Don't delete these comments, they are used to generate Compatibility Matrix table for release automation -->
5+
<!-- Compatibility Matrix start -->
46
CodeFlare Stack Compatibility Matrix
57

68
| Component | Version |
@@ -10,6 +12,7 @@ CodeFlare Stack Compatibility Matrix
1012
| CodeFlare-SDK | v0.4.4 |
1113
| InstaScale | v0.0.4 |
1214
| KubeRay | v0.5.0 |
15+
<!-- Compatibility Matrix end -->
1316

1417
## Release process
1518

@@ -23,23 +26,12 @@ Release steps:
2326

2427
2. Check result of [tag-and-build.yml](https://github.com/project-codeflare/codeflare-operator/actions/workflows/tag-and-build.yml) GitHub action, it should pass.
2528

26-
3. Update CodeFlare Stack Compatibility Matrix in operator README.
29+
3. Verify that compatibility matrix in [README](https://github.com/project-codeflare/codeflare-operator/blob/main/README.md) was properly updated.
2730

28-
4. Update InstaScale and MCAD versions:
29-
- in [Makefile](https://github.com/project-codeflare/codeflare-operator/blob/02e14b535b4f7172b0b809bcae4025008a1a968b/Makefile#L12-L16).
30-
- in [mcad/deployment.yaml.tmpl](https://github.com/project-codeflare/codeflare-operator/blob/main/config/internal/mcad/deployment.yaml.tmpl#L28)
31-
- in [controllers/defaults.go](https://github.com/project-codeflare/codeflare-operator/blob/main/controllers/defaults.go) by running `make defaults`
32-
- in [controllers/testdata/instascale_test_results/case_1/deployment.yaml](https://github.com/project-codeflare/codeflare-operator/blob/main/controllers/testdata/instascale_test_results/case_1/deployment.yaml) and [controllers/testdata/instascale_test_results/case_2/deployment.yaml](https://github.com/project-codeflare/codeflare-operator/blob/main/controllers/testdata/instascale_test_results/case_2/deployment.yaml)
31+
4. Verify that opened pull request to [OpenShift community operators repository](https://github.com/redhat-openshift-ecosystem/community-operators-prod) has proper content.
3332

34-
5. Create a release in CodeFlare operator repository, release notes should include new support matrix.
33+
5. Once PR is merged, update component stable tags to point at the latest image release.
3534

36-
6. Open a pull request to OpenShift community operators repository with latest bundle using make command, check that the created PR has proper content.
37-
```
38-
make openshift-community-operator-release
39-
```
35+
6. Announce the new release in slack and mail lists, if any.
4036

41-
7. Once merged, update component stable tags to point at the latest image release.
42-
43-
8. Announce the new release in slack and mail lists, if any.
44-
45-
9. Update the Distributed Workloads component in ODH (also copy/update the compatibility matrix).
37+
7. Update the Distributed Workloads component in ODH (also copy/update the compatibility matrix).

0 commit comments

Comments
 (0)