Skip to content

Commit 4e48e32

Browse files
committed
Convert "generate-stackbrew-library.sh" to output the new 2822-based format
1 parent a85a6d6 commit 4e48e32

File tree

1 file changed

+60
-10
lines changed

1 file changed

+60
-10
lines changed

generate-stackbrew-library.sh

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,75 @@
11
#!/bin/bash
2-
set -e
2+
set -eu
33

44
declare -A aliases=(
55
[9.5]='9 latest'
66
)
77

8+
self="$(basename "$BASH_SOURCE")"
89
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
910

1011
versions=( */ )
1112
versions=( "${versions[@]%/}" )
12-
url='git://github.com/docker-library/postgres'
1313

14-
echo '# maintainer: InfoSiftr <github@infosiftr.com> (@infosiftr)'
14+
# sort version numbers with highest first
15+
IFS=$'\n'; versions=( $(echo "${versions[*]}" | sort -rV) ); unset IFS
16+
17+
# get the most recent commit which modified any of "$@"
18+
fileCommit() {
19+
git log -1 --format='format:%H' HEAD -- "$@"
20+
}
21+
22+
# get the most recent commit which modified "$1/Dockerfile" or any file COPY'd from "$1/Dockerfile"
23+
dirCommit() {
24+
local dir="$1"; shift
25+
(
26+
cd "$dir"
27+
fileCommit \
28+
Dockerfile \
29+
$(git show HEAD:./Dockerfile | awk '
30+
toupper($1) == "COPY" {
31+
for (i = 2; i < NF; i++) {
32+
print $i
33+
}
34+
}
35+
')
36+
)
37+
}
38+
39+
cat <<-EOH
40+
# this file is generated via https://github.com/docker-library/postgres/blob/$(fileCommit "$self")/$self
41+
42+
Maintainers: Tianon Gravi <admwiggin@gmail.com> (@tianon),
43+
Joseph Ferguson <yosifkit@gmail.com> (@yosifkit)
44+
GitRepo: https://github.com/docker-library/postgres.git
45+
EOH
46+
47+
# prints "$2$1$3$1...$N"
48+
join() {
49+
local sep="$1"; shift
50+
local out; printf -v out "${sep//%/%%}%s" "$@"
51+
echo "${out#$sep}"
52+
}
1553

1654
for version in "${versions[@]}"; do
17-
commit="$(cd "$version" && git log -1 --format='format:%H' -- Dockerfile $(awk 'toupper($1) == "COPY" { for (i = 2; i < NF; i++) { print $i } }' Dockerfile))"
18-
fullVersion="$(grep -m1 'ENV PG_VERSION ' "$version/Dockerfile" | cut -d' ' -f3 | cut -d- -f1 | sed 's/~/-/g')"
19-
versionAliases=( $fullVersion $version ${aliases[$version]} )
20-
21-
echo
22-
for va in "${versionAliases[@]}"; do
23-
echo "$va: ${url}@${commit} $version"
55+
commit="$(dirCommit "$version")"
56+
57+
fullVersion="$(git show "$commit":"$version/Dockerfile" | awk '$1 == "ENV" && $2 == "PG_VERSION" { gsub(/-.*$/, "", $3); gsub(/~/, "-", $3); print $3; exit }')"
58+
59+
versionAliases=()
60+
while [ "$fullVersion" != "$version" -a "${fullVersion%[.-]*}" != "$fullVersion" ]; do
61+
versionAliases+=( $fullVersion )
62+
fullVersion="${fullVersion%[.-]*}"
2463
done
64+
versionAliases+=(
65+
$version
66+
${aliases[$version]:-}
67+
)
68+
69+
echo
70+
cat <<-EOE
71+
Tags: $(join ', ' "${versionAliases[@]}")
72+
GitCommit: $commit
73+
Directory: $version
74+
EOE
2575
done

0 commit comments

Comments
 (0)