From 9d775e9f0321afc1789c749115540cd1513224a7 Mon Sep 17 00:00:00 2001 From: Joao Marcal Date: Wed, 3 Apr 2024 19:21:42 +0100 Subject: [PATCH 1/8] chore(operator): adds the workflow for release-please adds as well documentation on the release process --- .github/workflows/operator-release-please.yml | 22 +++++++ operator/docs/operator/release.md | 60 +++++++++++++++++++ operator/release-please-config.json | 14 +++++ 3 files changed, 96 insertions(+) create mode 100644 .github/workflows/operator-release-please.yml create mode 100644 operator/docs/operator/release.md create mode 100644 operator/release-please-config.json diff --git a/.github/workflows/operator-release-please.yml b/.github/workflows/operator-release-please.yml new file mode 100644 index 0000000000000..1593b5f36cfd9 --- /dev/null +++ b/.github/workflows/operator-release-please.yml @@ -0,0 +1,22 @@ +name: operator-release-please + +on: + push: + paths: + - 'operator/**' + branches: + - master + +permissions: + contents: write + pull-requests: write + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: google-github-actions/release-please-action@v4 + with: + path: operator + config-file: operator/release-please-config.json + token: ${{ secrets.GH_TOKEN }} \ No newline at end of file diff --git a/operator/docs/operator/release.md b/operator/docs/operator/release.md new file mode 100644 index 0000000000000..cc575754339b7 --- /dev/null +++ b/operator/docs/operator/release.md @@ -0,0 +1,60 @@ +--- +title: "Release operations" +description: "Documentation on how the operator release process works" +lead: "" +date: 2023-04-01T09:00:00+00:00 +lastmod: 2023-04-01T09:00:00+00:00 +draft: false +images: [] +menu: + docs: + parent: "operator" +weight: 100 +toc: true +--- + +This document will go over the design of the release process for the Loki Operator and how to actually release. + +# Design + +To release Loki Operator we need the following: +1. Bump the Loki Operator version and generate the bundle manifests with `make bundle-all`; +2. Update the CHANGELOG.md with the new version; +3. Create a release tag on GitHub; +4. Open two PRs to [k8s-operatorhub/community-operators](https://github.com/k8s-operatorhub/community-operators) and [redhat-openshift-ecosystem/community-operators-prod](https://github.com/redhat-openshift-ecosystem/community-operators-prod) with the contents of the new bundles; + +Loki Operator uses the GitHub [action release-please](https://github.com/google-github-actions/release-please-action) to automate steps 2 and 3. Furthermore to automate step 4 we use a workflow that is triggered when a release tag is created. + +In the following sections we will go over how the workflows are configured. + +## release-please + +release-please automates CHANGELOG generation, the creation of GitHub releases, and version bumps. It does so by parsing the git history, looking for Conventional Commit messages, and creating release PRs. Once a release PR is merged release-please will create the release and it will again wait for a releasable unit before opening the next release PR. A releasable unit is a commit with one of the following prefixes: "feat", "fix", and "deps". + +The workflow that is responsible for the operator release-please is `.github/workflows/operator-release-please.yml`. Note that the operator release-please process is different from the one used by Loki. The operator release-please configuration lives in `operator/release-please-config.json`. + +Useful links: +- release-please [customizing releases documentation](https://github.com/googleapis/release-please/blob/main/docs/customizing.md) +- release-please [config documentation](https://github.com/googleapis/release-please/blob/main/docs/manifest-releaser.md#configfile) + +Since the operator is still pre `v1.0.0` we are leveraging `bump-minor-pre-major` and `bump-patch-for-minor-pre-major` so that merging "feat", "fix", and "deps" commits will only bump a patch version and merging "feat!" and "fix!" will bump the minor version. + +As of writting, the operator release-please will only act on merges to `main`. This means that we are able to support the following release scenarios: +- Case 1: Release a patch version of v0.Y.x+1 with the diff from v0.Y.x. This is only supported until a breaking feature gets merged to `main`. +- Case 2: Release a new minor version v0.Y+1.0 with the diff from v0.Y.x + +## Publish release to operatorhubs + +To publish a community release of Loki Operator to the community hubs we leverage the workflow in `.github/workflows/operator-publish-operator-hub.yml` this workflow is set to trigger on tag creation that matches `operator/`. + +This workflow will then use a workflow `.github/workflows/operator-reusable-hub-release.yml` that's responsible for: +- Creating on the folder `operators/loki-operator/` a new folder with the manifests for the new version; +- Adding the ocp supported version annotation to the `metadata.yaml` file only in the OpenShift community repo; +- Creating a PR to the appropriate community repo. + +# Releasing + +1. Creating a PR to bump the version (i.e https://github.com/grafana/loki/pull/12246) +2. Merging the release-please PR (i.e TBD ) +3. Grafana bot will automatically open a PRs to [k8s-operatorhub/community-operators](https://github.com/k8s-operatorhub/community-operators) and [redhat-openshift-ecosystem/community-operators-prod](https://github.com/redhat-openshift-ecosystem/community-operators-prod) + diff --git a/operator/release-please-config.json b/operator/release-please-config.json new file mode 100644 index 0000000000000..d493e0a81558b --- /dev/null +++ b/operator/release-please-config.json @@ -0,0 +1,14 @@ +{ + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": true, + "include-component-in-tag": true, + "tag-separator": "/", + "packages": { + "operator": { + "component": "operator", + "release-type": "go", + "pull-request-title-pattern": "chore(${component}): community release ${version}", + "changelog-path": "CHANGELOG.md" + } + } +} \ No newline at end of file From 4649626f8939531dadb87972838b4671de551b75 Mon Sep 17 00:00:00 2001 From: Joao Marcal Date: Thu, 4 Apr 2024 11:36:10 +0100 Subject: [PATCH 2/8] chore(operator): adds operator to release-please manifest adds bootstrap-sha to limit how far back release-please will have to look --- .release-please-manifest.json | 3 ++- operator/release-please-config.json | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 86dc4d17656aa..0d53815591edd 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,4 @@ { - ".": "2.9.6" + ".": "2.9.6", + "operator": "0.6.0" } diff --git a/operator/release-please-config.json b/operator/release-please-config.json index d493e0a81558b..6a59cc0e6a1e7 100644 --- a/operator/release-please-config.json +++ b/operator/release-please-config.json @@ -1,4 +1,5 @@ { + "bootstrap-sha": "d298093baa58fd31e1fe73544cea0408eb744710", "bump-minor-pre-major": true, "bump-patch-for-minor-pre-major": true, "include-component-in-tag": true, From 083c0a4ecb84f40cb45669d9d853c5578a8f8ab4 Mon Sep 17 00:00:00 2001 From: Joao Marcal Date: Mon, 8 Apr 2024 20:39:26 +0100 Subject: [PATCH 3/8] chore(operator): updates workflow to avoid operator releases from being set with latest --- .github/workflows/operator-release-please.yml | 24 +++++++++++++++++-- operator/release-please-config.json | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/operator-release-please.yml b/.github/workflows/operator-release-please.yml index 1593b5f36cfd9..7283859a4e1c5 100644 --- a/.github/workflows/operator-release-please.yml +++ b/.github/workflows/operator-release-please.yml @@ -12,11 +12,31 @@ permissions: pull-requests: write jobs: - release-please: + releasePlease: runs-on: ubuntu-latest + outputs: + release_created: ${{ steps.release.outputs.operator--release_created }} + release_name: ${{ steps.release.outputs.operator--tag_name }} steps: - uses: google-github-actions/release-please-action@v4 + id: release with: path: operator config-file: operator/release-please-config.json - token: ${{ secrets.GH_TOKEN }} \ No newline at end of file + token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} + publishRelease: + needs: + - "releasePlease" + runs-on: ubuntu-latest + if: ${{ needs.releasePlease.outputs.release_created }} + steps: + - name: "pull code to release" + uses: "actions/checkout@v4" + with: + path: "release" + - name: "publish release" + env: + GH_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} + working-directory: "release" + run: | + gh release edit "${{ needs.releasePlease.outputs.release_name }}" --draft=false --latest=false \ No newline at end of file diff --git a/operator/release-please-config.json b/operator/release-please-config.json index 6a59cc0e6a1e7..7fbd4eabf8a16 100644 --- a/operator/release-please-config.json +++ b/operator/release-please-config.json @@ -3,6 +3,7 @@ "bump-minor-pre-major": true, "bump-patch-for-minor-pre-major": true, "include-component-in-tag": true, + "draft": true, "tag-separator": "/", "packages": { "operator": { From e7a55f13f6d0491366acc3e5db0b97de045f40bc Mon Sep 17 00:00:00 2001 From: Joao Marcal Date: Tue, 9 Apr 2024 14:02:11 +0100 Subject: [PATCH 4/8] chore(operator): adds workflow to block merging operator release-please PR when missing prepare release PR --- .../operator-check-prepare-release-commit.yml | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/operator-check-prepare-release-commit.yml diff --git a/.github/workflows/operator-check-prepare-release-commit.yml b/.github/workflows/operator-check-prepare-release-commit.yml new file mode 100644 index 0000000000000..355bfd04041e8 --- /dev/null +++ b/.github/workflows/operator-check-prepare-release-commit.yml @@ -0,0 +1,49 @@ +name: operator-check-prepare-release-commit + +on: + pull_request: + paths: + - 'operator/**' + branches: + - master + +jobs: + check-commit: + runs-on: ubuntu-latest + if: | + github.event.pull_request.head.ref == 'release-please--branches--master--components--operator' && + contains(github.event.pull_request.title, 'chore( operator): community release') + steps: + - name: Extract release version + id: pr_semver + run: | + PR_TITLE="${{ github.event.pull_request.title }}" + SEMVER=$(echo "$PR_TITLE" | sed -n 's/^chore( operator): community release \([0-9]\+\.[0-9]\+\.[0-9]\+\)$/\1/p') + echo "semver=$SEMVER" >> $GITHUB_OUTPUT + + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: master + path: "release" + + - name: Check main commits for prepare release commit + id: check_commit + env: + GH_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} + working-directory: "release" + run: | + COMMIT=$(gh search commits "chore(operator): prepare community release v${{ steps.pr_semver.outputs.semver }}") + if [ -n "$COMMIT" ]; then + echo "Matching commit found." + echo "found=true" >> $GITHUB_OUTPUT + else + echo "No matching commit found." + echo "found=false" >> $GITHUB_OUTPUT + fi + + - name: Fail if no prepare release commit + if: steps.check_commit.outputs.found == 'false' + run: | + echo "No prepare release commit found for the release version ${{ steps.pr_semver.outputs.semver }}" + exit 1 From 42b19a977591939119a7e5de6a73bb28220f1c8f Mon Sep 17 00:00:00 2001 From: Joao Marcal Date: Tue, 9 Apr 2024 14:29:01 +0100 Subject: [PATCH 5/8] chore(operator): improve documentation --- operator/docs/operator/release.md | 34 +++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/operator/docs/operator/release.md b/operator/docs/operator/release.md index cc575754339b7..b92698841d6e4 100644 --- a/operator/docs/operator/release.md +++ b/operator/docs/operator/release.md @@ -13,19 +13,19 @@ weight: 100 toc: true --- -This document will go over the design of the release process for the Loki Operator and how to actually release. +This document will go over the design of the release process for the Loki Operator and how to release it. # Design To release Loki Operator we need the following: 1. Bump the Loki Operator version and generate the bundle manifests with `make bundle-all`; 2. Update the CHANGELOG.md with the new version; -3. Create a release tag on GitHub; +3. Create a release tag and a release on GitHub; 4. Open two PRs to [k8s-operatorhub/community-operators](https://github.com/k8s-operatorhub/community-operators) and [redhat-openshift-ecosystem/community-operators-prod](https://github.com/redhat-openshift-ecosystem/community-operators-prod) with the contents of the new bundles; -Loki Operator uses the GitHub [action release-please](https://github.com/google-github-actions/release-please-action) to automate steps 2 and 3. Furthermore to automate step 4 we use a workflow that is triggered when a release tag is created. +Loki Operator uses the GitHub [action release-please](https://github.com/google-github-actions/release-please-action) to automate steps 2 and 3. Furthermore, to automate step 4 we use a workflow that is triggered when a release tag is created. -In the following sections we will go over how the workflows are configured. +In the following sections, we will go over how the workflows are configured. ## release-please @@ -37,12 +37,27 @@ Useful links: - release-please [customizing releases documentation](https://github.com/googleapis/release-please/blob/main/docs/customizing.md) - release-please [config documentation](https://github.com/googleapis/release-please/blob/main/docs/manifest-releaser.md#configfile) +The following sub-section contains some notes on the Loki operator release-please configuration: +- Use of `bump-minor-pre-major` and `bump-patch-for-minor-pre-major`; +- Use of `draft`; +- Preventing merging the release-please PR without updating the manifests; + +### Use of `bump-minor-pre-major` and `bump-patch-for-minor-pre-major` + Since the operator is still pre `v1.0.0` we are leveraging `bump-minor-pre-major` and `bump-patch-for-minor-pre-major` so that merging "feat", "fix", and "deps" commits will only bump a patch version and merging "feat!" and "fix!" will bump the minor version. -As of writting, the operator release-please will only act on merges to `main`. This means that we are able to support the following release scenarios: +As of writing, the operator release-please will only act on merges to `main`. This means that we can support the following release scenarios: - Case 1: Release a patch version of v0.Y.x+1 with the diff from v0.Y.x. This is only supported until a breaking feature gets merged to `main`. - Case 2: Release a new minor version v0.Y+1.0 with the diff from v0.Y.x +### Use of `draft` + +Since the operator shares the same repo with Loki, we want to make sure that, when we create a release of the operator we don't that release to `latest`, otherwise it would look like the latest release from the operator was Loki's latest release. Unfortunately, release-please doesn't provide a way to disable this, so instead we enable `draft`. `draft` makes it so releases created by release-please are only created in draft. We then use a step that will publish the release without setting it to the latest. + +### Preventing merging the release-please PR without updating the manifests + +Since step 1. is currently not automated and disconnected from release-please we have put in place a workflow in `.github/workflows/operator-check-prepare-release-commit.yml` that runs on release-please PRs. This workflow is responsible for making sure that in master exists a commit with the message `chore(operator): prepare community release v$VERSION`. Once we automate step 1. we should be able to remove this workflow. + ## Publish release to operatorhubs To publish a community release of Loki Operator to the community hubs we leverage the workflow in `.github/workflows/operator-publish-operator-hub.yml` this workflow is set to trigger on tag creation that matches `operator/`. @@ -50,11 +65,12 @@ To publish a community release of Loki Operator to the community hubs we leverag This workflow will then use a workflow `.github/workflows/operator-reusable-hub-release.yml` that's responsible for: - Creating on the folder `operators/loki-operator/` a new folder with the manifests for the new version; - Adding the ocp supported version annotation to the `metadata.yaml` file only in the OpenShift community repo; -- Creating a PR to the appropriate community repo. +- Creating a PR for the appropriate community repo. # Releasing -1. Creating a PR to bump the version (i.e https://github.com/grafana/loki/pull/12246) -2. Merging the release-please PR (i.e TBD ) -3. Grafana bot will automatically open a PRs to [k8s-operatorhub/community-operators](https://github.com/k8s-operatorhub/community-operators) and [redhat-openshift-ecosystem/community-operators-prod](https://github.com/redhat-openshift-ecosystem/community-operators-prod) +1. Create a PR to bump the version (i.e https://github.com/grafana/loki/pull/12246), be careful with the commit message; +2. Re-triggering the action `operator-publish-operator-hub` on the release-please PR; +3. Merging the release-please PR (i.e TBD ); +4. Grafana bot will automatically open a PRs to [k8s-operatorhub/community-operators](https://github.com/k8s-operatorhub/community-operators) and [redhat-openshift-ecosystem/community-operators-prod](https://github.com/redhat-openshift-ecosystem/community-operators-prod); From 299c426a76b56b53db17c2de497e20276337ece9 Mon Sep 17 00:00:00 2001 From: Joao Marcal Date: Tue, 9 Apr 2024 15:21:40 +0100 Subject: [PATCH 6/8] chore(operator): fix GH_TOKEN name --- .github/workflows/operator-check-prepare-release-commit.yml | 2 +- .github/workflows/operator-release-please.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/operator-check-prepare-release-commit.yml b/.github/workflows/operator-check-prepare-release-commit.yml index 355bfd04041e8..850a516c9523a 100644 --- a/.github/workflows/operator-check-prepare-release-commit.yml +++ b/.github/workflows/operator-check-prepare-release-commit.yml @@ -30,7 +30,7 @@ jobs: - name: Check main commits for prepare release commit id: check_commit env: - GH_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} + GH_TOKEN: ${{ secrets.GH_TOKEN }} working-directory: "release" run: | COMMIT=$(gh search commits "chore(operator): prepare community release v${{ steps.pr_semver.outputs.semver }}") diff --git a/.github/workflows/operator-release-please.yml b/.github/workflows/operator-release-please.yml index 7283859a4e1c5..9650d15aaa6a1 100644 --- a/.github/workflows/operator-release-please.yml +++ b/.github/workflows/operator-release-please.yml @@ -23,7 +23,7 @@ jobs: with: path: operator config-file: operator/release-please-config.json - token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} + token: ${{ secrets.GH_TOKEN }} publishRelease: needs: - "releasePlease" @@ -36,7 +36,7 @@ jobs: path: "release" - name: "publish release" env: - GH_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} + GH_TOKEN: ${{ secrets.GH_TOKEN }} working-directory: "release" run: | gh release edit "${{ needs.releasePlease.outputs.release_name }}" --draft=false --latest=false \ No newline at end of file From d880c244eea22f3b2d90fa15bc21411e0bdb3859 Mon Sep 17 00:00:00 2001 From: Joao Marcal Date: Wed, 10 Apr 2024 17:35:16 +0100 Subject: [PATCH 7/8] chore(operator): merge two last steps on operator-check-prepare-release-commit --- .../operator-check-prepare-release-commit.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/operator-check-prepare-release-commit.yml b/.github/workflows/operator-check-prepare-release-commit.yml index 850a516c9523a..3a81467bf1ab6 100644 --- a/.github/workflows/operator-check-prepare-release-commit.yml +++ b/.github/workflows/operator-check-prepare-release-commit.yml @@ -29,21 +29,14 @@ jobs: - name: Check main commits for prepare release commit id: check_commit - env: + env:exit 1 GH_TOKEN: ${{ secrets.GH_TOKEN }} working-directory: "release" run: | COMMIT=$(gh search commits "chore(operator): prepare community release v${{ steps.pr_semver.outputs.semver }}") if [ -n "$COMMIT" ]; then - echo "Matching commit found." - echo "found=true" >> $GITHUB_OUTPUT + echo "Prepare release commit found." else - echo "No matching commit found." - echo "found=false" >> $GITHUB_OUTPUT + echo "No prepare release commit found for the release version ${{ steps.pr_semver.outputs.semver }}" + exit 1 fi - - - name: Fail if no prepare release commit - if: steps.check_commit.outputs.found == 'false' - run: | - echo "No prepare release commit found for the release version ${{ steps.pr_semver.outputs.semver }}" - exit 1 From 90c011347c602aae3b6bd42384105cf739c3b157 Mon Sep 17 00:00:00 2001 From: Joao Marcal Date: Thu, 11 Apr 2024 10:19:10 +0100 Subject: [PATCH 8/8] chore(operator): fix typo --- .github/workflows/operator-check-prepare-release-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/operator-check-prepare-release-commit.yml b/.github/workflows/operator-check-prepare-release-commit.yml index 3a81467bf1ab6..cf153f75f23ae 100644 --- a/.github/workflows/operator-check-prepare-release-commit.yml +++ b/.github/workflows/operator-check-prepare-release-commit.yml @@ -29,7 +29,7 @@ jobs: - name: Check main commits for prepare release commit id: check_commit - env:exit 1 + env: GH_TOKEN: ${{ secrets.GH_TOKEN }} working-directory: "release" run: |