-
Notifications
You must be signed in to change notification settings - Fork 87
186 lines (165 loc) · 9.08 KB
/
chart-update.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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/yq@v4.44.6
- 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 "devopshelm@hazelcast.com"
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"