-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpublish.sh
executable file
·92 lines (79 loc) · 2.86 KB
/
publish.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
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
set -eu
set -o pipefail
export COMMIT_MESSAGE=$(git log --format=%B --no-merges -n 1 | tr -d '\n')
# `is_pr_merge` is designed to detect if a gitsha represents a normal
# push commit (to any branch) or whether it represents travis attempting
# to merge between the origin and the upstream branch.
# For more details see: https://docs.travis-ci.com/user/pull-requests
function is_pr_merge() {
# Get the commit message via git log
# This should always be the exactly the text the developer provided
local COMMIT_LOG=${COMMIT_MESSAGE}
# Get the commit message via git show
# If the gitsha represents a merge then this will
# look something like "Merge e3b1981 into 615d2a3"
# Otherwise it will be the same as the "git log" output
export COMMIT_SHOW=$(git show -s --format=%B | tr -d '\n')
if [[ "${COMMIT_LOG}" != "${COMMIT_SHOW}" ]]; then
echo true
fi
}
# Detect if this commit represents a tag. This is useful
# to detect if we are on a travis job that is running due to
# "git tags --push". In this case we don't want to publish even
# if [publish binary] is present since that should refer only to the
# previously job that ran for that commit and not the tag made
function is_tag_commit() {
export COMMIT_MATCHES_KNOWN_TAG=$(git describe --exact-match $(git rev-parse HEAD) 2> /dev/null)
if [[ ${COMMIT_MATCHES_KNOWN_TAG} ]]; then
echo true
fi
}
# `publish` is used to publish binaries to s3 via commit messages if:
# - the commit message includes [publish binary]
# - the commit message includes [republish binary]
# - the commit is not a pr_merge (checked with `is_pr_merge` function)
function publish() {
echo "dumping binary meta..."
./node_modules/.bin/node-pre-gyp reveal --loglevel=error $@
echo "determining publishing status..."
if [[ $(is_pr_merge) ]]; then
echo "Skipping publishing because this is a PR merge commit"
elif [[ $(is_tag_commit) ]]; then
echo "Skipping publishing because this is a tag"
else
echo "Commit message was: '${COMMIT_MESSAGE}'"
if [[ ${COMMIT_MESSAGE} =~ "[publish binary]" ]]; then
echo "Publishing"
./node_modules/.bin/node-pre-gyp package publish $@
elif [[ ${COMMIT_MESSAGE} =~ "[republish binary]" ]]; then
echo "Re-Publishing"
./node_modules/.bin/node-pre-gyp package unpublish publish $@
else
echo "Skipping publishing since we did not detect either [publish binary] or [republish binary] in commit message"
fi
fi
}
function usage() {
>&2 echo "Usage"
>&2 echo ""
>&2 echo "$ ./scripts/publish.sh <args>"
>&2 echo ""
>&2 echo "All args are forwarded to node-pre-gyp like --debug"
>&2 echo ""
exit 1
}
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
for i in "$@"
do
case $i in
-h | --help)
usage
shift
;;
*)
;;
esac
done
publish $@