Skip to content

Commit 08fcb52

Browse files
authored
CLOUDP-295785 - move away from GHA variables (#388)
# Summary GitHub Variables cannot be accessed from forks. Forks are used by engineers to create PRs in this repo, but due to previously mentioned limitation some GitHub Actions fail. This PR moves the variables from GitHub to `root-context` file. Additionally to make contexts work in GitHub Actions I had to create `gha-private-context` file similar to `evg-private-context`, otherwise the switch command would fail. After this change all GitHub variables can be removed. ## Proof of Work Passing evg CI and GitHub Checks. ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details
1 parent d43f084 commit 08fcb52

File tree

7 files changed

+48
-8
lines changed

7 files changed

+48
-8
lines changed

.github/actions/setup-ubuntu-host/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ runs:
99
- name: setup python
1010
uses: actions/setup-python@v5
1111
with:
12-
python-version: ${{inputs.python-version}}
12+
python-version: '${{ inputs.python-version }}'
1313
cache: 'pip' # caching pip dependencies
1414
- name: Install dependencies
1515
shell: bash
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 'Switch context and export all environment variables'
2+
inputs:
3+
context-name:
4+
description: 'Context name to switch to'
5+
required: true
6+
runs:
7+
using: "composite"
8+
steps:
9+
- name: Switch context
10+
shell: bash
11+
run: |
12+
echo "Initializing context files"
13+
cp scripts/dev/contexts/gha-private-context scripts/dev/contexts/private-context
14+
scripts/dev/switch_context.sh ${{inputs.context-name}}
15+
echo "Finished initializing to the ${{inputs.context-name}}"
16+
while read line; do
17+
echo "$line" >> $GITHUB_ENV
18+
done < <(tail -n +5 .generated/context.env | sed 's/\"//g')

.github/workflows/preview_release_notes.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,22 @@ jobs:
2121
uses: actions/checkout@v4
2222
with:
2323
fetch-depth: '0'
24+
- name: Switch to root context
25+
id: switch_context
26+
uses: ./.github/actions/switch-context
27+
with:
28+
context-name: 'root-context'
2429
- name: Setup host
2530
uses: ./.github/actions/setup-ubuntu-host
2631
with:
27-
python-version: '${{ vars.PYTHON_VERSION }}'
32+
python-version: ${{ env.PYTHON_VERSION }}
2833
- name: Generate Release Notes
29-
id: generate_release_notes
3034
run: python -m scripts.release.release_notes -s $INITIAL_COMMIT_SHA -v $INITIAL_VERSION -o release_notes_tmp.md
3135
env:
3236
# We can not use environments set via GitHub UI because they will
3337
# not be available in the pull requests running from forks.
34-
INITIAL_COMMIT_SHA: 9ed5f98fc70c5b3442f633d2393265fb8a2aba0c
35-
INITIAL_VERSION: 1.3.0
38+
INITIAL_COMMIT_SHA: ${{ env.INITIAL_COMMIT_SHA }}
39+
INITIAL_VERSION: ${{ env.INITIAL_VERSION }}
3640
- name: Add disclaimer to release notes preview
3741
run: |
3842
echo -e "_:warning: (this preview might not be accurate if the PR is not rebased on current master branch)_\n" > release_notes_preview.md

.github/workflows/require_changelog.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ jobs:
2222
uses: actions/checkout@v4
2323
with:
2424
fetch-depth: '0'
25+
- name: Switch to root context
26+
id: switch_context
27+
uses: ./.github/actions/switch-context
28+
with:
29+
context-name: 'root-context'
2530
- name: Setup host
2631
uses: ./.github/actions/setup-ubuntu-host
2732
with:
28-
python-version: '${{ vars.PYTHON_VERSION }}'
33+
python-version: ${{ env.PYTHON_VERSION }}
2934
- name: Check if changelog entry file was added in this PR
3035
run: |
3136
set -o pipefail
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeou pipefail
4+
5+
export NAMESPACE=""
6+
export CLUSTER_NAME=""
7+
export LOCAL_OPERATOR="false"
8+
export BASE_REPO_URL=""

scripts/dev/contexts/root-context

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,7 @@ fi
129129
# but we can unify once we are done with unified operator
130130
# installation for both multicluster and single cluster setups.
131131
export OPERATOR_NAME="mongodb-kubernetes-operator"
132+
133+
# Variables used for release process
134+
export INITIAL_COMMIT_SHA="9ed5f98fc70c5b3442f633d2393265fb8a2aba0c"
135+
export INITIAL_VERSION="1.3.0"

scripts/dev/switch_context.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ else
6767
fi
6868
# Execute the command in a clean environment and capture exported variables
6969
# Let's use our PATH as a base to have utilities available.
70-
current_envs=$(env -i PATH="${PATH}" CURRENT_VARIANT_CONTEXT="${context}" bash -c "${base_command} && export -p")
70+
current_envs=$(env -i PWD="${PWD}" PATH="${PATH}" CURRENT_VARIANT_CONTEXT="${context}" bash -c "${base_command} && export -p")
7171

7272
# `export -p` instead of `env` ensures we can safely re-source variables which we rely on further
7373
# below like our operator.print.env script
@@ -76,7 +76,8 @@ else
7676
fi
7777

7878
# convert declare -x key=value into key=value
79-
current_envs=$(echo "${current_envs[@]}" | sed 's/^declare -x //g' | sed 's/=/=/'| sort | uniq)
79+
# filter out variables that don't have value (missing '=')
80+
current_envs=$(echo "${current_envs[@]}" | grep '=' | sed 's/^declare -x //g' | sed 's/=/=/'| sort | uniq)
8081

8182
echo -e "## This file is automatically generated by switch_context.sh\n## Do not edit it!" > "${destination_envs_file}.env"
8283
# shellcheck disable=SC2129

0 commit comments

Comments
 (0)