forked from pytchlang/pytch-releases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.sh
executable file
·150 lines (125 loc) · 4.57 KB
/
make.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
REPO_ROOT="$(dirname "$(realpath "$0")")"
cd "$REPO_ROOT"
# Rough test that submodules have been init'd correctly:
if [ ! -x pytch-vm/website-layer/make.sh ]; then
(
echo "It looks like submodules have not been set up yet. If you"
echo "have just cloned this repo, you can run 'develop.sh' to set"
echo "up the submodules and branches."
) >&2
exit 1
fi
if [ $(git status --ignore-submodules=none --porcelain | wc -l) -ne 0 ]; then
(
echo "Working directory not clean; abandoning build"
echo
git status
) >&2
exit 1
fi
current_branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "$current_branch" = releases ]; then
current_tag="$(git tag --points-at)"
if [ -z "$current_tag" ]; then
>&2 echo No tag found pointing to HEAD on releases
exit 1
fi
current_tutorials_branch="$(cd pytch-tutorials && git rev-parse --abbrev-ref HEAD)"
if [ "$current_tutorials_branch" != releases ]; then
>&2 echo Top level repo is on '"releases"' branch but tutorials is not
exit 1
fi
bare_version=$(echo $current_tag | sed 's/^v//')
zipfile_name=release-"$bare_version".zip
containing_dir=releases/"$bare_version"
export DEPLOY_BASE_URL=/
export PYTCH_VERSION_TAG=$current_tag
else
if [ ! -e pytch-tutorials/index.yaml ]; then
>&2 echo "No pytch-tutorials/index.yaml found; is correct branch checked out?"
exit 1
fi
bare_version=""
head_sha="$(git rev-parse HEAD | cut -c -12)"
zipfile_name=beta-g${head_sha}.zip
if [ ! -z "$PYTCH_DEPLOY_BASE_URL" ]; then
containing_dir="${PYTCH_DEPLOY_BASE_URL#/}"
if [ "$PYTCH_DEPLOY_BASE_URL" = "$containing_dir" ]; then
>&2 echo "PYTCH_DEPLOY_BASE_URL must start with a '/' character"
exit 1
fi
>&2 echo "Using custom DEPLOY_BASE_URL $PYTCH_DEPLOY_BASE_URL"
else
containing_dir=beta/g${head_sha}
fi
export DEPLOY_BASE_URL=/${containing_dir}
export PYTCH_VERSION_TAG=g$head_sha
fi
export PYTCH_DEPLOYMENT_ID=$(git rev-parse HEAD | cut -c -20)
>&2 echo Making "$zipfile_name"
logdir_relative="build-logs/$(date +%Y%m%dT%H%M%S)"
LOGDIR="$REPO_ROOT/$logdir_relative"
mkdir -p "$LOGDIR"
>&2 echo Logging to "$logdir_relative"
toplevel_htaccess() {
sed "s/VERSION-STRING/$bare_version/" < "$REPO_ROOT"/toplevel-htaccess-template
}
git submodule --quiet update \
&& (
rm -rf pytch-vm/node_modules \
pytch-vm/website-layer/layer-content \
pytch-vm/website-layer/layer.zip
rm -rf pytch-webapp/node_modules \
pytch-webapp/website-layer/layer-content \
pytch-webapp/website-layer/layer.zip
rm -rf pytch-website/venv \
pytch-website/website-layer/layer-content \
pytch-website/website-layer/layer.zip
rm -rf pytch-build/venv \
pytch-build/website-layer/layer-content \
pytch-build/website-layer/layer.zip
) \
&& (
(
cd pytch-vm
website-layer/make.sh > $LOGDIR/pytch-vm.out 2> $LOGDIR/pytch-vm.err
>&2 echo Built pytch-vm layer
) &
(
cd pytch-webapp
website-layer/make.sh > $LOGDIR/pytch-webapp.out 2> $LOGDIR/pytch-webapp.err
>&2 echo Built pytch-webapp layer
) &
(
cd pytch-website
website-layer/make.sh > $LOGDIR/pytch-website.out 2> $LOGDIR/pytch-website.err
>&2 echo Built pytch-website layer
) &
(
# This builds the tutorials layer, hence break in pattern for out/err files.
cd pytch-build
makesite/tutorials-layer.sh > $LOGDIR/pytch-tutorials.out 2> $LOGDIR/pytch-tutorials.err
>&2 echo Built pytch-tutorials layer
) &
wait
) \
&& (
mkdir -p website-layer
cd website-layer
rm -rf "$containing_dir"
mkdir -p "$containing_dir"
# The tutorials come from 'pytch-build'.
for repo in pytch-vm pytch-webapp pytch-website pytch-build; do
unzip -q -d $containing_dir ../$repo/website-layer/layer.zip
done
if [ ! -z $bare_version ]; then
>&2 echo Writing htaccess to redirect $bare_version
toplevel_htaccess $bare_version > "$containing_dir"/toplevel-dot-htaccess
fi
rm -f "$zipfile_name"
zip -q -r "$zipfile_name" "$containing_dir"
tarfile_name="${zipfile_name%.zip}".tar.gz
tar zcf "$tarfile_name" "$containing_dir"
)
echo "$(pwd)"/website-layer/"$zipfile_name"