4 # ./make-release --dry-run|--real <branch>
6 # ./make-release --dry-run main
8 #---------- argument parsing and options ----------
13 fail () { echo >&2 "${0##*/}: error: $*"; exit 12; }
15 dryrun=x-dry-run-unset
16 cargo_dryrun=--not-a-cargo-option-please-crash
19 2.--real) dryrun=x ; cargo_dryrun='' ; ;;
20 2.--dry-run) dryrun=dryrun; cargo_dryrun='--dry-run'; ;;
21 *) fail "bad usage" ;;
24 keyid=0x559AE46C2D6B6D3265E7CBA1E3E3392348B50D39
27 https://raw.githubusercontent.com/rust-lang/crates.io-index/master
31 dryrun () { echo "WOULD $*"; }
32 x () { echo >&2 "+ $*"; "$@"; }
35 trouble () { echo >&2 "***TROUBLE***: $*"; trouble=true; }
37 #---------- checks ----------
39 version=$(perl <Cargo.toml -ne '
40 next unless m{^version\s*=\s*\"([0-9.]+)\"\s*$};
41 print "$1\n" or die $!;
46 '') fail "no version?" ;;
49 echo "version $version"
52 diff <(git rev-parse refs/heads/$1) <(git rev-parse HEAD) \
53 || trouble "HEAD not equal to $1"
59 bad=$(git status --porcelain)
60 if [ "x$bad" != x ]; then
61 printf >&2 '%s\n' "$bad"
62 trouble 'tree is dirty'
66 tag_exists=$(git for-each-ref "[r]efs/tags/$tag")
67 if [ "x$tag_exists" != x ]; then trouble "tag $tag already exists"; fi
69 head -1 CHANGELOG.md | grep "^Version $version" \
70 || trouble "CHANGELOG.md not updated"
72 cargo_order='base . cli daemon wasm apitest wdriver'
73 missing=(git ls-files :\*/Cargo.toml :Cargo.toml)
74 for x in $cargo_order; do missing+=(:!$x/Cargo.toml); done
75 missing=$( "${missing[@]}" )
76 if [ "x$missing" != x ]; then trouble "missing cargo package(s) $missing"; fi
78 #---------- end of checks ----------
81 $dryrun fail "trouble! checks failed!"
86 #---------- actually do the work ----------
88 $dryrun git push chiark $branch
89 $dryrun git push origin $branch
91 #---------- non-idempotent things ----------
93 $dryrun make -j12 publish
95 $dryrun git tag -s -u "$keyid" -m "Otter v$version" $tag
96 $dryrun git push chiark $tag
97 $dryrun git push origin $tag
99 #---------- oh woe cargo ----------
101 # https://github.com/rust-lang/cargo/issues/9507
102 wait_for_crates_io () {
105 local url="$cratesio_raw_url/${p:0:2}/${p:2:2}/$p"
106 printf >&2 "waiting for upload of %s to take effect" "$p"
107 while sleep $delay; do
110 curl -sS "$url" | jq '.vers | select(. == "'"$version"'")'
112 if [ "x$got" != x ]; then break; fi
113 delay=$(( $delay * 11 / 10 + 1 ))
118 for cargo_dir in $cargo_order; do
119 $dryrun_no_more_cargo \
120 nailing-cargo --no-nail --linkfarm=git --- \
122 find . ! -type l ! -type d ! -path './target/*' -print0 \
124 cd $cargo_dir; cargo publish $cargo_dryrun
128 sed -n '/^name *=/ { s/^name *= *"\(.*\)" *$/\1/; p; q }' \
129 <$cargo_dir/Cargo.toml
132 wait_for_crates_io "$cargo_package"
134 dryrun_no_more_cargo=$dryrun
138 #---------- finish ----------
143 Successfully released to
151 You need to write release announcements
152 - sgo-software-announce