From 744ed299523ebd7edd105f8f4923fc2a5c631fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 15:33:32 +0200 Subject: [PATCH 01/14] CLOUDP-295785 - move away from GHA variables --- .github/actions/switch-context/action.yml | 28 +++++++++++++++++++++ .github/workflows/preview_release_notes.yml | 12 ++++++--- .github/workflows/require_changelog.yml | 7 +++++- scripts/dev/contexts/gha-private-context | 8 ++++++ scripts/dev/contexts/root-context | 4 +++ 5 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 .github/actions/switch-context/action.yml create mode 100644 scripts/dev/contexts/gha-private-context diff --git a/.github/actions/switch-context/action.yml b/.github/actions/switch-context/action.yml new file mode 100644 index 000000000..3e3755c7b --- /dev/null +++ b/.github/actions/switch-context/action.yml @@ -0,0 +1,28 @@ +name: 'Switch context' +inputs: + context-name: + description: 'Context name to switch to' + required: true + outputs: + python-version: + description: 'Python version' + value: string + initial-commit-sha: + description: 'Initial commit sha for calculating changelog diffs' + value: string + initial-version: + description: 'Initial version to release if no tag exists yet' + value: string +runs: + using: "composite" + steps: + - name: Switch context + shell: bash + run: | + echo "Initializing context files" + cp scripts/dev/contexts/gha-private-context scripts/dev/contexts/private-context + scripts/dev/switch_context.sh ${{inputs.context-name}} + echo "Finished initializing to the ${{inputs.context-name}}" + echo "python-version=$(echo $PYTHON_VERSION)" >> $GITHUB_OUTPUT + echo "initial-commit-sha=$(echo $INITIAL_COMMIT_SHA)" >> $GITHUB_OUTPUT + echo "initial-version=$(echo $INITIAL_VERSION)" >> $GITHUB_OUTPUT diff --git a/.github/workflows/preview_release_notes.yml b/.github/workflows/preview_release_notes.yml index fcd684ac9..3b8951624 100644 --- a/.github/workflows/preview_release_notes.yml +++ b/.github/workflows/preview_release_notes.yml @@ -21,18 +21,22 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: '0' + - name: Switch to root context + id: switch_context + uses: ./.github/actions/switch-context + with: + context-name: 'root-context' - name: Setup host uses: ./.github/actions/setup-ubuntu-host with: - python-version: '${{ vars.PYTHON_VERSION }}' + python-version: '${{ steps.switch_context.outputs.python-version }}' - name: Generate Release Notes - id: generate_release_notes run: python -m scripts.release.release_notes -s $INITIAL_COMMIT_SHA -v $INITIAL_VERSION -o release_notes_tmp.md env: # We can not use environments set via GitHub UI because they will # not be available in the pull requests running from forks. - INITIAL_COMMIT_SHA: 9ed5f98fc70c5b3442f633d2393265fb8a2aba0c - INITIAL_VERSION: 1.3.0 + INITIAL_COMMIT_SHA: '${{ steps.switch_context.outputs.initial-commit-sha }}' + INITIAL_VERSION: '${{ steps.switch_context.outputs.initial-version}}' - name: Add disclaimer to release notes preview run: | echo -e "_:warning: (this preview might not be accurate if the PR is not rebased on current master branch)_\n" > release_notes_preview.md diff --git a/.github/workflows/require_changelog.yml b/.github/workflows/require_changelog.yml index d5811d36d..7a31717ba 100644 --- a/.github/workflows/require_changelog.yml +++ b/.github/workflows/require_changelog.yml @@ -22,10 +22,15 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: '0' + - name: Switch to root context + id: switch_context + uses: ./.github/actions/switch-context + with: + context-name: 'root-context' - name: Setup host uses: ./.github/actions/setup-ubuntu-host with: - python-version: '${{ vars.PYTHON_VERSION }}' + python-version: '${{ steps.switch_context.outputs.python-version }}' - name: Check if changelog entry file was added in this PR run: | set -o pipefail diff --git a/scripts/dev/contexts/gha-private-context b/scripts/dev/contexts/gha-private-context new file mode 100644 index 000000000..c5a189fb8 --- /dev/null +++ b/scripts/dev/contexts/gha-private-context @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -Eeou pipefail + +export NAMESPACE="" +export CLUSTER_NAME="" +export LOCAL_OPERATOR="false" +export BASE_REPO_URL="" diff --git a/scripts/dev/contexts/root-context b/scripts/dev/contexts/root-context index 7b147aa34..888039232 100644 --- a/scripts/dev/contexts/root-context +++ b/scripts/dev/contexts/root-context @@ -129,3 +129,7 @@ fi # but we can unify once we are done with unified operator # installation for both multicluster and single cluster setups. export OPERATOR_NAME="mongodb-kubernetes-operator" + +# Variables used for release process +export INITIAL_COMMIT_SHA="9ed5f98fc70c5b3442f633d2393265fb8a2aba0c" +export INITIAL_VERSION="1.3.0" From 87c9ccac6ce69e2ec196f4e6ad506b57be64a145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 15:37:19 +0200 Subject: [PATCH 02/14] fix --- .github/actions/switch-context/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/switch-context/action.yml b/.github/actions/switch-context/action.yml index 3e3755c7b..4a33d5227 100644 --- a/.github/actions/switch-context/action.yml +++ b/.github/actions/switch-context/action.yml @@ -23,6 +23,7 @@ runs: cp scripts/dev/contexts/gha-private-context scripts/dev/contexts/private-context scripts/dev/switch_context.sh ${{inputs.context-name}} echo "Finished initializing to the ${{inputs.context-name}}" + source .generated/context.export.env echo "python-version=$(echo $PYTHON_VERSION)" >> $GITHUB_OUTPUT echo "initial-commit-sha=$(echo $INITIAL_COMMIT_SHA)" >> $GITHUB_OUTPUT echo "initial-version=$(echo $INITIAL_VERSION)" >> $GITHUB_OUTPUT From 1cc3eaf2b5ef1204cf2cc9e8ca4e717ad2d73c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 15:44:19 +0200 Subject: [PATCH 03/14] test --- .github/actions/switch-context/action.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/actions/switch-context/action.yml b/.github/actions/switch-context/action.yml index 4a33d5227..d76214abd 100644 --- a/.github/actions/switch-context/action.yml +++ b/.github/actions/switch-context/action.yml @@ -23,7 +23,8 @@ runs: cp scripts/dev/contexts/gha-private-context scripts/dev/contexts/private-context scripts/dev/switch_context.sh ${{inputs.context-name}} echo "Finished initializing to the ${{inputs.context-name}}" - source .generated/context.export.env - echo "python-version=$(echo $PYTHON_VERSION)" >> $GITHUB_OUTPUT - echo "initial-commit-sha=$(echo $INITIAL_COMMIT_SHA)" >> $GITHUB_OUTPUT - echo "initial-version=$(echo $INITIAL_VERSION)" >> $GITHUB_OUTPUT + source .generated/context.env + printenv + echo "python-version=$(echo ${PYTHON_VERSION})" | tee $GITHUB_OUTPUT + echo "initial-commit-sha=$(echo ${INITIAL_COMMIT_SHA})" | tee $GITHUB_OUTPUT + echo "initial-version=$(echo ${INITIAL_VERSION})" | tee $GITHUB_OUTPUT From b519d6d1babe1da8467311fcd08b98893bfcfe55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 16:43:13 +0200 Subject: [PATCH 04/14] test --- .github/actions/switch-context/action.yml | 18 +++--------------- .github/workflows/preview_release_notes.yml | 6 +++--- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/.github/actions/switch-context/action.yml b/.github/actions/switch-context/action.yml index d76214abd..414cd22e4 100644 --- a/.github/actions/switch-context/action.yml +++ b/.github/actions/switch-context/action.yml @@ -3,16 +3,6 @@ inputs: context-name: description: 'Context name to switch to' required: true - outputs: - python-version: - description: 'Python version' - value: string - initial-commit-sha: - description: 'Initial commit sha for calculating changelog diffs' - value: string - initial-version: - description: 'Initial version to release if no tag exists yet' - value: string runs: using: "composite" steps: @@ -23,8 +13,6 @@ runs: cp scripts/dev/contexts/gha-private-context scripts/dev/contexts/private-context scripts/dev/switch_context.sh ${{inputs.context-name}} echo "Finished initializing to the ${{inputs.context-name}}" - source .generated/context.env - printenv - echo "python-version=$(echo ${PYTHON_VERSION})" | tee $GITHUB_OUTPUT - echo "initial-commit-sha=$(echo ${INITIAL_COMMIT_SHA})" | tee $GITHUB_OUTPUT - echo "initial-version=$(echo ${INITIAL_VERSION})" | tee $GITHUB_OUTPUT + while read line; do + echo "$line" >> $GITHUB_ENV + done < .generated/context.env diff --git a/.github/workflows/preview_release_notes.yml b/.github/workflows/preview_release_notes.yml index 3b8951624..978ccbb1d 100644 --- a/.github/workflows/preview_release_notes.yml +++ b/.github/workflows/preview_release_notes.yml @@ -29,14 +29,14 @@ jobs: - name: Setup host uses: ./.github/actions/setup-ubuntu-host with: - python-version: '${{ steps.switch_context.outputs.python-version }}' + python-version: '${{ env.PYTHON_VERSION }}' - name: Generate Release Notes run: python -m scripts.release.release_notes -s $INITIAL_COMMIT_SHA -v $INITIAL_VERSION -o release_notes_tmp.md env: # We can not use environments set via GitHub UI because they will # not be available in the pull requests running from forks. - INITIAL_COMMIT_SHA: '${{ steps.switch_context.outputs.initial-commit-sha }}' - INITIAL_VERSION: '${{ steps.switch_context.outputs.initial-version}}' + INITIAL_COMMIT_SHA: '${{ env.INITIAL_COMMIT_SHA }}' + INITIAL_VERSION: '${{ env.INITIAL_VERSION }}' - name: Add disclaimer to release notes preview run: | echo -e "_:warning: (this preview might not be accurate if the PR is not rebased on current master branch)_\n" > release_notes_preview.md From 77c22754f6f77e232a6e7d60d448c7da8af02a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 16:45:37 +0200 Subject: [PATCH 05/14] test 2 --- .github/actions/switch-context/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/switch-context/action.yml b/.github/actions/switch-context/action.yml index 414cd22e4..9af7a7657 100644 --- a/.github/actions/switch-context/action.yml +++ b/.github/actions/switch-context/action.yml @@ -15,4 +15,4 @@ runs: echo "Finished initializing to the ${{inputs.context-name}}" while read line; do echo "$line" >> $GITHUB_ENV - done < .generated/context.env + done < .generated/context.env | tail -n +5 From 5dd12b217d3f66cabf1b922844c4b1a6993903a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 16:49:06 +0200 Subject: [PATCH 06/14] test 3 --- .github/actions/switch-context/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/switch-context/action.yml b/.github/actions/switch-context/action.yml index 9af7a7657..5c23af0d1 100644 --- a/.github/actions/switch-context/action.yml +++ b/.github/actions/switch-context/action.yml @@ -15,4 +15,4 @@ runs: echo "Finished initializing to the ${{inputs.context-name}}" while read line; do echo "$line" >> $GITHUB_ENV - done < .generated/context.env | tail -n +5 + done < tail -n +5 .generated/context.env From af83232dbebee584ea43ccfeb4bd0dd8e15603f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 16:50:34 +0200 Subject: [PATCH 07/14] test 4 --- .github/actions/switch-context/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/switch-context/action.yml b/.github/actions/switch-context/action.yml index 5c23af0d1..153c87a47 100644 --- a/.github/actions/switch-context/action.yml +++ b/.github/actions/switch-context/action.yml @@ -15,4 +15,4 @@ runs: echo "Finished initializing to the ${{inputs.context-name}}" while read line; do echo "$line" >> $GITHUB_ENV - done < tail -n +5 .generated/context.env + done < <(tail -n +5 .generated/context.env) From ef06a29558962bc33a2902399b50619f18aa47c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 21:44:11 +0200 Subject: [PATCH 08/14] test 4 --- scripts/dev/switch_context.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/dev/switch_context.sh b/scripts/dev/switch_context.sh index ef2705451..06ffb085e 100755 --- a/scripts/dev/switch_context.sh +++ b/scripts/dev/switch_context.sh @@ -67,7 +67,7 @@ else fi # Execute the command in a clean environment and capture exported variables # Let's use our PATH as a base to have utilities available. - current_envs=$(env -i PATH="${PATH}" CURRENT_VARIANT_CONTEXT="${context}" bash -c "${base_command} && export -p") + current_envs=$(env -i PWD="${PWD}" PATH="${PATH}" CURRENT_VARIANT_CONTEXT="${context}" bash -c "${base_command} && export -p") # `export -p` instead of `env` ensures we can safely re-source variables which we rely on further # below like our operator.print.env script @@ -76,7 +76,8 @@ else fi # convert declare -x key=value into key=value -current_envs=$(echo "${current_envs[@]}" | sed 's/^declare -x //g' | sed 's/=/=/'| sort | uniq) +# filter out variables that don't have value (missing '=') +current_envs=$(echo "${current_envs[@]}" | grep '=' | sed 's/^declare -x //g' | sed 's/=/=/'| sort | uniq) echo -e "## This file is automatically generated by switch_context.sh\n## Do not edit it!" > "${destination_envs_file}.env" # shellcheck disable=SC2129 From 16b1cbce6d4c0a895ac4520198ffef74e3a55de2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 21:48:19 +0200 Subject: [PATCH 09/14] Final test --- .github/actions/switch-context/action.yml | 2 +- .github/workflows/preview_release_notes.yml | 6 +++--- .github/workflows/require_changelog.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/actions/switch-context/action.yml b/.github/actions/switch-context/action.yml index 153c87a47..ac944adb6 100644 --- a/.github/actions/switch-context/action.yml +++ b/.github/actions/switch-context/action.yml @@ -1,4 +1,4 @@ -name: 'Switch context' +name: 'Switch context and export all environment variables' inputs: context-name: description: 'Context name to switch to' diff --git a/.github/workflows/preview_release_notes.yml b/.github/workflows/preview_release_notes.yml index 978ccbb1d..316c3176a 100644 --- a/.github/workflows/preview_release_notes.yml +++ b/.github/workflows/preview_release_notes.yml @@ -29,14 +29,14 @@ jobs: - name: Setup host uses: ./.github/actions/setup-ubuntu-host with: - python-version: '${{ env.PYTHON_VERSION }}' + python-version: ${{ env.PYTHON_VERSION }} - name: Generate Release Notes run: python -m scripts.release.release_notes -s $INITIAL_COMMIT_SHA -v $INITIAL_VERSION -o release_notes_tmp.md env: # We can not use environments set via GitHub UI because they will # not be available in the pull requests running from forks. - INITIAL_COMMIT_SHA: '${{ env.INITIAL_COMMIT_SHA }}' - INITIAL_VERSION: '${{ env.INITIAL_VERSION }}' + INITIAL_COMMIT_SHA: ${{ env.INITIAL_COMMIT_SHA }} + INITIAL_VERSION: ${{ env.INITIAL_VERSION }} - name: Add disclaimer to release notes preview run: | echo -e "_:warning: (this preview might not be accurate if the PR is not rebased on current master branch)_\n" > release_notes_preview.md diff --git a/.github/workflows/require_changelog.yml b/.github/workflows/require_changelog.yml index 7a31717ba..3c5f86c93 100644 --- a/.github/workflows/require_changelog.yml +++ b/.github/workflows/require_changelog.yml @@ -30,7 +30,7 @@ jobs: - name: Setup host uses: ./.github/actions/setup-ubuntu-host with: - python-version: '${{ steps.switch_context.outputs.python-version }}' + python-version: ${{ env.PYTHON_VERSION }} - name: Check if changelog entry file was added in this PR run: | set -o pipefail From 3d850963522288933b98672e6eadda0fa5af0d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 21:51:22 +0200 Subject: [PATCH 10/14] update python version to 3.13.0 --- scripts/dev/contexts/root-context | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dev/contexts/root-context b/scripts/dev/contexts/root-context index 888039232..26f5d807b 100644 --- a/scripts/dev/contexts/root-context +++ b/scripts/dev/contexts/root-context @@ -92,7 +92,7 @@ export e2e_cloud_qa_baseurl_static_2="${OM_HOST}" export OLM_VERSION=v0.31.0 # Python version we use locally and in CI -export PYTHON_VERSION=3.13 +export PYTHON_VERSION=3.13.0 ## MCO From f86569b1d2f94b5bb5a35c33b5db108a13adb369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 21:59:11 +0200 Subject: [PATCH 11/14] update python version to 3.13 with single quotes --- .github/actions/switch-context/action.yml | 2 +- scripts/dev/contexts/root-context | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/switch-context/action.yml b/.github/actions/switch-context/action.yml index ac944adb6..8f7b6afbc 100644 --- a/.github/actions/switch-context/action.yml +++ b/.github/actions/switch-context/action.yml @@ -15,4 +15,4 @@ runs: echo "Finished initializing to the ${{inputs.context-name}}" while read line; do echo "$line" >> $GITHUB_ENV - done < <(tail -n +5 .generated/context.env) + done < <(tail -n +5 .generated/context.env | sed "s/\"/'/g") diff --git a/scripts/dev/contexts/root-context b/scripts/dev/contexts/root-context index 26f5d807b..888039232 100644 --- a/scripts/dev/contexts/root-context +++ b/scripts/dev/contexts/root-context @@ -92,7 +92,7 @@ export e2e_cloud_qa_baseurl_static_2="${OM_HOST}" export OLM_VERSION=v0.31.0 # Python version we use locally and in CI -export PYTHON_VERSION=3.13.0 +export PYTHON_VERSION=3.13 ## MCO From 5d2520ca3504d6d00c1f00afbbbb1ec50b469a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 22:01:44 +0200 Subject: [PATCH 12/14] test --- .github/actions/setup-ubuntu-host/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-ubuntu-host/action.yml b/.github/actions/setup-ubuntu-host/action.yml index 8ab3c2a4c..fb6f1dca9 100644 --- a/.github/actions/setup-ubuntu-host/action.yml +++ b/.github/actions/setup-ubuntu-host/action.yml @@ -9,7 +9,7 @@ runs: - name: setup python uses: actions/setup-python@v5 with: - python-version: ${{inputs.python-version}} + python-version: '3.13' cache: 'pip' # caching pip dependencies - name: Install dependencies shell: bash From 85a320148624d64f100d908af3099b899f584298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 22:04:02 +0200 Subject: [PATCH 13/14] test --- .github/actions/setup-ubuntu-host/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-ubuntu-host/action.yml b/.github/actions/setup-ubuntu-host/action.yml index fb6f1dca9..ec1a93286 100644 --- a/.github/actions/setup-ubuntu-host/action.yml +++ b/.github/actions/setup-ubuntu-host/action.yml @@ -9,7 +9,7 @@ runs: - name: setup python uses: actions/setup-python@v5 with: - python-version: '3.13' + python-version: '${{ inputs.python-version }}' cache: 'pip' # caching pip dependencies - name: Install dependencies shell: bash From 3b7e37b3c6bdde9e97fdbc44c62eb1f8fe6dc7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kara=C5=9B?= Date: Fri, 29 Aug 2025 22:06:37 +0200 Subject: [PATCH 14/14] test --- .github/actions/switch-context/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/switch-context/action.yml b/.github/actions/switch-context/action.yml index 8f7b6afbc..ece7fab80 100644 --- a/.github/actions/switch-context/action.yml +++ b/.github/actions/switch-context/action.yml @@ -15,4 +15,4 @@ runs: echo "Finished initializing to the ${{inputs.context-name}}" while read line; do echo "$line" >> $GITHUB_ENV - done < <(tail -n +5 .generated/context.env | sed "s/\"/'/g") + done < <(tail -n +5 .generated/context.env | sed 's/\"//g')