Repository navigation
Expand file tree
/
Copy pathcompute-tags.sh
More file actions
executable file
·83 lines (69 loc) · 2.54 KB
/
Copy pathcompute-tags.sh
File metadata and controls
executable file
·83 lines (69 loc) · 2.54 KB
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
#!/usr/bin/env bash
#
# Prints the tags the merge job applies to one directory's multi-arch image,
# one full image reference per line.
#
# The exact tag, <version>-<variant>-<suite>, is always printed. The floating
# tags follow only when update_floating_tags is true, so rebuilding an old
# patch release never moves them backwards: <branch>-<variant>-<suite>, the
# suite-less <major>-<variant> and <variant>, and latest for cli alone, as the
# official image does. A pre-release only ever gets the exact tag.
#
# The suite-less tags track whichever suite the run built on, so build.yml
# refuses update_floating_tags together with a base override.
#
# Usage: scripts/compute-tags.sh <version> <variant> <suite> <update_floating_tags>
# e.g. scripts/compute-tags.sh 8.4.13 fpm trixie false
set -Eeuo pipefail
# shellcheck source=scripts/pin-version.sh
source "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/pin-version.sh"
# GHCR only accepts lowercase repository names. build.yml reads this too.
IMAGE=ghcr.io/specsnl/php
LATEST_VARIANT=cli
# Replaces pin-version.sh's, which parse_version calls.
usage() {
echo >&2 "usage: ${0##*/} <version> <variant> <suite> <update_floating_tags> e.g. ${0##*/} 8.4.13 fpm trixie false"
exit 2
}
# Fails with usage unless a variant or suite can go into a tag as-is.
check_tag_part() {
local name="$1" value="$2"
if [[ ! "$value" =~ ^[a-z0-9][a-z0-9.]*$ ]]; then
echo >&2 "error: '$value' is not a $name like fpm or trixie"
usage
fi
}
# Succeeds when a run may move the floating tags. Pre-releases never do,
# whatever update_floating_tags says.
floating_tags_allowed() {
local version="$1" update_floating_tags="$2"
[ "$update_floating_tags" = true ] && ! is_prerelease "$version"
}
main() {
[ "$#" -eq 4 ] || usage
local version="$1" variant="$2" suite="$3" update_floating_tags="$4"
parse_version "$version"
check_tag_part variant "$variant"
check_tag_part suite "$suite"
case "$update_floating_tags" in
true | false) ;;
*)
echo >&2 "error: update_floating_tags must be true or false, not '$update_floating_tags'"
usage
;;
esac
echo "$IMAGE:$version-$variant-$suite"
if floating_tags_allowed "$version" "$update_floating_tags"; then
echo "$IMAGE:$branch-$variant-$suite"
echo "$IMAGE:${branch%%.*}-$variant"
echo "$IMAGE:$variant"
if [ "$variant" = "$LATEST_VARIANT" ]; then
echo "$IMAGE:latest"
fi
elif [ "$update_floating_tags" = true ]; then
echo >&2 "note: $version is a pre-release, so the floating tags stay where they are"
fi
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
fi