forked from openshift/release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag
executable file
·78 lines (64 loc) · 1.92 KB
/
tag
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
#!/bin/sh
set -euo pipefail
# Tag the contents of a branch and push to upstream.
#
# Usage: TO= FROM= ./branch [tag|reset|push]
#
# Argument:
# * <empty>: displays latest commit on the branch
# * tag: creates the tags and branches locally
# * reset: deletes the branches or tags to start over
# * push: actually push the branches and tags
base=$( dirname "${BASH_SOURCE[0]}")
source "${base}/lib/constants.sh"
DIR=${DIR:-/tmp/dist}
BRANCH=${BRANCH:-master}
for repo in "${MANAGED_REPOS[@]}"; do
if [[ ! -d ${DIR}/src/github.com/${repo} ]]; then
mkdir -p ${DIR}/src/github.com/${repo}
pushd ${DIR}/src/github.com/${repo} &>/dev/null
git clone --depth=1 --branch ${BRANCH} [email protected]:${repo} .
git remote set-branches origin '*'
popd &>/dev/null
fi
done
# clear the repos back to a known state
if [[ "${1-}" == "reset" ]]; then
for repo in "${MANAGED_REPOS[@]}"; do
pushd ${DIR}/src/github.com/${repo} &>/dev/null
git remote set-branches origin '*'
git fetch origin release-${FROM} 2>/dev/null
git checkout release-${FROM}
git reset origin/release-${FROM} --hard >/dev/null
if [[ -n "${TO-}" ]]; then
git tag -d v${TO} || true
fi
popd &>/dev/null
done
exit 0
fi
if [[ -z "${FROM-}" ]]; then
echo "Must set FROM= to the major/minor version of the current release, e.g. 3.9"
exit 1
fi
if [[ -z "${TO-}" ]]; then
echo "Must set TO= to the desired tag, e.g. 3.10.0"
exit 1
fi
for repo in "${MANAGED_REPOS[@]}"; do
pushd ${DIR}/src/github.com/${repo} &>/dev/null
if [[ "${1-}" == "" ]]; then
echo ${repo} '|' $( git log --oneline -1 HEAD )
continue
fi
! git rev-parse release-${FROM} &>/dev/null
! git rev-parse v${TO} &>/dev/null
git checkout release-${FROM}
if [[ "${1-}" == "tag" || "${1-}" == "push" ]]; then
git tag -f -s -a -m "v${TO}" v${TO}
fi
if [[ "${1-}" == "push" ]]; then
git push origin "v${TO}"
fi
popd &>/dev/null
done