-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommit-release
executable file
·102 lines (93 loc) · 2.73 KB
/
commit-release
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
101
102
#!/bin/sh
set -eu
dir=$1
version=$2
date=$3
if [ ! "$dir" ]; then
echo "usage: $0 dir [date]" >&2
exit 2
fi
echo dir=$dir
echo date=$date
download_and_extract() {
_name=$1 &&
_version=$2 &&
if [ "$_version" = "`cat $dir/$_name/.version`" ]; then return; fi &&
_file=$_name-$_version.tar.gz &&
_url=https://github.com/apple-oss-distributions/$_name/archive/$_file &&
# Keep the most recent items in cache
(cd cache && ls -t | tail -n +1000 | xargs -I {} rm -- {}) &&
# tar considers empty files to be valid, so check with gzip
if ! gzip -t cache/$_file; then
echo downloading $_url
_status=`curl -sL -D - -o cache/$_file $_url | \
awk '/^HTTP/{s=$2}END{print s}'`
if [ "$_status" = 404 ]; then
return 4
elif [ "$_status" != 200 ]; then
return 1
fi
fi &&
_dirname=`tar -tf cache/$_file | head -n 1 | cut -f 1 -d '/'` &&
gzip -t cache/$_file &&
tar -C $dir -xzf cache/$_file &&
# If directory lacks write permission, add it to allow removing files.
# If file size greater than 100MB (GitHub limit), remove it.
# Else if file lacks read permission, add it so git can read the file.
find $dir/$_dirname -type d ! -perm -u+w -exec chmod +w {} + -o \
-type f \( -size +204800 -exec rm -f {} + -o \
! -perm -u+r -exec chmod +r {} + \) &&
if [ -d "$dir/$_name" ]; then rm -rf $dir/$_name; fi &&
mv $dir/$_dirname $dir/$_name &&
echo $_version > $dir/$_name/.version || return 1
}
echo .version > $dir/.git/info/exclude
mkdir -p cache
if [ "$date" ]; then
export GIT_AUTHOR_DATE="${date}T00:00Z"
export GIT_COMMITTER_DATE="${date}T00:00Z"
fi
read comment name
echo name=$name
echo version=$version
names=
echo $comment $name > $dir/release.txt
while read _name _version; do
if [ ! "$_name" ]; then continue; fi
echo name=$_name version=$_version
if [ "$names" ]; then
names="$names|$_name"
else
names=$_name
fi
printf "%s\t%s\n" "$_name" "$_version" >> $dir/release.txt
download_and_extract $_name $_version &&
_status=$? || _status=$?
if [ "$_status" = 4 ]; then
echo skipping
elif [ "$_status" != 0 ]; then
exit 1
fi
done
removed=`printf "%s\n" $dir/*/ | grep -E -v "$dir/($names)/" || true`
# macOS 10.0.1 - 10.0.3 are missing most things so ignore them
# Same with some Developer Tools versions
if
[ "$removed" ] &&
[ "$name" != "Mac OS X 10.0.1" ] &&
[ "$name" != "Mac OS X 10.0.2" ] &&
[ "$name" != "Mac OS X 10.0.3" ] &&
[ "$name" != "Developer Tools 2.1" ] &&
[ "$name" != "Developer Tools 3.0" ] &&
[ "$name" != "Developer Tools 3.2" ]
then
echo REMOVING "$removed"
rm -rf $removed
fi
git -C $dir add .
git -C $dir lfs ls-files -n | xargs -E '' -I {} git -C $dir rm -f -- {}
git -C $dir commit -m $version
git -C $dir tag $version
if [ "${PUSH_RELEASE-}" ]; then
git -C $dir push && git -C $dir push --tags
fi