-
Notifications
You must be signed in to change notification settings - Fork 5
629 lines (595 loc) · 28.5 KB
/
entando-release.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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
name: Entando Release
on:
repository_dispatch:
types: [entando-release]
env:
# URL of the DockerHub repositories configuration file
DOCKER_HUB_REPOS_CONFIG_URL: global-config/docker-hub-repositories.json
# catalyst-infra-templates namespace and repository
CATALYST_INFRA_TEMPLATES_REPO: entando/catalyst-infra-templates
# entando-k8s-operator-bundle namespace and repository
ENTANDO_K8S_OPERATOR_BUNDLE_REPO: entando-k8s/entando-k8s-operator-bundle
# entando-releases namespace and repository
ENTANDO_RELEASES_REPO: entando/entando-releases
# The user name to be associated with the commit
COMMIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
# The user email address to be associated with the commit
COMMIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
# The user token to be associated with the commit
COMMIT_USER_TOKEN: ${{ secrets.ENTANDO_BOT_TOKEN }}
# Major release version specified in the repository_dispatch payload
MAJOR: ${{ github.event.client_payload.major }}
# Minor release version specified in the repository_dispatch payload
MINOR: ${{ github.event.client_payload.minor }}
# Patch release version specified in the repository_dispatch payload
PATCH: ${{ github.event.client_payload.patch }}
# Suffix release version specified in the repository_dispatch payload
SUFFIX: ${{ github.event.client_payload.suffix }}
# Auxiliary variables that are created based in the repository_dispatch payload
# Release version. Example: 7.1
RELEASE_VERSION: ${{ github.event.client_payload.major }}.${{ github.event.client_payload.minor }}
# Release branch. Example: release/7.1
RELEASE_BRANCH: release/${{ github.event.client_payload.major }}.${{ github.event.client_payload.minor }}
# Release version with patch. Example: 7.1.4
RELEASE_VERSION_PATCH: ${{ github.event.client_payload.major }}.${{ github.event.client_payload.minor }}.${{ github.event.client_payload.patch }}
# Release version with patch. Example: 7.1.4-rc2
RELEASE_VERSION_SUFFIX: ${{ github.event.client_payload.major }}.${{ github.event.client_payload.minor }}.${{ github.event.client_payload.patch }}${{ github.event.client_payload.suffix }}
# Release tag. Example: v7.1.4-rc2
RELEASE_TAG: v${{ github.event.client_payload.major }}.${{ github.event.client_payload.minor }}.${{ github.event.client_payload.patch }}${{ github.event.client_payload.suffix }}
jobs:
setup:
runs-on: ubuntu-latest
outputs:
entando_k8s_operator_release_branch_exists: ${{ steps.entando-k8s-operator-release-branch.outputs.entando-k8s-operator-exists }}
entando_releases_release_branch_exists: ${{ steps.entando-releases-release-branch.outputs.entando-releases-exists }}
steps:
- name: Checkout entando-k8s-operator-bundle
uses: actions/checkout@v3
with:
repository: ${{ env.ENTANDO_K8S_OPERATOR_BUNDLE_REPO }}
ref: develop
token: ${{ secrets.ENTANDO_BOT_TOKEN }}
fetch-depth: 0
- name: entando-k8s-operator ${{ env.RELEASE_BRANCH }} branch exists?
id: entando-k8s-operator-release-branch
run: |
echo "entando-k8s-operator-exists=$(git ls-remote --heads origin ${{ env.RELEASE_BRANCH }})" >> $GITHUB_OUTPUT
- name: Checkout entando-releases
uses: actions/checkout@v3
with:
repository: ${{ env.ENTANDO_RELEASES_REPO }}
ref: develop
token: ${{ secrets.ENTANDO_BOT_TOKEN }}
fetch-depth: 0
- name: entando-releases ${{ env.RELEASE_BRANCH }} branch exists?
id: entando-releases-release-branch
run: |
echo "entando-releases-exists=$(git ls-remote --heads origin ${{ env.RELEASE_BRANCH }})" >> $GITHUB_OUTPUT
release-entando-k8s-operator-bundle:
name: Release operator-bundle
runs-on: ubuntu-latest
needs: setup
steps:
# Validate client payload
- name: Validate client payload
run: |
# Check if mandatory fields are present
if [[ -z "${{ env.MAJOR }}" ]]
then
echo "::error :: Mandatory field 'major' not found in client_paylod"
exit 1
fi
if [[ -z "${{ env.MINOR }}" ]]
then
echo "::error :: Mandatory field 'minor' not found in client_paylod"
exit 2
fi
if [[ -z "${{ env.PATCH }}" ]]
then
echo "::error :: Mandatory field 'patch' not found in client_paylod"
exit 3
fi
# Checkout the catalyst-infra-templates repository
- name: Checkout catalyst-infra-templates
uses: actions/checkout@v3
with:
repository: ${{ env.CATALYST_INFRA_TEMPLATES_REPO }}
token: ${{ secrets.ENTANDO_BOT_TOKEN }}
# Load Docker Hub repositories configuration
- name: Load Docker Hub repositories
run: |
echo "DOCKER_HUB_REPOS=$(jq -c . < $DOCKER_HUB_REPOS_CONFIG_URL)" >> $GITHUB_ENV
- name: Checkout entando-k8s-operator-bundle to create ${{ env.RELEASE_BRANCH }}
uses: actions/checkout@v3
if: ${{ needs.setup.outputs.entando_k8s_operator_release_branch_exists == '' }}
with:
repository: ${{ env.ENTANDO_K8S_OPERATOR_BUNDLE_REPO }}
ref: develop
token: ${{ secrets.ENTANDO_BOT_TOKEN }}
fetch-depth: 0
- name: Create release branch ${{ env.RELEASE_BRANCH }}
if: ${{ needs.setup.outputs.entando_k8s_operator_release_branch_exists == '' }}
run: |
git checkout -b ${{ env.RELEASE_BRANCH }}
git push origin ${{ env.RELEASE_BRANCH }}
# Checkout the entando-k8s-operator-bundle repository
- name: Checkout entando-k8s-operator-bundle ${{ env.RELEASE_BRANCH }}
uses: actions/checkout@v3
with:
repository: ${{ env.ENTANDO_K8S_OPERATOR_BUNDLE_REPO }}
ref: ${{ env.RELEASE_BRANCH }}
token: ${{ secrets.ENTANDO_BOT_TOKEN }}
fetch-depth: 0
# Validate the release tag
- name: Validate release tag
run: |
# Check if the release tag already exists
if [[ $(git tag -l $RELEASE_TAG) ]]
then
echo "::error :: Tag '$RELEASE_TAG' already exists"
exit 4
fi
# Installing crane
- name: Installing crane
uses: imjasonh/[email protected]
# Update images versions and SHA digests in the values.yaml file
- name: Set images versions and sha
env:
# Convert the client_payload JSON object to a string and set it as an environment variable
CLIENT_PAYLOAD: ${{ toJson(github.event.client_payload) }}
run: |
for IMAGE in $(echo "$CLIENT_PAYLOAD" | jq -c '.images[]'); do
IMAGE_NAME=$(echo $IMAGE | jq -r '.name')
NEW_VERSION=$(echo $IMAGE | jq -r '.version')
FOUND_IMAGE=false
for DOCKER_HUB_REPO in $(echo "$DOCKER_HUB_REPOS" | jq -c '.images[]'); do
REPO_NAME=$(echo $DOCKER_HUB_REPO | jq -r '.name')
REPO_NAMESPACE=$(echo $DOCKER_HUB_REPO | jq -r '.docker_hub_namespace')
REPO=$(echo $DOCKER_HUB_REPO | jq -r '.docker_hub_repository')
if [[ $IMAGE_NAME == $REPO_NAME ]]
then
FOUND_IMAGE=true
NEW_DIGEST="$(crane digest ${REPO_NAMESPACE}/${REPO}:${NEW_VERSION})"
NEW_DIGEST=${NEW_DIGEST//sha256:/}
echo "This is the digest: ${NEW_DIGEST}"
ORIGINAL_VERSION=$(yq ".operator.relatedImages.$IMAGE_NAME.version" values.yaml)
ORIGINAL_SHA=$(yq ".operator.relatedImages.$IMAGE_NAME.sha256" values.yaml)
yq -i ".operator.relatedImages.$IMAGE_NAME.version = \"$NEW_VERSION\"" values.yaml
yq -i ".operator.relatedImages.$IMAGE_NAME.sha256 = \"$NEW_DIGEST\"" values.yaml
# Print the original and updated version and SHA digest of the Docker image
echo "Updating values.yaml"
echo "Image name: $IMAGE_NAME"
echo 'Original data: version="'$ORIGINAL_VERSION'", sha="'$ORIGINAL_SHA'"'
echo 'New data: version="'$NEW_VERSION'", sha='$NEW_DIGEST
echo ""
fi
done
# If the Docker image doesn't exist in the Docker Hub repositories configuration, exit with an error
if [[ $FOUND_IMAGE = false ]]
then
echo "::error :: Image '$IMAGE_NAME' does not exist in '$DOCKER_HUB_REPOS_CONFIG_URL'"
exit 6
fi
done
# Generating kustomization files for K8S and OCP environments
- name: Kustomization templates generation
run: |
DOCKER_REGISTRY="registry.hub.docker.com/entando"
IMAGE_KEYS=$(cat values.yaml | yq '.operator.relatedImages | keys' | tr -d '-' | tr -d '[:blank:]')
# insert a controller to do not print the image if the release is old
SKIP_PRINT=false
# Define paths to store the kustomization files
K8S_K="plain-templates/misc/kustomization-K8S.yaml"
OCP_K="plain-templates/misc/kustomization-OCP.yaml"
# Delete old generated files
rm -f "$K8S_K"
rm -f "$OCP_K"
for key in $IMAGE_KEYS; do
version=$(yq ".operator.relatedImages.$key.version" values.yaml)
digest_sha256=$(yq ".operator.relatedImages.$key.sha256" values.yaml)
case $key in
rhel8_mysql_80)
key="entando-mysql-ubi"
SKIP_PRINT=false
;;
rhel8_postgresql_12)
key="entando-postgres-ubi"
SKIP_PRINT=false
;;
app_builder_6_3)
key="app-builder"
SKIP_PRINT=true
;;
app_builder_6_4)
key="app-builder"
SKIP_PRINT=false
;;
busybox)
key="busybox"
SKIP_PRINT=false
;;
entando_avatar_plugin)
key="entando-avatar-plugin"
SKIP_PRINT=false
;;
entando_component_manager_6_3)
key="entando-component-manager"
SKIP_PRINT=true
;;
entando_component_manager_6_4)
key="entando-component-manager"
SKIP_PRINT=false
;;
entando_de_app_eap_6_3)
key="entando-de-app-eap"
SKIP_PRINT=true
;;
entando_de_app_eap_6_4)
key="entando-de-app-eap"
SKIP_PRINT=false
;;
entando_de_app_wildfly_6_3)
key="entando-de-app-wildfly"
SKIP_PRINT=true
;;
entando_de_app_wildfly_6_4)
key="entando-de-app-wildfly"
SKIP_PRINT=false
;;
entando_de_app_tomcat_6_4)
key="entando-de-app-tomcat"
SKIP_PRINT=false
;;
entando_k8s_app_controller)
key="entando-k8s-app-controller"
SKIP_PRINT=false
;;
entando_k8s_app_plugin_link_controller)
key="entando-k8s-app-plugin-link-controller"
SKIP_PRINT=false
;;
entando_k8s_cluster_infrastructure_controller)
key="entando-k8s-cluster-infrastructure-controller"
SKIP_PRINT=false
;;
entando_k8s_composite_app_controller)
key="entando-k8s-composite-app-controller"
SKIP_PRINT=false
;;
entando_k8s_controller_coordinator)
key="entando-k8s-controller-coordinator"
SKIP_PRINT=false
;;
entando_k8s_database_service_controller)
key="entando-k8s-database-service-controller"
SKIP_PRINT=false
;;
entando_k8s_dbjob)
key="entando-k8s-dbjob"
SKIP_PRINT=false
;;
entando_k8s_keycloak_controller)
key="entando-k8s-keycloak-controller"
SKIP_PRINT=false
;;
entando_k8s_plugin_controller)
key="entando-k8s-plugin-controller"
SKIP_PRINT=false
;;
entando_k8s_service)
key="entando-k8s-service"
SKIP_PRINT=false
;;
entando_process_driven_plugin)
key="entando-process-driven-plugin"
SKIP_PRINT=false
;;
entando_keycloak)
key="entando-keycloak"
SKIP_PRINT=false
;;
entando_redhat_sso)
key="entando-redhat-sso"
SKIP_PRINT=false
;;
mysql_80_centos7)
key="entando-mysql-rocky"
SKIP_PRINT=false
;;
postgresql_12_centos7)
key="entando-postgres-rocky"
SKIP_PRINT=false
;;
esac
if [ $SKIP_PRINT ]; then
echo "skiping... too old."
fi
if [ $SKIP_PRINT == false ]; then
printf -- "- name: %s/%s\n newName: %s/%s\n newTag: %s\n" "$DOCKER_REGISTRY" "$key" "$DOCKER_REGISTRY" "$key" "$version" >>"$K8S_K"
printf -- "- name: %s/%s\n newName: %s/%s\n digest: sha256:%s\n" "$DOCKER_REGISTRY" "$key" "$DOCKER_REGISTRY" "$key" "$digest_sha256" >>"$OCP_K"
fi
done
# Generating manifest files
- name: Run generate-manifest.sh
run: |
bash ./generate-manifests.sh --version "${{ env.RELEASE_VERSION_PATCH }}" --mainline "${{ env.RELEASE_VERSION }}"
# Commit updated values.yaml and manifest files
- name: Commit updated values.yaml and manifest files
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_user_name: ${{ env.COMMIT_USER_NAME }}
commit_user_email: ${{ env.COMMIT_USER_EMAIL }}
commit_message: Automated entando-k8s-operator-bundle update
# Tag entando-k8s-operator-bundle
- name: Tag entando-k8s-operator-bundle ${{ env.RELEASE_TAG }}
run: |
git tag ${{ env.RELEASE_TAG }} ${{ env.RELEASE_BRANCH }}
git push origin ${{ env.RELEASE_TAG }}
# Release entando-k8s-operator-bundle
- name: Release entando-k8s-operator-bundle ${{ env.RELEASE_TAG }}
run: |
curl \
-X GET \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.ENTANDO_BOT_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ env.ENTANDO_K8S_OPERATOR_BUNDLE_REPO }}/releases/latest > releases.json
LATEST_TAG_NAME=$(jq .tag_name releases.json)
echo "The current entando-k8s-operator-bundle latest tag is = $LATEST_TAG_NAME"
VERSION_REGEX='^([0-9]+).([0-9]+).([0-9]+)$'
CURRENT_LATEST_VERSION=${LATEST_TAG_NAME:2:-1}
echo "CURRENT_LATEST_VERSION = $CURRENT_LATEST_VERSION"
if [[ $CURRENT_LATEST_VERSION =~ $VERSION_REGEX ]]; then
current_major=${BASH_REMATCH[1]}
current_minor=${BASH_REMATCH[2]}
current_patch=${BASH_REMATCH[3]}
echo "current_major = $current_major, current_minor = $current_minor, current_patch = $current_patch"
else
echo "CURRENT_LATEST_VERSION = $CURRENT_LATEST_VERSION did not match regex"
fi
MAKE_LATEST=false
if [[ ${{ env.RELEASE_VERSION_SUFFIX }} =~ $VERSION_REGEX ]]; then
new_major=${BASH_REMATCH[1]}
new_minor=${BASH_REMATCH[2]}
new_patch=${BASH_REMATCH[3]}
echo "new_major = $new_major, new_minor = $new_minor, new_patch = $new_patch"
if [[ $new_major -gt $current_major ]] ||
[[ $new_major -eq $current_major && $new_minor -gt $current_minor ]] ||
[[ $new_major -eq $current_major && $new_minor -eq $current_minor && $new_patch -gt $current_patch ]]; then
MAKE_LATEST=true
else
echo "RELEASE_VERSION_SUFFIX = ${{ env.RELEASE_VERSION_SUFFIX }} was not considered the latest"
fi
else
echo "RELEASE_VERSION_SUFFIX = ${{ env.RELEASE_VERSION_SUFFIX }} did not match regex"
fi
echo "MAKE_LATEST = $MAKE_LATEST"
PAYLOAD='{"tag_name":"${{ env.RELEASE_TAG }}","target_commitish":"${{ env.RELEASE_BRANCH }}","name":"${{ env.RELEASE_TAG }}","body":"${{ env.RELEASE_TAG }} release","draft":false,"prerelease":false,"generate_release_notes":true,"make_latest":"'$MAKE_LATEST\"}
echo $PAYLOAD
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.ENTANDO_BOT_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ env.ENTANDO_K8S_OPERATOR_BUNDLE_REPO }}/releases \
-d "$PAYLOAD"
release-entando-releases-bundle:
name: Release entando-releases
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [setup, release-entando-k8s-operator-bundle]
steps:
- name: Checkout entando-releases to create ${{ env.RELEASE_BRANCH }}
uses: actions/checkout@v3
if: ${{ needs.setup.outputs.entando_releases_release_branch_exists == '' }}
with:
repository: ${{ env.ENTANDO_RELEASES_REPO }}
ref: develop
token: ${{ secrets.ENTANDO_BOT_TOKEN }}
fetch-depth: 0
- name: Create release branch ${{ env.RELEASE_BRANCH }}
if: ${{ needs.setup.outputs.entando_releases_release_branch_exists == '' }}
run: |
git checkout -b ${{ env.RELEASE_BRANCH }}
git push origin ${{ env.RELEASE_BRANCH }}
# Checkout the entando-releases repository
- name: Checkout entando-releases ${{ env.RELEASE_BRANCH }}
uses: actions/checkout@v3
with:
repository: ${{ env.ENTANDO_RELEASES_REPO }}
ref: ${{ env.RELEASE_BRANCH }}
token: ${{ secrets.ENTANDO_BOT_TOKEN }}
fetch-depth: 0
# Validate the release tag
- name: Validate release tag
run: |
# Check if the release tag already exists
if [[ $(git tag -l $RELEASE_TAG) ]]
then
echo "::error :: Tag '$RELEASE_TAG' already exists"
exit 7
fi
# Installing crane
- name: Installing crane
uses: imjasonh/[email protected]
# Update the manifest file
- name: Update manifest file
env:
# Convert the client_payload JSON object to a string and set it as an environment variable
CLIENT_PAYLOAD: ${{ toJson(github.event.client_payload) }}
run: |
sed -i "s|ENTANDO_RELEASE=.*|ENTANDO_RELEASE=\"${{ env.RELEASE_TAG }}\"|" manifest
sed -i "s|OPERATOR_BUNDLE_VERSION=.*|OPERATOR_BUNDLE_VERSION=\"${{ env.RELEASE_TAG }}\"|" manifest
while true; do
BASE_URL="https://hub.docker.com/v2/namespaces/entandobuilduser/repositories/entando-k8s-index/tags?name="${{ env.RELEASE_VERSION_SUFFIX }}"&page_size=1000"
echo "Querying docker hub: $BASE_URL"
curl -X GET $BASE_URL > result.json
cat result.json
COUNT=$(jq .count result.json)
# Check if the Docker image version exists on Docker Hub
if [[ $COUNT > 0 ]]
then
for ((i=0;i<COUNT;i++)); do
DOCKER_HUB_VERSION=$(jq .results[$i].name result.json)
if [[ \"${{ env.RELEASE_VERSION_SUFFIX }}\" == $DOCKER_HUB_VERSION ]]
then
DIGEST="$(crane digest entandobuilduser/entando-k8s-index:${{ env.RELEASE_VERSION_SUFFIX }})"
echo "This is the digest: ${DIGEST}"
sed -i "s|OKD_CATALOG_IMAGE=.*|OKD_CATALOG_IMAGE=\"registry.hub.docker.com/entandobuilduser/entando-k8s-index@${DIGEST}\"|" manifest
CATALOG_SHA_UPDATED=true
fi
done
fi
if [[ $CATALOG_SHA_UPDATED = true ]]
then
echo "OKD_CATALOG_IMAGE value updated to '${DIGEST}'. Exiting"
rm result.json
break
else
echo "Waiting for entando-k8s-index to release the version ${{ env.RELEASE_VERSION_SUFFIX }}. It takes around 1 minute. Waiting 20 seconds."
sleep 20
fi
done
for PROPERTY in $(echo $CLIENT_PAYLOAD | jq -c '.properties[]'); do
PROPERTY_NAME=$(echo $PROPERTY | jq -r '.name')
PROPERTY_VALUE=$(echo $PROPERTY | jq -r '.value')
sed -i "s|${PROPERTY_NAME}=.*|${PROPERTY_NAME}=\"${PROPERTY_VALUE}\"|" manifest
done
# Generating manifest files
- name: Run build.sh
run: |
bash ./build.sh
# Commit the changes made by build.sh
- name: Commit changes made by build.sh
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_user_name: ${{ env.COMMIT_USER_NAME }}
commit_user_email: ${{ env.COMMIT_USER_EMAIL }}
commit_message: Automated entando-releases update
# Tag and release entando-releases
- name: Tag and release entando-releases ${{ env.RELEASE_TAG }}
run: |
curl \
-X GET \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.ENTANDO_BOT_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ env.ENTANDO_RELEASES_REPO }}/releases/latest > releases.json
LATEST_TAG_NAME=$(jq .tag_name releases.json)
echo "The current entando-releases latest tag is = $LATEST_TAG_NAME"
VERSION_REGEX='^([0-9]+).([0-9]+).([0-9]+)$'
CURRENT_LATEST_VERSION=${LATEST_TAG_NAME:2:-1}
echo "CURRENT_LATEST_VERSION = $CURRENT_LATEST_VERSION"
if [[ $CURRENT_LATEST_VERSION =~ $VERSION_REGEX ]]; then
current_major=${BASH_REMATCH[1]}
current_minor=${BASH_REMATCH[2]}
current_patch=${BASH_REMATCH[3]}
echo "current_major = $current_major, current_minor = $current_minor, current_patch = $current_patch"
else
echo "CURRENT_LATEST_VERSION = $CURRENT_LATEST_VERSION did not match regex"
fi
MAKE_LATEST=false
if [[ ${{ env.RELEASE_VERSION_SUFFIX }} =~ $VERSION_REGEX ]]; then
new_major=${BASH_REMATCH[1]}
new_minor=${BASH_REMATCH[2]}
new_patch=${BASH_REMATCH[3]}
echo "new_major = $new_major, new_minor = $new_minor, new_patch = $new_patch"
if [[ $new_major -gt $current_major ]] ||
[[ $new_major -eq $current_major && $new_minor -gt $current_minor ]] ||
[[ $new_major -eq $current_major && $new_minor -eq $current_minor && $new_patch -gt $current_patch ]]; then
MAKE_LATEST=true
else
echo "RELEASE_VERSION_SUFFIX = ${{ env.RELEASE_VERSION_SUFFIX }} was not considered the latest"
fi
else
echo "RELEASE_VERSION_SUFFIX = ${{ env.RELEASE_VERSION_SUFFIX }} did not match regex"
fi
echo "MAKE_LATEST = $MAKE_LATEST"
PAYLOAD='{"tag_name":"${{ env.RELEASE_TAG }}","target_commitish":"${{ env.RELEASE_BRANCH }}","name":"${{ env.RELEASE_TAG }}","body":"${{ env.RELEASE_TAG }} release","draft":false,"prerelease":false,"generate_release_notes":true,"make_latest":"'$MAKE_LATEST\"}
echo $PAYLOAD
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.ENTANDO_BOT_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ env.ENTANDO_RELEASES_REPO }}/releases \
-d "$PAYLOAD"
# Recreate quickstart tag and release
- name: Recreate quickstart tag and release
run: |
if [[ -z "${{ env.SUFFIX }}" ]]
then
while true; do
curl \
-X GET \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.ENTANDO_BOT_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ env.ENTANDO_RELEASES_REPO }}/releases?per_page=50 > releases.json
COUNT=$(jq length releases.json)
TAG_FOUND=false
for ((i=0;i<COUNT;i++)); do
RELEASE_TAG_NAME=$(jq .[$i].tag_name releases.json)
echo "Comparing $RELEASE_TAG_NAME with \"${{ env.RELEASE_TAG }}\""
if [[ $RELEASE_TAG_NAME == \"${{ env.RELEASE_TAG }}\" ]]
then
TAG_FOUND=true
break
fi
done
if [[ $TAG_FOUND = false ]]
then
echo "Waiting for entando-releases release to be done. It takes around 15 seconds. Waiting 5 seconds."
sleep 5
continue
else
echo "Exiting"
break
fi
done
curl \
-X GET \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.ENTANDO_BOT_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ env.ENTANDO_RELEASES_REPO }}/releases/latest > releases.json
LATEST_TAG_NAME=$(jq .tag_name releases.json)
echo "Comparing $LATEST_TAG_NAME with \"${{ env.RELEASE_TAG }}\""
if [[ $LATEST_TAG_NAME == \"${{ env.RELEASE_TAG }}\" ]]
then
curl \
-X GET \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.ENTANDO_BOT_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ env.ENTANDO_RELEASES_REPO }}/releases?per_page=10 > releases.json
COUNT=$(jq length releases.json)
for ((i=0;i<COUNT;i++)); do
RELEASE_TAG_NAME=$(jq .[$i].tag_name releases.json)
if [[ $RELEASE_TAG_NAME == \"quickstart\" ]]
then
RELEASE_ID=$(jq .[$i].id releases.json)
curl \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.ENTANDO_BOT_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ env.ENTANDO_RELEASES_REPO }}/releases/${RELEASE_ID}
break
else
echo "Not entering because $RELEASE_TAG_NAME it is not \"quickstart\""
fi
done
git push --delete origin quickstart
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.ENTANDO_BOT_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ env.ENTANDO_RELEASES_REPO }}/releases \
-d '{"tag_name":"quickstart","target_commitish":"${{ env.RELEASE_BRANCH }}","name":"quickstart","body":"quickstart release","draft":false,"prerelease":false,"generate_release_notes":true,"make_latest":"false"}'
else
echo "Not recreating tag because $LATEST_TAG_NAME is different then \"${{ env.RELEASE_TAG }}\""
fi
rm releases.json
fi