-
Notifications
You must be signed in to change notification settings - Fork 0
222 lines (187 loc) · 9.5 KB
/
cluster-provider-test-pull-request.yaml
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
name: cluster-$provider test pull requests
on:
pull_request:
types: [opened, synchronize, reopened, closed]
jobs:
create-or-update-test-pull-request:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Git
run: |
git config --global user.email "[email protected]"
git config --global user.name "taylorbot"
- uses: oleksiyrudenko/[email protected]
with:
global: true
actor: 'taylorbot'
email: '[email protected]'
token: '${{ secrets.TAYLORBOT_GITHUB_ACTION }}'
- name: Clone cluster chart repository
run: |
git clone https://github.com/giantswarm/cluster.git
- name: Get cluster chart pull request details
id: cluster_chart_pr
env:
GITHUB_TOKEN: ${{ secrets.TAYLORBOT_GITHUB_ACTION }}
run: |
# Get pull request number
cluster_chart_pr_number="${{ github.event.issue.number }}"
if [ -z "$cluster_chart_pr_number" ]; then
cluster_chart_pr_number="${{ github.event.number }}"
fi
echo "Pull request number is $cluster_chart_pr_number."
echo "cluster_chart_pr_number=$cluster_chart_pr_number" >> $GITHUB_ENV
cluster_chart_pr_details=$(gh pr view $cluster_chart_pr_number --json "title,author,headRefName")
# Get pull request title
cluster_chart_pr_title=$(echo $cluster_chart_pr_details | jq -r '.title')
echo "cluster_chart_pr_title=$cluster_chart_pr_title" >> $GITHUB_ENV
# Get pull request author details
cluster_chart_pr_author_username=$(echo $cluster_chart_pr_details | jq -r '.author.login')
cluster_chart_pr_author_name=$(echo $cluster_chart_pr_details | jq -r '.author.name')
echo "cluster_chart_pr_author_username=$cluster_chart_pr_author_username" >> $GITHUB_ENV
echo "cluster_chart_pr_author_name=$cluster_chart_pr_author_name" >> $GITHUB_ENV
# Get pull request head branch name (the branch that has changes)
cluster_chart_pr_branch_name=$(echo $cluster_chart_pr_details | jq -r '.headRefName')
echo "cluster_chart_pr_branch_name=$cluster_chart_pr_branch_name" >> $GITHUB_ENV
- name: Get cluster chart custom version for the pull request
run: |
cd cluster
git fetch --tags
# get the latest tag and trim 'v' prefix
latest_release=$(git describe --tags $(git rev-list --tags --max-count=1))
latest_release="${latest_release#v}"
git checkout "${{ env.cluster_chart_pr_branch_name }}"
latest_commit_sha=$(git rev-parse --verify HEAD)
echo "Custom cluster chart version is $latest_release-$latest_commit_sha"
echo "custom_cluster_chart_new_version=$latest_release-$latest_commit_sha" >> $GITHUB_ENV
- name: Clone cluster-aws repository
run: |
git clone https://github.com/giantswarm/cluster-aws.git
- name: Check if branch exists in cluster-aws repo
id: check_branch
run: |
cd cluster-aws
# Check if branch exists
branch_name="test-cluster-chart-pr-${{ env.cluster_chart_pr_number }}"
echo "cluster_aws_branch_name=$branch_name" >> $GITHUB_ENV
repo_url="https://github.com/giantswarm/cluster-aws"
if git ls-remote --heads "$repo_url" | grep -q "refs/heads/$branch_name"; then
echo "Found that cluster-aws already has the branch $branch_name. Will update it if needed."
echo "branch_exists=true" >> $GITHUB_ENV
else
echo "Found that cluster-aws does not have the branch $branch_name. Will create it."
echo "branch_exists=false" >> $GITHUB_ENV
fi
- name: Create new cluster-aws branch
if: env.branch_exists == 'false'
run: |
cd cluster-aws
git checkout -b ${{ env.cluster_aws_branch_name }}
- name: Checkout existing cluster-aws branch
if: env.branch_exists == 'true'
run: |
cd cluster-aws
git checkout ${{ env.cluster_aws_branch_name }}
- name: Update cluster chart version in Chart.yaml
run: |
cd cluster-aws/helm/cluster-aws
current_version="$(yq e '.dependencies[] | select(.name == "cluster").version' Chart.yaml)"
echo "cluster_chart_current_version=$current_version" >> $GITHUB_ENV
new_version="${{ env.custom_cluster_chart_new_version }}"
if [ $new_version != $current_version ]; then
echo "Updating cluster chart version"
new_version="$new_version" yq e '.dependencies[] |= select(.name == "cluster") * {"version": strenv(new_version)}' -i Chart.yaml
yq e '.dependencies[] |= select(.name == "cluster") * {"repository": "https://giantswarm.github.io/cluster-test-catalog"}' -i Chart.yaml
echo -e "Updated cluster chart version. Chart.yaml content is now:\n---"
cat Chart.yaml
echo -e "---\n"
# Retry logic for helm dependency update
retry=0
max_retries=20
success=false
while [ $retry -lt $max_retries ]; do
if helm dependency update; then
success=true
break
else
retry=$((retry + 1))
echo "Retry $retry/$max_retries: helm dependency update failed, retrying in 15 seconds..."
sleep 15
fi
done
if [ "$success" = false ]; then
echo "helm dependency update failed after $max_retries retries"
exit 1
fi
echo "cluster_chart_version_updated=true" >> $GITHUB_ENV
else
echo "Cluster chart version is already up-to-date."
echo "cluster_chart_version_updated=false" >> $GITHUB_ENV
fi
- name: Commit and push changes
if: env.cluster_chart_version_updated == 'true'
run: |
cd cluster-aws
git add helm/cluster-aws/Chart.yaml
git add helm/cluster-aws/Chart.lock
git commit -m "Update cluster chart version to ${{ env.custom_cluster_chart_new_version }}"
git remote set-url origin https://${{ env.GITHUB_TOKEN }}@github.com/giantswarm/cluster-aws.git
git push origin ${{ env.cluster_aws_branch_name }}
env:
GITHUB_TOKEN: ${{ secrets.TAYLORBOT_GITHUB_ACTION }}
- name: Create a draft pull request
if: env.branch_exists == 'false'
run: |
title="Test cluster chart PR #${{ env.cluster_chart_pr_number }}"
body="> [!WARNING]"
body="$body\n> DO NOT MERGE! This PR has been created automatically by @taylorbot on behalf of ${{ env.cluster_chart_pr_author_name }} (@${{ env.cluster_chart_pr_author_username }})."
body="$body\n\n### Changes"
body="$body\n\nUpdate the cluster chart version from \`${{ env.cluster_chart_current_version }}\` to \`${{ env.custom_cluster_chart_new_version }}\` in order to test @${{ env.cluster_chart_pr_author_username }}'s cluster chart pull request https://github.com/giantswarm/cluster/pull/${{ env.cluster_chart_pr_number }}."
body="$body\n\nCluster chart pull request title: \`${{ env.cluster_chart_pr_title }}\`."
body="$body\n\n### Testing"
body="$body\n\nPlease comment this pull request with \`/run cluster-test-suites\` in order to run e2e tests."
# body="$body\n\n> [!NOTE]"
# body="$body\n> This PR will be closed automatically when the cluster chart PR is closed."
echo -e "$body" | gh pr create --repo giantswarm/cluster-aws \
--head ${{ env.cluster_aws_branch_name }} \
--title "$title" \
--draft \
--label testing \
--label do-not-merge/hold \
--body-file -
cluster_aws_pr_number=$(gh pr list --repo giantswarm/cluster-aws --head ${{ env.cluster_aws_branch_name }} --json number | jq ".[0].number")
cluster_chart_comment="Hey @${{ env.cluster_chart_pr_author_username }}, a test pull request has been created for you in the cluster-aws repo! Go to pull request https://github.com/giantswarm/cluster-aws/pull/$cluster_aws_pr_number in order to test your cluster chart changes on AWS."
echo -e "$cluster_chart_comment" | gh pr comment \
--repo giantswarm/cluster \
--body "$cluster_chart_comment" \
${{ env.cluster_chart_pr_number }}
env:
GITHUB_TOKEN: ${{ secrets.TAYLORBOT_GITHUB_ACTION }}
close-cluster-aws-pr:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Get cluster chart pull request number
env:
GITHUB_TOKEN: ${{ secrets.TAYLORBOT_GITHUB_ACTION }}
run: |
# Get pull request number
cluster_chart_pr_number="${{ github.event.issue.number }}"
if [ -z "$cluster_chart_pr_number" ]; then
cluster_chart_pr_number="${{ github.event.number }}"
fi
echo "Pull request number is $cluster_chart_pr_number."
echo "cluster_chart_pr_number=$cluster_chart_pr_number" >> $GITHUB_ENV
- name: Close cluster-aws pull requests
env:
GITHUB_TOKEN: ${{ secrets.TAYLORBOT_GITHUB_ACTION }}
run: |
gh pr list --repo giantswarm/cluster-aws --head test-cluster-chart-pr-${{ env.cluster_chart_pr_number }} --json number --jq '.[].number' | while read pr_number; do
gh pr close $pr_number \
--repo giantswarm/cluster-aws \
--comment "Closing this pull request after closing/merging cluster chart pull request." \
--delete-branch
done