forked from postgis/docker-postgis
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapply-ci.sh
executable file
·93 lines (79 loc) · 3.25 KB
/
apply-ci.sh
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
#!/bin/bash
set -Eeuo pipefail
# Source environment variables and necessary configurations
source tools/environment_init.sh
[ -f ./versions.json ]
input_file="versions.json"
# cleaning the workfile
rm -f _matrix.yml
rm -f _circleci_arm64.yml
## Load .env files config.
#set -a
#if [[ "${TEST:-}" == "true" ]]; then
# # shellcheck disable=SC1091
# source .env.test
#else
# # shellcheck disable=SC1091
# source .env
#fi
#set +a
versions=$(jq 'keys[]' "$input_file")
# the bundle version and the source - should be generated in the same workflow.
# so we need all bundle base list - for removing the matrix.
function generate_versions_bundle_base() {
versions_bundle_base=''
for version in $versions; do
version=$(echo "$version" | tr -d '"')
variants=$(jq ".\"$version\" | keys[]" "$input_file")
for variant in $variants; do
variant=$(echo "$variant" | tr -d '"')
if [[ $(echo "$version" | grep -o '-' | wc -l) -eq 2 ]]; then
echo "bundle detected: ${version}-${variant} ( The version variable contains two '-' ) "
versions_bundle_base+=$(echo "${version}" | cut -d'-' -f1-2)-${variant}
fi
done
done
echo "## versions_bundle_base=$versions_bundle_base"
}
generate_versions_bundle_base
#TODO: arch based filter for amd64 and arm64
for version in $versions; do
# Remove quotes around version
version=$(echo "$version" | tr -d '"')
variants=$(jq ".\"$version\" | keys[]" "$input_file")
for variant in $variants; do
# Remove quotes around variant
variant=$(echo "$variant" | tr -d '"')
arch=$(jq -r ".\"$version\".\"$variant\".arch" "$input_file")
if [[ $arch == *"amd64"* ]]; then
if [[ $versions_bundle_base =~ ${version}-${variant} ]]; then
echo "# --skip-- - { version: \"$version\", variant: \"$variant\" } --> generated with the related bundle job!" >>_matrix.yml
else
echo " - { version: \"$version\", variant: \"$variant\" }" >>_matrix.yml
fi
fi
if [[ $arch == *"arm64"* ]]; then
if [[ $versions_bundle_base =~ ${version}-${variant} ]]; then
echo "# --skip-- \"${version}-${variant}\", --> generated with the related bundle job!" >>_circleci_arm64.yml
else
echo " \"${version}-${variant}\"," >>_circleci_arm64.yml
fi
fi
done
done
# ------------- Update .github/workflows/main.yml ------------------
echo "## update .github/workflows/main.yml ##"
awk -v content="$(<_matrix.yml)" '
$0 ~ "#matrix-include-start" {print; print content; f=1; next}
$0 ~ "#matrix-include-end" {f=0}
!f' .github/workflows/main.yml >.github/workflows/main.tmp && mv .github/workflows/main.tmp .github/workflows/main.yml
echo "## _matrix.yml ## "
cat _matrix.yml
# ------------- Update .circleci/config.yml ------------------
echo "## update .circleci/config.yml ##"
awk -v content="$(<_circleci_arm64.yml)" '
$0 ~ "#circleci-targets-start" {print; print content; f=1; next}
$0 ~ "#circleci-targets-end" {f=0}
!f' .circleci/config.yml >.circleci/config.tmp && mv .circleci/config.tmp .circleci/config.yml
echo "## _circleci_arm64.yml ##"
cat _circleci_arm64.yml