Skip to content

Commit

Permalink
feat: bump chart versions and references automatically (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathnogueira authored Aug 9, 2024
1 parent bfd6852 commit 36c0856
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/bump-chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## This job is triggered by the "Release version" of any
## of the tracetest components. When a new version of any tracetest
## component is released, this workflow should be triggered and
## it will update the respective chart with the new release version
##
##
## Required values in the payload:
## * @string project_name
## * @string version
name: Update chart version

on:
repository_dispatch:
types: [update-chart]

jobs:
update-chart:
name: Update chart
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update appVersion
run: |
./scripts/update_chart.sh \
${{ github.event.client_payload.project_name }} \
${{ github.event.client_payload.version }}
9 changes: 9 additions & 0 deletions scripts/git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
commit_and_push() {
message=$1

git config --global user.name "GitHub Actions"
git config --global user.email ""

git commit -m "$message"
git push
}
28 changes: 28 additions & 0 deletions scripts/update_chart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -e

get_path() {
path=$1
PWD=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
realPath="$PWD/$path"

echo $realPath
}

source `get_path ./update_chart_references.sh`
source `get_path ./git.sh`

# Update the `appVersion` in each chart affected by a new release
# Parameters:
# @string projectName
# @string version
projectName=$1
version=$2

update_chart_references $projectName $version `get_path ./update_chart_instructions.yaml`

git add `get_path ../charts`
git status

commit_and_push "Bump chart to version $version"
25 changes: 25 additions & 0 deletions scripts/update_chart_instructions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Define what files/paths needs to be updated with new tag for each repository
# The file paths are relative to `argo/` directory
oss:
- file: charts/tracetest-agent-operator/values.yaml
jsonpath: .config.targetVersion

core:
- file: charts/tracetest-core/Chart.yaml
jsonpath: .appVersion

cloud:
- file: charts/tracetest-cloud/Chart.yaml
jsonpath: .appVersion
- file: charts/tracetest-agent-operator/Chart.yaml
jsonpath: .appVersion
- file: charts/tracetest-monitor-operator/Chart.yaml
jsonpath: .appVersion

frontend:
- file: charts/tracetest-frontend/Chart.yaml
jsonpath: .appVersion

pokeshop:
- file: charts/pokeshop-demo/Chart.yaml
jsonpath: .appVersion
33 changes: 33 additions & 0 deletions scripts/update_chart_references.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

update_chart_references() {
REPO_NAME=$1
NEW_TAG=$2
INSTRUCTIONS_FILE=$3

instructions=`yq e ".${REPO_NAME}" -o=json "$INSTRUCTIONS_FILE"`
if [[ "$instructions" != "null" ]]; then
echo "$instructions" | jq -c .[] | while read -r line; do
FILE=$(echo $line | jq -r '.file')
JSON_PATH=$(echo $line | jq -r '.jsonpath')
SED_EXPRESSION=$(echo $line | jq -r '.sed_expression // empty')
ABSOLUTE_FILE_PATH=`get_path ../$FILE`

echo "$FILE:"
echo " JSON path: $JSON_PATH"

if [[ -n "$SED_EXPRESSION" ]]; then
echo " SED expression: " '"'$SED_EXPRESSION'"'
# Use yq to get the value, and then sed to update it
ORIGINAL_VALUE=$(yq e "$JSON_PATH" "$ABSOLUTE_FILE_PATH")
REPLACED_SED_EXPRESSION=$(echo "$SED_EXPRESSION" | sed "s/{{TAG}}/$NEW_TAG/g")
UPDATED_VALUE=$(echo "$ORIGINAL_VALUE" | sed "$REPLACED_SED_EXPRESSION")
yq e "$JSON_PATH = \"$UPDATED_VALUE\"" -i "$ABSOLUTE_FILE_PATH"
else
# Default handling for direct JSON paths
yq e "$JSON_PATH = \"$NEW_TAG\"" -i "$ABSOLUTE_FILE_PATH"
fi
echo
done
fi
}

0 comments on commit 36c0856

Please sign in to comment.