-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverify-oss-formula-uptodate
executable file
·100 lines (89 loc) · 2.95 KB
/
verify-oss-formula-uptodate
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
93
94
95
96
97
98
99
100
#!/bin/bash
set -e
SELFDIR=$(dirname "$0")
SELFDIR=$(cd "$SELFDIR" && pwd)
# shellcheck source=lib/functions.sh
source "$SELFDIR/lib/functions.sh"
CORE_GIT_REPO_CACHE=
CORE_GIT_REMOTE=origin
function usage()
{
echo "Usage: ./verify-oss-formula-uptodate OPTIONS..."
echo "Verify whether the open source formula is still up-to-date compared to the one in Homebrew-core."
echo
echo "Optional options:"
echo " -c PATH Path to local Homebrew-core git repo cache"
echo " -r NAME Remote name in git repo cache. Default: origin"
echo " -h Show usage"
}
function parse_options()
{
local OPTIND=1
local opt
while getopts "c:r:h" opt; do
case "$opt" in
c)
CORE_GIT_REPO_CACHE="$OPTARG"
;;
r)
CORE_GIT_REMOTE="$OPTARG"
;;
h)
usage
exit
;;
*)
return 1
;;
esac
done
(( OPTIND -= 1 )) || true
shift $OPTIND || true
}
parse_options "$@"
if [[ "$CORE_GIT_REPO_CACHE" = "" ]]; then
TEMP_DIR=$(mktemp -d /tmp/verify-oss-formula-uptodate.XXXXXX)
function _cleanup()
{
run rm -rf "$TEMP_DIR"
}
echo "*** HINT: cloning homebrew-core takes a while. To speed up this operation next time, use specify a cache using -c and -r."
echo "+ Created temp dir $TEMP_DIR"
run git clone --bare https://github.com/Homebrew/homebrew-core.git "$TEMP_DIR/repo"
echo "+ Changing directory to: $TEMP_DIR/repo"
cd "$TEMP_DIR/repo"
echo "+ git log -n 1 --format=%ad master -- Formula/passenger.rb"
CORE_DATE=$(git log -n 1 --format=%ad master -- Formula/passenger.rb)
else
if [[ -e "$CORE_GIT_REPO_CACHE" ]]; then
echo "+ Changing directory to: $CORE_GIT_REPO_CACHE"
cd "$CORE_GIT_REPO_CACHE"
run git fetch "$CORE_GIT_REMOTE"
else
run git clone --bare https://github.com/Homebrew/homebrew-core.git "$CORE_GIT_REPO_CACHE"
echo "+ Changing directory to: $CORE_GIT_REPO_CACHE"
cd "$CORE_GIT_REPO_CACHE"
if [[ "$CORE_GIT_REMOTE" != origin ]]; then
run git remote add "$CORE_GIT_REMOTE" https://github.com/Homebrew/homebrew-core.git
run git fetch "$CORE_GIT_REMOTE"
fi
fi
echo "+ git log -n 1 --format=%ad $CORE_GIT_REMOTE/master -- Formula/passenger.rb"
CORE_DATE=$(git log -n 1 --format="%ad" "$CORE_GIT_REMOTE/master" -- Formula/passenger.rb)
fi
CORE_TIMESTAMP=$(ruby -rtime -e 'puts Time.parse(ARGV[0]).to_i' "$CORE_DATE")
echo "Homebrew-core's timestamp: $CORE_DATE => $CORE_TIMESTAMP"
echo
echo "+ Changing directory: $SELFDIR"
cd "$SELFDIR"
echo "+ Running: git log -n 1 --format=%ad -- Formula/passenger.rb"
OUR_DATE=$(git log -n 1 --format=%ad -- Formula/passenger.rb)
OUR_TIMESTAMP=$(ruby -rtime -e 'puts Time.parse(ARGV[0]).to_i' "$OUR_DATE")
echo "Our timestamp: $OUR_DATE => $OUR_TIMESTAMP"
echo
if [[ "$OUR_TIMESTAMP" -ge "$CORE_TIMESTAMP" ]] && [[ "$OUR_CONTENT" = "$CORE_CONTENT" ]]; then
echo "Our formula is sufficiently up-to-date compared to the one in the Homebrew official core tap."
else
echo "ERROR: our formula is outdated. There is a newer one in the Homebrew official core tap. Please merge over the changes."
exit 1
fi