diff --git a/.github/workflows/bump-chart.yaml b/.github/workflows/bump-chart.yaml new file mode 100644 index 0000000..7b35e06 --- /dev/null +++ b/.github/workflows/bump-chart.yaml @@ -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 }} + \ No newline at end of file diff --git a/scripts/git.sh b/scripts/git.sh new file mode 100644 index 0000000..beb8909 --- /dev/null +++ b/scripts/git.sh @@ -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 +} \ No newline at end of file diff --git a/scripts/update_chart.sh b/scripts/update_chart.sh new file mode 100755 index 0000000..aa763df --- /dev/null +++ b/scripts/update_chart.sh @@ -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" \ No newline at end of file diff --git a/scripts/update_chart_instructions.yaml b/scripts/update_chart_instructions.yaml new file mode 100644 index 0000000..45cf5d2 --- /dev/null +++ b/scripts/update_chart_instructions.yaml @@ -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 \ No newline at end of file diff --git a/scripts/update_chart_references.sh b/scripts/update_chart_references.sh new file mode 100644 index 0000000..db1dc56 --- /dev/null +++ b/scripts/update_chart_references.sh @@ -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 +} \ No newline at end of file