Tag and Release #24
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build the CodeFlare Operator image and push it to the project-codeflare image registry | |
name: Tag and Release | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Tag to be used for operator image' | |
required: true | |
default: 'v0.0.0-dev' | |
replaces: | |
description: 'The previous semantic version that this tag replaces.' | |
required: true | |
default: 'v0.0.0-dev' | |
mcad-version: | |
description: 'Published version of multi-cluster-app-dispatcher' | |
required: true | |
default: 'v0.0.0-dev' | |
codeflare-sdk-version: | |
description: 'Published version of CodeFlare-SDK' | |
required: true | |
default: 'v0.0.0-dev' | |
instascale-version: | |
description: 'Published version of InstaScale' | |
required: true | |
default: 'v0.0.0-dev' | |
is-stable: | |
description: 'Select if the built image should be tagged as stable' | |
required: true | |
type: boolean | |
quay-organization: | |
description: 'Quay organization used to push the built images to' | |
required: true | |
default: 'project-codeflare' | |
community-operators-prod-fork-organization: | |
description: 'Owner of forked community-operators-prod repository used to push bundle files to' | |
required: true | |
default: 'project-codeflare' | |
community-operators-prod-organization: | |
description: 'Owner of target community-operators-prod repository used to open a PR against' | |
required: true | |
default: 'redhat-openshift-ecosystem' | |
jobs: | |
push: | |
runs-on: ubuntu-latest | |
# Permission required to create a release | |
permissions: | |
contents: write | |
pull-requests: write | |
env: | |
IMAGE_ORG_BASE: quay.io/${{ github.event.inputs.quay-organization }} | |
PR_BRANCH_NAME: adjustments-release-${{ github.event.inputs.version }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: v1.19 | |
- name: Verify that release doesn't exist yet | |
shell: bash {0} | |
run: | | |
gh release view ${{ github.event.inputs.version }} | |
status=$? | |
if [[ $status -eq 0 ]]; then | |
echo "Release ${{ github.event.inputs.version }} already exists." | |
exit 1 | |
fi | |
env: | |
GITHUB_TOKEN: ${{ github.TOKEN }} | |
- name: Activate cache | |
uses: actions/cache@v3 | |
with: | |
path: /cache | |
key: ${{ runner.os }}-cache-${{ hashFiles('**/go.sum', '.pre-commit-config.yaml') }} | |
- name: Install operator-sdk | |
run: make install-operator-sdk | |
- name: Adjust Compatibility Matrix in readme | |
run: | | |
sed -i -E "s|(.*CodeFlare Operator.*\[).*(\].*releases/tag/).*(\).*)|\1${{ github.event.inputs.version }}\2${{ github.event.inputs.version }}\3|" README.md | |
sed -i -E "s|(.*Multi-Cluster App Dispatcher.*\[).*(\].*releases/tag/).*(\).*)|\1${{ github.event.inputs.mcad-version }}\2${{ github.event.inputs.mcad-version }}\3|" README.md | |
sed -i -E "s|(.*CodeFlare-SDK.*\[).*(\].*releases/tag/).*(\).*)|\1${{ github.event.inputs.codeflare-sdk-version }}\2${{ github.event.inputs.codeflare-sdk-version }}\3|" README.md | |
sed -i -E "s|(.*InstaScale.*\[).*(\].*releases/tag/).*(\).*)|\1${{ github.event.inputs.instascale-version }}\2${{ github.event.inputs.instascale-version }}\3|" README.md | |
- name: Adjust MCAD, SDK and InstaScale dependencies in the code | |
run: | | |
# Remove leading 'v' | |
sed -i -E "s/(.*MCAD_VERSION \?= ).*/\1${{ github.event.inputs.mcad-version }}/" Makefile | |
sed -i -E "s/(.*MCAD_REF \?= ).*/\1release-\${MCAD_VERSION}/" Makefile | |
sed -i -E "s/(.*INSTASCALE_VERSION \?= ).*/\1${{ github.event.inputs.instascale-version }}/" Makefile | |
- name: Login to Quay.io | |
uses: redhat-actions/podman-login@v1 | |
with: | |
username: ${{ secrets.QUAY_ID }} | |
password: ${{ secrets.QUAY_TOKEN }} | |
registry: quay.io | |
- name: Image Build and Push | |
run: | | |
make build | |
make image-build -e IMG=quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:${{ github.event.inputs.version }} | |
make image-push -e IMG=quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:${{ github.event.inputs.version }} | |
- name: Image Push as stable tag | |
if: ${{ inputs.is-stable }} | |
run: | | |
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 | |
make image-push -e IMG=quay.io/${{ github.event.inputs.quay-organization }}/codeflare-operator:stable | |
- name: Build bundle and create PR in OpenShift community operators repository | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "codeflare-machine-account" | |
make openshift-community-operator-release | |
env: | |
VERSION: ${{ github.event.inputs.version }} | |
PREVIOUS_VERSION: ${{ github.event.inputs.replaces }} | |
INSTASCALE_VERSION: ${{ github.event.inputs.instascale-version }} | |
MCAD_VERSION: ${{ github.event.inputs.mcad-version }} | |
GH_TOKEN: ${{ secrets.CODEFLARE_MACHINE_ACCOUNT_TOKEN }} | |
OPERATORS_REPO_FORK_ORG: ${{ github.event.inputs.community-operators-prod-fork-organization }} | |
OPERATORS_REPO_ORG: ${{ github.event.inputs.community-operators-prod-organization }} | |
- name: Cleanup the go.mod and go.sum | |
run: | | |
go mod tidy | |
- name: Commit changes in the code back to repository | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: Update dependency versions for release ${{ github.event.inputs.version }} | |
file_pattern: 'README.md */defaults.go *.yaml Makefile go.mod go.sum' | |
create_branch: true | |
branch: ${{ env.PR_BRANCH_NAME }} | |
- name: Create a PR with code changes | |
run: | | |
GIT_BRANCH=${GITHUB_REF#refs/heads/} | |
gh pr create --base "$GIT_BRANCH" --fill --head "${{ env.PR_BRANCH_NAME }}" --label "lgtm" --label "approved" | |
env: | |
GITHUB_TOKEN: ${{ secrets.CODEFLARE_MACHINE_ACCOUNT_TOKEN }} | |
- name: Wait until PR with code changes is merged | |
run: | | |
timeout 3600 bash -c 'until [[ $(gh pr view '${{ env.PR_BRANCH_NAME }}' --json state --jq .state) == "MERGED" ]]; do sleep 5 && echo "$(gh pr view '${{ env.PR_BRANCH_NAME }}' --json state --jq .state)"; done' | |
env: | |
GITHUB_TOKEN: ${{ github.TOKEN }} | |
- name: Delete remote branch | |
run: | | |
git push origin --delete ${{ env.PR_BRANCH_NAME }} | |
- name: Creates a release in GitHub | |
run: | | |
gh release create ${{ github.event.inputs.version }} --target ${{ github.ref }} --generate-notes | |
# Edit notes to add there compatibility matrix | |
sed --null-data -E "s/(.*<\!-- Compatibility Matrix start -->)(.*)(<\!-- Compatibility Matrix end -->.*)/\2/" README.md > release-notes.md | |
echo "" >> release-notes.md | |
echo "$(gh release view --json body --jq .body)" >> release-notes.md | |
gh release edit ${{ github.event.inputs.version }} --notes-file release-notes.md | |
rm release-notes.md | |
env: | |
GITHUB_TOKEN: ${{ secrets.CODEFLARE_MACHINE_ACCOUNT_TOKEN }} | |
shell: bash |