-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-supported-tags.sh
executable file
·75 lines (58 loc) · 2.36 KB
/
generate-supported-tags.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
#!/usr/bin/env bash
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
COMMIT_ID=$(git rev-parse --verify HEAD)
JSON="$(cat ./versions.json)"
OFFICIAL_VERSIONS_KEYS=()
REPOSITORY='https://github.com/dstmodders/docker-terraria-server'
TSHOCK_VERSIONS_KEYS=()
mapfile -t OFFICIAL_VERSIONS_KEYS < <(jq -r '.official | keys[]' <<< "$JSON")
# shellcheck disable=SC2207
IFS=$'\n' OFFICIAL_VERSIONS_KEYS=($(sort -rV <<< "${OFFICIAL_VERSIONS_KEYS[*]}")); unset IFS
mapfile -t TSHOCK_VERSIONS_KEYS < <(jq -r '.tshock | keys[]' <<< "$JSON")
# shellcheck disable=SC2207
IFS=$'\n' TSHOCK_VERSIONS_KEYS=($(sort -rV <<< "${TSHOCK_VERSIONS_KEYS[*]}")); unset IFS
readonly BASE_DIR
readonly COMMIT_ID
readonly JSON
readonly OFFICIAL_VERSIONS_KEYS
readonly REPOSITORY
readonly TSHOCK_VERSIONS_KEYS
function print_url() {
local tags="$1"
local commit="$2"
local directory="$3"
local url="[$tags]($REPOSITORY/blob/$commit/$directory/Dockerfile)"
echo "- $url"
}
cd "$BASE_DIR" || exit 1
printf "## Supported tags and respective \`Dockerfile\` links\n\n"
# reference: 1.4.4.9-official, 1.4.4.9, official, latest
for key in "${OFFICIAL_VERSIONS_KEYS[@]}"; do
commit="$COMMIT_ID"
terraria_version=$(jq -r ".official | .[$key] | .terraria_version" <<< "$JSON")
terraria_latest=$(jq -r ".official | .[$key] | .terraria_latest" <<< "$JSON")
tags="\`$terraria_version-official\`, \`$terraria_version\`"
if [ "$terraria_latest" == 'true' ]; then
tags="$tags, \`official\`, \`latest\`"
fi
print_url "$tags" "$commit" 'official'
done
# reference: 1.4.4.9-tshock-5.2.0, 1.4.4.9-tshock, tshock-5.2.0, 5.2.0, tshock
for key in "${TSHOCK_VERSIONS_KEYS[@]}"; do
commit="$COMMIT_ID"
terraria_version=$(jq -r ".tshock | .[$key] | .terraria_version" <<< "$JSON")
terraria_latest=$(jq -r ".tshock | .[$key] | .terraria_latest" <<< "$JSON")
tshock_version=$(jq -r ".tshock | .[$key] | .tshock_version" <<< "$JSON")
tshock_latest=$(jq -r ".tshock | .[$key] | .tshock_latest" <<< "$JSON")
tags="\`$terraria_version-tshock-$tshock_version\`"
if [ "$tshock_latest" == 'true' ]; then
tags="$tags, \`$terraria_version-tshock\`"
fi
if [ "$terraria_latest" == 'true' ]; then
tags="$tags, \`tshock-$tshock_version\`, \`$tshock_version\`"
fi
if [ "$terraria_latest" == 'true' ] && [ "$tshock_latest" == 'true' ]; then
tags="$tags, \`tshock\`"
fi
print_url "$tags" "$commit" 'tshock'
done