Skip to content

Commit 8dc98f9

Browse files
authored
chore(cd): Refactor version update action and add new sandbox paths (#60)
1 parent 2028d60 commit 8dc98f9

2 files changed

Lines changed: 70 additions & 65 deletions

File tree

.github/actions/update-config-version/action.yml

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@ inputs:
44
env:
55
description: 'Environment name (staging/production)'
66
required: true
7-
version_key:
8-
description: 'YAML path to the version key'
9-
required: true
10-
values_yaml:
11-
# Added this multi-file support because of app-config repo setup
12-
description: 'Path(s) to the values.yaml file(s) - one per line for multiple files'
7+
versions:
8+
description: |
9+
Version updates, one per line:
10+
--file "path/to/file.yaml" --key ".yq.expression" --value "version"
1311
required: true
1412
merge:
1513
description: 'Whether to merge the PR automatically (true/false)'
1614
required: true
17-
version:
18-
description: 'Version value to set'
19-
required: true
2015
github_token:
2116
description: 'GitHub token for authentication'
2217
required: true
@@ -82,9 +77,7 @@ runs:
8277
INPUT_TARGET_REPO: ${{ inputs.target_repo }}
8378
INPUT_BRANCH: ${{ inputs.branch }}
8479
INPUT_MERGE: ${{ inputs.merge }}
85-
INPUT_VERSION: ${{ inputs.version }}
86-
INPUT_VERSION_KEY: ${{ inputs.version_key }}
87-
INPUT_VALUES_YAML: ${{ inputs.values_yaml }}
80+
INPUT_VERSIONS: ${{ inputs.versions }}
8881
GITHUB_SERVER_URL: ${{ github.server_url }}
8982
GITHUB_REPOSITORY: ${{ github.repository }}
9083
GITHUB_RUN_ID: ${{ github.run_id }}
@@ -98,8 +91,6 @@ runs:
9891
TARGET_REPO_NAME="${INPUT_TARGET_REPO}"
9992
BRANCH="${INPUT_BRANCH}"
10093
MERGE="${INPUT_MERGE}"
101-
VERSION_VALUE="${INPUT_VERSION}"
102-
VERSION_KEY="${INPUT_VERSION_KEY}"
10394
10495
# Validate environment (staging or production only)
10596
if [[ ! "$ENV" =~ ^(staging|production)$ ]]; then
@@ -127,26 +118,10 @@ runs:
127118
exit 1
128119
fi
129120
130-
# Validate version format (semver or commit SHA)
131-
if [[ ! "$VERSION_VALUE" =~ ^(v?[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?|[0-9a-f]{7,40})$ ]]; then
132-
echo "ERROR: Invalid version format: $VERSION_VALUE"
133-
echo "Version must be semantic version (e.g., 1.2.3, v1.2.3) or commit SHA"
134-
exit 1
135-
fi
136-
137-
# Validate version key format (YAML path)
138-
if [[ ! "$VERSION_KEY" =~ ^\.?[a-zA-Z0-9_.]+$ ]]; then
139-
echo "ERROR: Invalid version key format: $VERSION_KEY"
140-
exit 1
141-
fi
142-
143121
# Set additional variables
144122
export ENV
145123
export RELEASE_NAME="deepnote-toolkit"
146-
export VERSION_KEY
147-
export VERSION_VALUE
148124
export TARGET_REPO_NAME
149-
export VALUES_YAML="${INPUT_VALUES_YAML}"
150125
export ORG_NAME="deepnote"
151126
export SOURCE_REPO_NAME="deepnote-toolkit"
152127
export GIT_URL="https://github.com/${ORG_NAME}/${SOURCE_REPO_NAME}"
@@ -159,27 +134,34 @@ runs:
159134
exit 1
160135
fi
161136
162-
# Commit body with GitHub Actions info
163-
git_commit_body="Bump ${ENV} ${RELEASE_NAME} to ${VERSION_VALUE}
164-
GitHub Actions: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}
165-
GitHub: ${GIT_URL}/commit/${GITHUB_SHA}"
137+
# Parse versions input: --file "path" --key ".expression" --value "version"
138+
declare -a FILE_PATHS
139+
declare -a VERSION_KEYS
140+
declare -a VERSION_VALUES
166141
167-
# Convert multiline input to array
168-
readarray -t FILES_ARRAY <<< "$VALUES_YAML"
169-
170-
# Remove empty lines and trim whitespace (using safe bash parameter expansion)
171-
YAML_FILES=()
172-
for file in "${FILES_ARRAY[@]}"; do
142+
while IFS= read -r line || [[ -n "$line" ]]; do
173143
# Trim leading whitespace
174-
file="${file#"${file%%[![:space:]]*}"}"
144+
line="${line#"${line%%[![:space:]]*}"}"
175145
# Trim trailing whitespace
176-
file="${file%"${file##*[![:space:]]}"}"
146+
line="${line%"${line##*[![:space:]]}"}"
177147
178148
# Skip empty lines
179-
if [ -z "$file" ]; then
149+
if [ -z "$line" ]; then
180150
continue
181151
fi
182152
153+
# Parse arguments from line
154+
file="" key="" value=""
155+
[[ $line =~ --file[[:space:]]+\"([^\"]+)\" ]] && file="${BASH_REMATCH[1]}"
156+
[[ $line =~ --key[[:space:]]+\"([^\"]+)\" ]] && key="${BASH_REMATCH[1]}"
157+
[[ $line =~ --value[[:space:]]+\"([^\"]+)\" ]] && value="${BASH_REMATCH[1]}"
158+
159+
if [[ -z "$file" || -z "$key" || -z "$value" ]]; then
160+
echo "ERROR: Missing or malformed argument in line: $line"
161+
echo "Expected format: --file \"path\" --key \".expression\" --value \"version\""
162+
exit 1
163+
fi
164+
183165
# Validate file path format (no path traversal, must end in .yaml or .yml)
184166
if [[ "$file" =~ \.\. ]]; then
185167
echo "ERROR: Path traversal detected in file path: $file"
@@ -192,25 +174,49 @@ runs:
192174
exit 1
193175
fi
194176
195-
YAML_FILES+=("$file")
196-
done
177+
# Validate key format (yq path expression)
178+
if [[ ! "$key" =~ ^\.?[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*$ ]]; then
179+
echo "ERROR: Invalid key format: $key"
180+
echo "Key must be a valid yq path expression (e.g., .foo.bar, .config.VERSION)"
181+
exit 1
182+
fi
183+
184+
# Validate version format (semver or commit SHA)
185+
if [[ ! "$value" =~ ^(v?[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?|[0-9a-f]{7,40})$ ]]; then
186+
echo "ERROR: Invalid version format: $value"
187+
echo "Version must be semantic version (e.g., 1.2.3, v1.2.3) or commit SHA"
188+
exit 1
189+
fi
197190
198-
# Validate we have at least one file
199-
if [ ${#YAML_FILES[@]} -eq 0 ]; then
200-
echo "ERROR: No YAML files provided"
191+
FILE_PATHS+=("$file")
192+
VERSION_KEYS+=("$key")
193+
VERSION_VALUES+=("$value")
194+
done <<< "$INPUT_VERSIONS"
195+
196+
# Validate we have at least one entry
197+
if [ ${#FILE_PATHS[@]} -eq 0 ]; then
198+
echo "ERROR: No version entries provided"
201199
exit 1
202200
fi
203201
202+
# Use first version value for commit message
203+
VERSION_VALUE="${VERSION_VALUES[0]}"
204+
205+
# Commit body with GitHub Actions info
206+
git_commit_body="Bump ${ENV} ${RELEASE_NAME} to ${VERSION_VALUE}
207+
GitHub Actions: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}
208+
GitHub: ${GIT_URL}/commit/${GITHUB_SHA}"
209+
204210
octopilot_args=(
205211
"--repo"
206212
"${ORG_NAME}/${TARGET_REPO_NAME}(merge=${MERGE},branch=${BRANCH})"
207213
)
208214
209-
# Add updates for all files
210-
for file in "${YAML_FILES[@]}"; do
215+
# Add updates for all file/key/value entries
216+
for i in "${!FILE_PATHS[@]}"; do
211217
octopilot_args+=(
212218
"--update"
213-
"yq(file=${file},expression='(${VERSION_KEY} = strenv(VERSION_VALUE))')"
219+
"yq(file=${FILE_PATHS[$i]},expression='(${VERSION_KEYS[$i]} = \"${VERSION_VALUES[$i]}\")')"
214220
)
215221
done
216222

.github/workflows/cd.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -474,26 +474,25 @@ jobs:
474474
uses: ./.github/actions/update-config-version
475475
with:
476476
env: staging
477-
version_key: .deepnoteConfig.DEEPNOTE_TOOLKIT_VERSION
478-
values_yaml: charts/deepnote/env/single-tenant-staging-values.yaml
477+
versions: |
478+
--file "charts/deepnote/env/single-tenant-staging-values.yaml" --key ".deepnoteConfig.DEEPNOTE_TOOLKIT_VERSION" --value "${{ env.VERSION }}"
479479
merge: true
480480
target_repo: ops
481481
branch: master
482-
version: ${{ env.VERSION }}
483482
github_token: ${{ secrets.DEEPNOTE_BOT_USER_TOKEN }}
484483

485484
- name: Update app-config repo multi-tenant staging version
486485
uses: ./.github/actions/update-config-version
487486
with:
488487
env: staging
489-
version_key: .deepnote.deepnoteConfig.DEEPNOTE_TOOLKIT_VERSION
490-
values_yaml: |
491-
env/dev-ue1/staging/deepnote/helm/values.yaml
492-
env/dev-ue1/values-ra.yaml
488+
versions: |
489+
--file "env/dev-ue1/staging/deepnote/helm/values.yaml" --key ".deepnote.deepnoteConfig.DEEPNOTE_TOOLKIT_VERSION" --value "${{ env.VERSION }}"
490+
--file "env/dev-ue1/values-ra.yaml" --key ".deepnote.deepnoteConfig.DEEPNOTE_TOOLKIT_VERSION" --value "${{ env.VERSION }}"
491+
--file "env/dev-ue1/staging/values.yaml" --key ".global.deepnote.toolkit.version" --value "${{ env.VERSION }}"
492+
--file "env/sandboxes/staging/values.yaml" --key ".global.deepnote.toolkit.version" --value "${{ env.VERSION }}"
493493
merge: true
494494
target_repo: app-config
495495
branch: main
496-
version: ${{ env.VERSION }}
497496
github_token: ${{ secrets.DEEPNOTE_BOT_USER_TOKEN }}
498497

499498
release-production:
@@ -515,22 +514,22 @@ jobs:
515514
uses: ./.github/actions/update-config-version
516515
with:
517516
env: production
518-
version_key: .deepnoteConfig.DEEPNOTE_TOOLKIT_VERSION
519-
values_yaml: charts/deepnote/chart/values.yaml
517+
versions: |
518+
--file "charts/deepnote/chart/values.yaml" --key ".deepnoteConfig.DEEPNOTE_TOOLKIT_VERSION" --value "${{ env.VERSION }}"
520519
merge: false
521520
target_repo: ops
522521
branch: master
523-
version: ${{ env.VERSION }}
524522
github_token: ${{ secrets.DEEPNOTE_BOT_USER_TOKEN }}
525523

526524
- name: Update app-config repo multi-tenant production version
527525
uses: ./.github/actions/update-config-version
528526
with:
529527
env: production
530-
version_key: .deepnote.deepnoteConfig.DEEPNOTE_TOOLKIT_VERSION
531-
values_yaml: env/prod-ue1/prod/deepnote/helm/values.yaml
528+
versions: |
529+
--file "env/prod-ue1/prod/deepnote/helm/values.yaml" --key ".deepnote.deepnoteConfig.DEEPNOTE_TOOLKIT_VERSION" --value "${{ env.VERSION }}"
530+
--file "env/prod-ue1/prod/values.yaml" --key ".global.deepnote.toolkit.version" --value "${{ env.VERSION }}"
531+
--file "env/sandboxes/prod/values.yaml" --key ".global.deepnote.toolkit.version" --value "${{ env.VERSION }}"
532532
merge: false
533533
target_repo: app-config
534534
branch: main
535-
version: ${{ env.VERSION }}
536535
github_token: ${{ secrets.DEEPNOTE_BOT_USER_TOKEN }}

0 commit comments

Comments
 (0)