diff --git a/.github/actions/setup-ubuntu-host/action.yml b/.github/actions/setup-ubuntu-host/action.yml index 8ab3c2a4c..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: ${{inputs.python-version}} + python-version: '${{ inputs.python-version }}' cache: 'pip' # caching pip dependencies - name: Install dependencies shell: bash diff --git a/.github/actions/switch-context/action.yml b/.github/actions/switch-context/action.yml new file mode 100644 index 000000000..ece7fab80 --- /dev/null +++ b/.github/actions/switch-context/action.yml @@ -0,0 +1,18 @@ +name: 'Switch context and export all environment variables' +inputs: + context-name: + description: 'Context name to switch to' + required: true +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}}" + while read line; do + echo "$line" >> $GITHUB_ENV + done < <(tail -n +5 .generated/context.env | sed 's/\"//g') diff --git a/.github/workflows/preview_release_notes.yml b/.github/workflows/preview_release_notes.yml index fcd684ac9..316c3176a 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: ${{ env.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: ${{ 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 d5811d36d..3c5f86c93 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: ${{ env.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" 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