chiark / gitweb /
jstest: Introduce Rust helper code
[otter.git] / make-release
1 #!/bin/bash
2 #
3 # usage:
4 #    ./make-release --dry-run|--real <branch>
5 # eg
6 #    ./make-release --dry-run main
7
8
9 # Overall release steps:
10 #
11 #  - update dependencies (cargo update, cargo upgrades)
12 #  - update our Nightly rust and do a test build, note in build.rst
13 #  - edit CHANGELOG.md
14 #  - update versions
15 #  - ensure pretest == tested == main
16 #  - make deploy and test that chiark still works
17 #  - make-release
18 #  - release announcement to mailing list
19 #  - blog post
20
21 #---------- argument parsing and options ----------
22
23 set -e
24 set -o pipefail
25
26 fail () { echo >&2 "${0##*/}: error: $*"; exit 12; }
27
28 dryrun=x-dry-run-unset
29 cargo_dryrun=--not-a-cargo-option-please-crash
30
31 case "$#.$1" in
32 2.--real)    dryrun=x     ; cargo_dryrun=''         ; ;;
33 2.--dry-run) dryrun=dryrun; cargo_dryrun='--dry-run'; ;;
34 *)           fail "bad usage" ;;
35 esac
36
37 keyid=0x559AE46C2D6B6D3265E7CBA1E3E3392348B50D39
38
39 cratesio_raw_url=\
40 https://raw.githubusercontent.com/rust-lang/crates.io-index/master
41
42 branch="$2"
43
44 dryrun () { echo "WOULD  $*"; }
45 x () { echo >&2 "+ $*"; "$@"; }
46
47 trouble=false
48 trouble () { echo >&2 "***TROUBLE***: $*"; trouble=true; }
49
50 #---------- checks ----------
51
52 version=$(perl <Cargo.toml -ne '
53     next unless m{^version\s*=\s*\"([0-9.]+)\"\s*$};
54     print "$1\n" or die $!;
55     exit 0;
56 ')
57
58 case "$version" in
59 '') fail "no version?" ;;
60 esac
61
62 echo "version $version"
63
64 equals () {
65     diff <(git rev-parse refs/heads/$1) <(git rev-parse HEAD) \
66         || trouble "HEAD not equal to $1"
67 }
68
69 equals $branch
70 equals tested
71
72 bad=$(git status --porcelain)
73 if [ "x$bad" != x ]; then
74     printf >&2 '%s\n' "$bad"
75     trouble 'tree is dirty'
76 fi
77
78 tag="otter-$version"
79 tag_exists=$(git for-each-ref "[r]efs/tags/$tag")
80 if [ "x$tag_exists" != x ]; then trouble "tag $tag already exists"; fi
81
82 head -1 CHANGELOG.md | grep "^Version $version" \
83 || trouble "CHANGELOG.md not updated"
84
85 cargo_order='base . cli daemon wasm apitest wdriver jstest'
86 missing=(git ls-files :\*/Cargo.toml :Cargo.toml)
87 for x in $cargo_order; do missing+=(:!$x/Cargo.toml); done
88 missing=$( "${missing[@]}" )
89 if [ "x$missing" != x ]; then trouble "missing cargo package(s) $missing"; fi
90
91 #---------- end of checks ----------
92
93 if $trouble; then
94     $dryrun fail "trouble! checks failed!"
95 else
96     echo 'checks passed'
97 fi
98
99 #---------- actually do the work ----------
100
101 $dryrun git push chiark $branch
102 $dryrun git push origin $branch
103
104 #---------- non-idempotent things ----------
105
106 $dryrun make -j12 publish
107
108 $dryrun git tag -s -u "$keyid" -m "Otter v$version" $tag
109 $dryrun git push chiark $tag
110 $dryrun git push origin $tag
111
112 #---------- oh woe cargo ----------
113
114 # https://github.com/rust-lang/cargo/issues/9507
115 wait_for_crates_io () {
116     local p=$1
117     local delay=1
118     local url="$cratesio_raw_url/${p:0:2}/${p:2:2}/$p"
119     printf >&2 "waiting for upload of %s to take effect" "$p"
120     while sleep $delay; do
121         printf >&2 .
122         local got=$(
123             curl -sS "$url" | jq '.vers | select(. == "'"$version"'")'
124         )
125         if [ "x$got" != x ]; then break; fi
126         delay=$(( $delay * 11 / 10 + 1 ))
127     done
128     echo >&2 'done'
129 }
130
131 for cargo_dir in $cargo_order; do
132     $dryrun_no_more_cargo \
133     nailing-cargo --no-nail --linkfarm=git --- \
134         sh -xec "
135           find . ! -type l ! -type d ! -path './target/*' -print0 \
136               | xargs -0r rm --
137           cd $cargo_dir; cargo publish $cargo_dryrun
138         "
139
140     cargo_package=$(
141         sed -n '/^name *=/ { s/^name *= *"\(.*\)" *$/\1/; p; q }' \
142             <$cargo_dir/Cargo.toml
143     )
144
145     wait_for_crates_io "$cargo_package"
146
147     dryrun_no_more_cargo=$dryrun
148
149 done
150
151 #---------- finish ----------
152
153 $dryrun cat <<END
154
155
156 Successfully released to
157   - git tags
158   - all git branches
159   - cargo publish
160
161 Consider
162   - make deploy
163
164 You need to write release announcements
165   - sgo-software-announce
166   - blog
167
168 END