chiark / gitweb /
docs: Document new substitution syntax
[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 #  - edit CHANGELOG.md
13 #  - update versions
14 #  - ensure pretest == tested == main
15 #  - make deploy and test that chiark still works
16 #  - make-release
17 #  - release announcement to mailing list
18 #  - blog post
19
20 #---------- argument parsing and options ----------
21
22 set -e
23 set -o pipefail
24
25 fail () { echo >&2 "${0##*/}: error: $*"; exit 12; }
26
27 dryrun=x-dry-run-unset
28 cargo_dryrun=--not-a-cargo-option-please-crash
29
30 case "$#.$1" in
31 2.--real)    dryrun=x     ; cargo_dryrun=''         ; ;;
32 2.--dry-run) dryrun=dryrun; cargo_dryrun='--dry-run'; ;;
33 *)           fail "bad usage" ;;
34 esac
35
36 keyid=0x559AE46C2D6B6D3265E7CBA1E3E3392348B50D39
37
38 cratesio_raw_url=\
39 https://raw.githubusercontent.com/rust-lang/crates.io-index/master
40
41 branch="$2"
42
43 dryrun () { echo "WOULD  $*"; }
44 x () { echo >&2 "+ $*"; "$@"; }
45
46 trouble=false
47 trouble () { echo >&2 "***TROUBLE***: $*"; trouble=true; }
48
49 #---------- checks ----------
50
51 version=$(perl <Cargo.toml -ne '
52     next unless m{^version\s*=\s*\"([0-9.]+)\"\s*$};
53     print "$1\n" or die $!;
54     exit 0;
55 ')
56
57 case "$version" in
58 '') fail "no version?" ;;
59 esac
60
61 echo "version $version"
62
63 equals () {
64     diff <(git rev-parse refs/heads/$1) <(git rev-parse HEAD) \
65         || trouble "HEAD not equal to $1"
66 }
67
68 equals $branch
69 equals tested
70
71 bad=$(git status --porcelain)
72 if [ "x$bad" != x ]; then
73     printf >&2 '%s\n' "$bad"
74     trouble 'tree is dirty'
75 fi
76
77 tag="otter-$version"
78 tag_exists=$(git for-each-ref "[r]efs/tags/$tag")
79 if [ "x$tag_exists" != x ]; then trouble "tag $tag already exists"; fi
80
81 head -1 CHANGELOG.md | grep "^Version $version" \
82 || trouble "CHANGELOG.md not updated"
83
84 cargo_order='base . cli daemon wasm apitest wdriver jstest'
85 missing=(git ls-files :\*/Cargo.toml :Cargo.toml)
86 for x in $cargo_order; do missing+=(:!$x/Cargo.toml); done
87 missing=$( "${missing[@]}" )
88 if [ "x$missing" != x ]; then trouble "missing cargo package(s) $missing"; fi
89
90 #---------- end of checks ----------
91
92 if $trouble; then
93     $dryrun fail "trouble! checks failed!"
94 else
95     echo 'checks passed'
96 fi
97
98 #---------- actually do the work ----------
99
100 $dryrun git push chiark $branch
101 $dryrun git push origin $branch
102
103 #---------- non-idempotent things ----------
104
105 $dryrun make -j12 PUBLISH_VERSION=$version publish
106 $dryrun make -j12 PUBLISH_VERSION=$version publish-make-current
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 --preclean-build=src --linkfarm=git --- \
134         sh -xec "
135           cd $cargo_dir; cargo publish $cargo_dryrun
136         "
137
138     cargo_package=$(
139         sed -n '/^name *=/ { s/^name *= *"\(.*\)" *$/\1/; p; q }' \
140             <$cargo_dir/Cargo.toml
141     )
142
143     wait_for_crates_io "$cargo_package"
144
145     dryrun_no_more_cargo=$dryrun
146
147 done
148
149 #---------- finish ----------
150
151 $dryrun cat <<END
152
153
154 Successfully released to
155   - git tags
156   - all git branches
157   - cargo publish
158
159 Consider
160   - make deploy
161
162 You need to write release announcements
163   - sgo-software-announce
164   - blog
165
166 END