forked from uw-psych/hyakvnc_apptainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag-release.sh
executable file
·82 lines (63 loc) · 1.81 KB
/
tag-release.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
#!/usr/bin/env bash
set -o pipefail
[[ -n "${XDEBUG:-}" ]] && set -x
TAG_PREFIX="sif-"
IMAGE_TAG_SEP="@"
IMAGE_NAME="${1:-}"
[[ -n "${IMAGE_NAME:-}" ]] || { echo "IMAGE_NAME is empty" >&2; exit 1; }
shift
IMAGE_TAG="${1:-}"
if [[ -z "${IMAGE_TAG:-}" ]]; then
IMAGE_TAG="latest"
echo "IMAGE_TAG is empty, using default: ${IMAGE_TAG}" >&2
else
shift
fi
FULL_CONTAINER_NAME="${IMAGE_NAME}:${IMAGE_TAG}"
GIT_TAG="${TAG_PREFIX}${IMAGE_NAME}${IMAGE_TAG_SEP}${IMAGE_TAG}"
[[ -n "${GIT_TAG:-}" ]] || { echo "GIT_TAG is empty" >&2; exit 1; }
comment="${1:-}"
if [[ -z "${comment:-}" ]]; then
comment="${FULL_CONTAINER_NAME}"
echo "comment is empty, using default: ${comment}" >&2
else
shift
fi
git_tag_args=()
git_commit_args=()
if [[ -n "${comment:-}" ]]; then
git_tag_args+=(-m "${comment}")
git_commit_args+=(-m "${comment}")
fi
for arg in "$@"; do
git_tag_args+=(-m "${arg}")
git_commit_args+=(-m "${arg}")
done
echo "git_tag_args: ${git_commit_args[*]}" >&2
echo "git_commit_args: ${git_commit_args[*]}" >&2
if git tag -l "${GIT_TAG:-}" | grep -q "^${GIT_TAG:-}$"; then
echo "git tag ${GIT_TAG} already exists" >&2
if [[ -t 1 ]]; then
choice=y
read -rp "Do you want to continue? [Y/n] " choice
[[ "${choice:-y}" =~ ^[Yy]$ ]] || exit 1
fi
fi
if [[ -t 1 ]]; then
echo "git tag -fa ${GIT_TAG} ${git_tag_args[*]}"
choice=y
read -rp "Do you want to continue? [Y/n] " choice
[[ "${choice:-y}" =~ ^[Yy]$ ]] || exit 1
fi
git commit --allow-empty "${git_commit_args[@]}"
git push
git tag -fa "${GIT_TAG}" "${git_tag_args[@]}"
echo 'Tag contents:'
git tag -l --format='%(contents)' "$(git describe --tags --abbrev=0 || true)"
if [[ -t 1 ]]; then
choice=y
read -rp "Do you want to push to origin? [Y/n] " choice
[[ "${choice:-y}" =~ ^[Yy]$ ]] || exit 0
fi
echo "Pushing to origin: ${GIT_TAG}"
git push -f origin "${GIT_TAG}"