Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Commit cee133d

Browse files
authored
Improve argument parsing of promote-nightly-to-release (#255)
Currently, skipping a release requires manually editing this script to change MINOR-1 to MINOR-2, and suppressing the various checks in it. - fully support this case with `--previous` - add `--force` to permit local changes - add `--dry-run` to verify inferred version - improve argument parsing significantly - move the workdir check before the git check, as the git check fails if the workdir is wrong Options (including `--help`) can come before or after the arguments, as long as `--` isn't specified. Test plan: - Used to tag and start build of 4.133 (with --previous=4.131) - ran without `--previous` and with `--dry-run` to verify the MINOR-1 logic still works - needed `--force` to run as I hadn't committed this yet.
1 parent d24093f commit cee133d

File tree

1 file changed

+153
-27
lines changed

1 file changed

+153
-27
lines changed

bin/promote-nightly-to-release

Lines changed: 153 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,182 @@
77
# LICENSE file in the root directory of this source tree.
88

99
set -e
10-
NIGHTLY="$1"
11-
VERSION="$2"
1210

13-
if [ -z "$NIGHTLY" -o -z "$VERSION" -o "$1" == "--help" ]; then
14-
echo "Usage: $0 (YYYY.MM.DD|existing-tag) MAJOR.MINOR"
11+
function show_help() {
12+
cat<<EOF
13+
Usage: $0 [OPTIONS] (YYYY.MM.DD|existing-tag) MAJOR.MINOR"
14+
Options:
15+
--help
16+
Show this page
17+
--previous=PREV_MAJOR.PREV_MINOR
18+
(default: MAJOR.(MINOR - 1))
19+
Manually specify the previous release. Useful when a release has been
20+
skipped.
21+
--dry-run
22+
Only show the versions that would be used, don't actually do anything.
23+
--force
24+
Skip safety checks:
25+
- allow uncommitted changes to this repository
26+
- do not require that the local checkout is in sync with upstream
27+
EOF
28+
}
29+
30+
if [ "$#" == "0" ]; then
31+
show_help;
32+
exit 1;
33+
fi
34+
35+
FORCE=false
36+
DRY_RUN=false
37+
POSITIONAL_ARGUMENTS=()
38+
while (($#)); do
39+
case "$1" in
40+
--help)
41+
show_help
42+
exit
43+
;;
44+
--force)
45+
FORCE=true
46+
shift
47+
;;
48+
--dry-run)
49+
DRY_RUN=true
50+
shift
51+
;;
52+
--previous)
53+
shift
54+
if ! (($#)); then
55+
echo "'--previous' requires a value."
56+
show_help
57+
exit 1
58+
fi
59+
PREVIOUS_VERSION="$1"
60+
shift
61+
;;
62+
--previous=*)
63+
PREVIOUS_VERSION="${1#--previous=}"
64+
if [ -z "${PREVIOUS_VERSION}" ]; then
65+
echo "'--previous' requires a value."
66+
show_help
67+
exit 1
68+
fi
69+
shift
70+
;;
71+
--)
72+
shift
73+
POSITIONAL_ARGUMENTS=("${POSITIONAL_ARGUMENTS[@]}" "$@")
74+
break
75+
;;
76+
--*)
77+
echo "Unrecognized option: $1"
78+
show_help
79+
exit 1
80+
;;
81+
*)
82+
POSITIONAL_ARGUMENTS+=("$1")
83+
shift
84+
;;
85+
esac
86+
done
87+
88+
if [ "${#POSITIONAL_ARGUMENTS[@]}" != "2" ]; then
89+
echo "Expected two arguments, got ${#POSITIONAL_ARGUMENTS[@]}:"
90+
echo " ${POSITIONAL_ARGUMENTS[*]}"
91+
show_help
1592
exit 1
1693
fi
17-
if ! echo "$VERSION" | grep -q -e '^[0-9]\+\.[0-9]\+$'; then
18-
echo "Only specify MAJOR.MINOR version, not MAJOR.MINOR.RELEASE"
94+
95+
NIGHTLY="${POSITIONAL_ARGUMENTS[0]}"
96+
VERSION="${POSITIONAL_ARGUMENTS[1]}"
97+
98+
if [ -z "$NIGHTLY" -o -z "$VERSION" ]; then
99+
echo "Missing nightly $NIGHTLY or version $VERSION"
100+
show_help
19101
exit 1
20102
fi
21-
if [ "$(<.git/HEAD)" != "ref: refs/heads/master" ]; then
22-
echo "Run from master branch."
103+
104+
function check_version() {
105+
local VERSION="$1"
106+
if ! echo "$VERSION" | grep -q -e '^[0-9]\+\.[0-9]\+$'; then
107+
echo "Only specify MAJOR.MINOR version, not MAJOR.MINOR.RELEASE"
108+
exit 1
109+
fi
110+
}
111+
112+
check_version "$VERSION"
113+
114+
if [ -z "${PREVIOUS_VERSION}" ]; then
115+
MAJOR=$(echo "$VERSION" | cut -f1 -d.)
116+
MINOR=$(echo "$VERSION" | cut -f2 -d.)
117+
PREVIOUS_VERSION="${PREVIOUS_VERSION:-"${MAJOR}.$((MINOR-1))"}"
118+
fi
119+
check_version "$PREVIOUS_VERSION"
120+
121+
if [ "$#" -gt 2 ]; then
122+
echo "Options must come before positional arguments."
123+
show_help
23124
exit 1
24125
fi
25-
if ! git diff --exit-code >/dev/null; then
26-
echo "Uncommitted changes, bailing out."
126+
127+
cat <<EOF
128+
----------------
129+
--- Versions ---
130+
----------------
131+
Nightly build:
132+
${NIGHTLY}
133+
Previous version:
134+
${PREVIOUS_VERSION}
135+
Tagging version:
136+
${VERSION}
137+
----------------
138+
EOF
139+
140+
if $DRY_RUN; then
141+
exit 0
142+
fi
143+
144+
if $FORCE; then
145+
FORCEABLE='[WARNING - FORCED]'
146+
else
147+
FORCEABLE='[FORCEABLE ERROR]'
148+
fi
149+
150+
PKGDIR="$(pwd)"
151+
if [ ! -e "$PKGDIR/bin/$(basename "$0")" ]; then
152+
echo "This script must be ran from the root of the packaging repository."
27153
exit 1
28154
fi
29155

156+
if [ "$(<.git/HEAD)" != "ref: refs/heads/master" ]; then
157+
echo "${FORCEABLE} Run from master branch."
158+
$FORCE || exit 1
159+
fi
160+
if ! git diff --exit-code >/dev/null; then
161+
echo "${FORCEABLE} Uncommitted changes."
162+
$FORCE || exit 1
163+
fi
164+
30165
echo "Fetching any updates to packaging repo..."
31166
git fetch >/dev/null
32167
if ! git diff --exit-code origin/master..HEAD >/dev/null; then
33-
echo "Current branch is out of sync with origin/master, bailing out."
34-
exit 1
168+
echo "${FORCEABLE} Current branch is out of sync with origin/master"
169+
$FORCE || exit 1
35170
fi
36171

37-
MAJOR=$(echo "$VERSION" | cut -f1 -d.)
38-
MINOR=$(echo "$VERSION" | cut -f2 -d.)
39-
40172
SED=$(if [ "$(uname -s)" == "Darwin" ]; then echo gsed; else echo sed; fi)
41173

42-
if ! which $SED >/dev/null; then
174+
if ! which "$SED" >/dev/null; then
43175
echo "'$SED' is required."
44176
if [ "$SED" == "gsed" ]; then
45177
echo "Try: brew install gnu-sed"
46178
fi
47179
exit 1
48180
fi
49181

50-
PKGDIR="$(pwd)"
51-
if [ ! -e "$PKGDIR/bin/$(basename $0)" ]; then
52-
echo "This script must be ran from the root of the packaging repository."
53-
exit 1
54-
fi
55-
56182
GIT_ORIGIN="$(git remote get-url origin)"
57183
if [ "$GIT_ORIGIN" != "git@github.com:hhvm/packaging.git" ]; then
58-
echo "Git origin must be set to hhvm/packaging (not a fork)."
59-
exit 1
184+
echo "${FORCEABLE} Git origin must be set to hhvm/packaging (not a fork)."
185+
$FORCE || exit 1
60186
fi
61187

62188
function statusline() {
@@ -71,8 +197,8 @@ function statusline() {
71197
statusline "Creating packaging branch..."
72198
git checkout -b "HHVM-${VERSION}"
73199
statusline "Marking support for new DISTRO apt repo.."
74-
echo "DISTRO-${MAJOR}.${MINOR}" >> DEBIAN_REPOSITORIES
75-
git commit DEBIAN_REPOSITORIES -m "Adding DISTRO-${MAJOR}.${MINOR} apt repositories"
200+
echo "DISTRO-${VERSION}" >> DEBIAN_REPOSITORIES
201+
git commit DEBIAN_REPOSITORIES -m "Adding DISTRO-${VERSION} apt repositories"
76202
statusline "Pushing packaging branch..."
77203
git push -u origin "HEAD:HHVM-${VERSION}"
78204

@@ -101,7 +227,7 @@ git clone git@github.com:hhvm/hhvm-docker.git
101227
(
102228
cd hhvm-docker
103229
statusline "Removing 'latest' from previous release branch tags..."
104-
git checkout "HHVM-${MAJOR}.$(($MINOR - 1))"
230+
git checkout "HHVM-${PREVIOUS_VERSION}"
105231
$SED -i '/^latest$/d' EXTRA_TAGS
106232
git commit EXTRA_TAGS -m "Removing 'latest' tag"
107233
git push

0 commit comments

Comments
 (0)