Skip to content

Chart Version Update #566

Chart Version Update

Chart Version Update #566

Workflow file for this run

name: Chart Version Update
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
chart-update:
runs-on: ubuntu-latest
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Get Secrets
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
DEVOPS_GITHUB_TOKEN,CN/DEVOPS_GITHUB_TOKEN
- name: Delete Old Workflow Run
run: |
echo ${{ env.DEVOPS_GITHUB_TOKEN }} | gh auth login --with-token
WORKFLOW_ID=$(gh api repos/${GITHUB_REPOSITORY}/actions/workflows | jq '.workflows[] | select(.["name"] | contains("Chart Version Update")) | .id')
RUN_ID=$(gh api repos/${GITHUB_REPOSITORY}/actions/workflows/${WORKFLOW_ID}/runs --paginate | jq '.workflow_runs[] | select(.["status"] | contains("completed")) | select(.head_commit.message) | .id')
if [[ -n "$RUN_ID" ]]; then
gh api repos/${GITHUB_REPOSITORY}/actions/runs/$RUN_ID -X DELETE >/dev/null
fi
- name: Install yq
uses: mikefarah/[email protected]
- name: Checkout code
uses: actions/checkout@v4
- name: Update Charts
working-directory: stable
id: update_version
run: |
echo ${{ env.DEVOPS_GITHUB_TOKEN }} | gh auth login --with-token
HZ_REPO="hazelcast/hazelcast-mono"
MC_REPO="hazelcast/management-center"
paths=("hazelcast-enterprise")
# Function to extract a specific field value from a YAML file
extract_version() {
local FIELD="$1"
local FILENAME="$2"
VERSION=$(yq eval $FIELD "$FILENAME")
echo "$VERSION"
}
# Function to get the latest Git tag from the specified repository
get_latest_tag() {
echo ${{ env.DEVOPS_GITHUB_TOKEN }} | gh auth login --with-token
local LATEST_TAG=$(gh api repos/$1/git/matching-refs/tags --jq '.[].ref | select(test("^refs/tags/v[0-9]+\\.[0-9]+\\.[0-9]+$")) | sub("^refs/tags/v"; "")' | sort -V | tail -n1)
echo "$LATEST_TAG"
}
# Function to extract major, minor, and patch parts from a version string
extract_version_parts() {
local VERSION="${1#v}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
echo "$MAJOR,$MINOR,$PATCH"
}
# Function to increment a version part
increment_version() {
local PART_VALUE=$1
((PART_VALUE++))
echo "$PART_VALUE"
}
# Function to update the chart version based on the latest tag and app version
update_version() {
local LATEST_TAG="$1"
local APP_VERSION="$2"
local CHART_VERSION="$3"
# Extract version parts from the latest tag, app version, and chart version
IFS=',' read -r LATEST_MAJOR LATEST_MINOR LATEST_PATCH <<< "$(extract_version_parts "$LATEST_TAG")"
IFS=',' read -r APP_MAJOR APP_MINOR APP_PATCH <<< "$(extract_version_parts "$APP_VERSION")"
IFS=',' read -r CHART_MAJOR CHART_MINOR CHART_PATCH <<< "$(extract_version_parts "$CHART_VERSION")"
# Compare the version parts and update the chart version if necessary
if [[ $LATEST_MAJOR != $APP_MAJOR ]]; then
CHART_MINOR=0
CHART_PATCH=0
CHART_MAJOR=$(increment_version "$CHART_MAJOR")
elif [[ $LATEST_MINOR != $APP_MINOR ]]; then
CHART_MINOR=$(increment_version "$CHART_MINOR")
CHART_PATCH=0
elif [[ $LATEST_PATCH != $APP_PATCH ]]; then
CHART_PATCH=$(increment_version "$CHART_PATCH")
fi
echo "$CHART_MAJOR.$CHART_MINOR.$CHART_PATCH"
}
# Function to check the version and update the chart files if necessary
check_version_and_update() {
HZ_LATEST_TAG=$(get_latest_tag "$HZ_REPO")
MC_LATEST_TAG=$(get_latest_tag "$MC_REPO")
for path in "${paths[@]}"; do
APP_VERSION=$(extract_version .appVersion "$path/Chart.yaml")
CHART_VERSION=$(extract_version .version "$path/Chart.yaml")
MC_VERSION=$(extract_version .mancenter.image.tag "$path/values.yaml")
echo "HZ_LATEST_TAG=${HZ_LATEST_TAG}" >> $GITHUB_ENV
echo "MC_LATEST_TAG=${MC_LATEST_TAG}" >> $GITHUB_ENV
if [[ $HZ_LATEST_TAG != $APP_VERSION && $MC_LATEST_TAG != $MC_VERSION ]]; then
NEW_CHART_VERSION=$(update_version "$HZ_LATEST_TAG" "$APP_VERSION" "$CHART_VERSION")
sed -i -E -e 's/(version: ).*/\1'"$NEW_CHART_VERSION"'/' -e 's/(appVersion: ).*/\1'\"$HZ_LATEST_TAG\"'/' "$path/Chart.yaml"
awk '/^image:/ {p=1} p && /tag:/ {sub(/tag:.*/, "tag: \"'$HZ_LATEST_TAG'\""); p=0} 1' "$path/values.yaml" > temp.yaml && mv temp.yaml "$path/values.yaml"
awk '/^mancenter:/ {p=1} p && /tag:/ {sub(/tag:.*/, "tag: \"'$MC_LATEST_TAG'\""); p=0} 1' "$path/values.yaml" > temp.yaml && mv temp.yaml "$path/values.yaml"
echo "HZ_UPDATED=true" >> $GITHUB_OUTPUT
echo "HZ_UPDATED=true" >> $GITHUB_ENV
echo "MC_UPDATED=true" >> $GITHUB_OUTPUT
echo "MC_UPDATED=true" >> $GITHUB_ENV
elif [[ $HZ_LATEST_TAG != $APP_VERSION && $MC_LATEST_TAG == $MC_VERSION ]]; then
NEW_CHART_VERSION=$(update_version "$HZ_LATEST_TAG" "$APP_VERSION" "$CHART_VERSION")
sed -i -E -e 's/(version: ).*/\1'"$NEW_CHART_VERSION"'/' -e 's/(appVersion: ).*/\1'\"$HZ_LATEST_TAG\"'/' "$path/Chart.yaml"
awk '/^image:/ {p=1} p && /tag:/ {sub(/tag:.*/, "tag: \"'$HZ_LATEST_TAG'\""); p=0} 1' "$path/values.yaml" > temp.yaml && mv temp.yaml "$path/values.yaml"
echo "HZ_UPDATED=true" >> $GITHUB_OUTPUT
echo "HZ_UPDATED=true" >> $GITHUB_ENV
elif [[ $HZ_LATEST_TAG == $APP_VERSION && $MC_LATEST_TAG != $MC_VERSION ]]; then
NEW_CHART_VERSION=$(update_version "$MC_LATEST_TAG" "$MC_VERSION" "$CHART_VERSION")
sed -i -E -e 's/(version: ).*/\1'"$NEW_CHART_VERSION"'/' "$path/Chart.yaml"
awk '/^mancenter:/ {p=1} p && /tag:/ {sub(/tag:.*/, "tag: \"'$MC_LATEST_TAG'\""); p=0} 1' "$path/values.yaml" > temp.yaml && mv temp.yaml "$path/values.yaml"
echo "MC_UPDATED=true" >> $GITHUB_OUTPUT
echo "MC_UPDATED=true" >> $GITHUB_ENV
else
echo "No new tag found for HZ in '$path' path. The latest tag is: $HZ_LATEST_TAG"
echo "No new tag found for MC in '$path' path. The latest tag is: $MC_LATEST_TAG"
fi
done
}
check_version_and_update
- name: Generate Branch Name and PR Title
id: title
if: (steps.update_version.outputs.HZ_UPDATED == 'true' || steps.update_version.outputs.MC_UPDATED == 'true')
run: |
if [[ $HZ_UPDATED == 'true' && $MC_UPDATED != 'true' ]]; then
TITLE="Upgrade Hazelcast version to ${{ env.HZ_LATEST_TAG }}"
BRANCH="update-hz-to-${{ env.HZ_LATEST_TAG }}"
elif [[ $HZ_UPDATED != 'true' && $MC_UPDATED == 'true' ]]; then
TITLE="Upgrade MC version to ${{ env.MC_LATEST_TAG }}"
BRANCH="update-mc-to-${{ env.MC_LATEST_TAG }}"
else
TITLE="Upgrade Hazelcast and MC version to ${{ env.HZ_LATEST_TAG }} and ${{ env.MC_LATEST_TAG }}"
BRANCH="update-hz-mc-to-${{ env.HZ_LATEST_TAG }}-${{ env.MC_LATEST_TAG }}"
fi
echo "TITLE=$TITLE" >> $GITHUB_ENV
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
PR_NUMBER=$(gh pr list --repo ${GITHUB_REPOSITORY} --search "$TITLE" --json number | jq -r '.[].number')
if [[ -z "$PR_NUMBER" ]]; then
echo "PR_EXIST=false" >> $GITHUB_OUTPUT
echo "PR_EXIST=false" >> $GITHUB_ENV
fi
- name: Commit and Push Changes
if: (steps.update_version.outputs.HZ_UPDATED == 'true' || steps.update_version.outputs.MC_UPDATED == 'true') && steps.title.outputs.PR_EXIST == 'false'
run: |
git config user.email "[email protected]"
git config user.name "devOpsHelm"
git fetch origin
git checkout master
git pull origin master
git checkout -b ${{ env.BRANCH }}
git add .
git commit --signoff -m "${{ env.TITLE }}"
git push -u origin ${{ env.BRANCH }}
- name: Create PR to Main Branch
if: (steps.update_version.outputs.HZ_UPDATED == 'true' || steps.update_version.outputs.MC_UPDATED == 'true') && steps.title.outputs.PR_EXIST == 'false'
run: |
echo ${{ env.DEVOPS_GITHUB_TOKEN }} | gh auth login --with-token
gh pr create --fill \
--label "safe-to-test" \
--reviewer "hasancelik,cheels"