1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Temporarily publish test results under versioned directories.
|
4 | #
|
5 | # Usage:
|
6 | # ./publish.sh <function name>
|
7 | #
|
8 | # Use cases:
|
9 | # - Blogging
|
10 | # - Shared debugging
|
11 | # - Running tests on machines without a web server.
|
12 | #
|
13 | # Releases publish HTML the oilshell.org__deploy repo, but here we publish
|
14 | # directly to web servers.
|
15 |
|
16 | set -o nounset
|
17 | set -o pipefail
|
18 | set -o errexit
|
19 |
|
20 | readonly HOST='oilshell.org'
|
21 |
|
22 | log() {
|
23 | echo "$@" 1>&2
|
24 | }
|
25 |
|
26 | current-branch-name() {
|
27 | git rev-parse --abbrev-ref HEAD
|
28 | }
|
29 |
|
30 | versioned-dest() {
|
31 | local branch=$(current-branch-name)
|
32 | log "branch $branch"
|
33 | local hash=$(git rev-parse $branch)
|
34 | local short_hash=${hash:0:8}
|
35 | log "hash $short_hash"
|
36 |
|
37 | local dest="oilshell.org/git-branch/$branch/$short_hash"
|
38 | echo $dest
|
39 | }
|
40 |
|
41 | share-dir-versioned() {
|
42 | local dir=$1
|
43 | local user=$2
|
44 | local host=oilshell.org
|
45 |
|
46 | local dest
|
47 | dest="$(versioned-dest)/$(basename $dir)"
|
48 |
|
49 | ssh $user@$host mkdir -p $dest
|
50 |
|
51 | # rsync is faster than scp and has the --no-target-directory behavior.
|
52 | # We need --copy-links because the CSS files are symlinks.
|
53 | rsync --archive --verbose --copy-links \
|
54 | "$dir/" "$user@$host:$dest/"
|
55 |
|
56 | echo "Visit http://$dest/"
|
57 | }
|
58 |
|
59 | spec() {
|
60 | ### Publish spec tests to a versioned directory on a web server
|
61 |
|
62 | local user=$1
|
63 | share-dir-versioned _tmp/spec $user
|
64 | }
|
65 |
|
66 | benchmarks-perf() {
|
67 | ### Identical to above, except for the directory
|
68 |
|
69 | local user=$1
|
70 | share-dir-versioned _tmp/perf $user
|
71 | }
|
72 |
|
73 | benchmark() {
|
74 | ### Publish benchmarks to a versioned dir
|
75 |
|
76 | local user=$1
|
77 | local benchmark=${2:-osh-parser}
|
78 |
|
79 | local dest
|
80 | # Add hostname because spec tests aren't hermetic yet.
|
81 | #dest="$(versioned-dest)/$(hostname)/spec"
|
82 | dest="$(versioned-dest)/$benchmark"
|
83 |
|
84 | echo $dest
|
85 |
|
86 | ssh $user@$HOST mkdir -p $dest
|
87 |
|
88 | scp _tmp/$benchmark/index.html $user@$HOST:$dest/
|
89 |
|
90 | echo "Visit http://$dest/"
|
91 | }
|
92 |
|
93 | compress-wild() {
|
94 | local out="$PWD/_tmp/wild/wild.wwz"
|
95 | pushd _tmp/wild-www
|
96 | time zip -r -q $out . # recursive, quiet
|
97 | ls -l $out
|
98 | }
|
99 |
|
100 | # NOTE: Have to copy the web/ dir too? For testing, use ./local.sh
|
101 | # test-release-tree.
|
102 | wild() {
|
103 | local user=$1
|
104 | local host=${2:-${user}.org} # default host looks like the name
|
105 |
|
106 | local dest
|
107 | dest="$(versioned-dest)" # no wild/ suffix, since it's wild.wwz/
|
108 |
|
109 | ssh $user@$host mkdir -p $dest
|
110 |
|
111 | rsync --archive --verbose \
|
112 | _tmp/wild/wild.wwz $user@$host:$dest/
|
113 |
|
114 | echo "Visit http://$dest/wild.wwz/"
|
115 | }
|
116 |
|
117 | web-dir() {
|
118 | local user=$1
|
119 | local dest=$2
|
120 |
|
121 | # This is made by copy-web in devtools/release.sh. Reuse it here.
|
122 | rsync --archive --verbose \
|
123 | _release/VERSION/web/ $dest
|
124 |
|
125 | echo "Published to $dest"
|
126 | }
|
127 |
|
128 | web-dir-versioned() {
|
129 | ### Publish static assets needed for the wild HTML pages (versioned)
|
130 | local user=$1
|
131 | local host=oilshell.org
|
132 |
|
133 | local branch=$(current-branch-name)
|
134 | local dir=oilshell.org/git-branch/$branch/web/
|
135 |
|
136 | local dest=$user@$host:$dir
|
137 |
|
138 | ssh $user@$host mkdir --verbose -p $dir
|
139 | web-dir $user $dest
|
140 | }
|
141 |
|
142 | web-dir-preview() {
|
143 | ### Publish static assets needed for the wild HTML pages.
|
144 | local user=$1
|
145 | local host=oilshell.org
|
146 |
|
147 | local dir='oilshell.org/preview/web'
|
148 |
|
149 | ssh $user@$host mkdir --verbose -p $dir
|
150 |
|
151 | local dest=$user@$host:$dir
|
152 | web-dir $user $dest
|
153 | }
|
154 |
|
155 | doc-preview() {
|
156 | ### Publish a file (e.g. _release/VERSION/doc/json.html) to
|
157 | local user=$1
|
158 | local host=oilshell.org
|
159 |
|
160 | local path=$2
|
161 | local dest=${3:-'oilshell.org/preview/doc'}
|
162 |
|
163 | ssh $user@$host mkdir --verbose -p $dest
|
164 | scp $path $user@$host:$dest
|
165 | }
|
166 |
|
167 | mycpp-benchmarks() {
|
168 | doc-preview $1 _tmp/mycpp-benchmarks/index.html oilshell.org/preview/benchmarks/mycpp
|
169 | }
|
170 |
|
171 | shell-vs-shell() {
|
172 | doc-preview $1 _tmp/shell-vs-shell/index.html oilshell.org/preview/shell-vs-shell
|
173 | }
|
174 |
|
175 | file-to-share() {
|
176 | local user=$1
|
177 | local host=oilshell.org
|
178 |
|
179 | local file=$2
|
180 | local dest_suffix=${3:-} # e.g. .txt
|
181 |
|
182 | local dest=$user@$host:oilshell.org/share/$(basename $file)$dest_suffix
|
183 |
|
184 | scp $file $dest
|
185 | }
|
186 |
|
187 | "$@"
|