chiark / gitweb /
Break out clisupport.rs
[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 #---------- argument parsing and options ----------
9
10 set -e
11
12 fail () { echo >&2 "${0##*/}: error: $*"; exit 12; }
13
14 dryrun=x-dry-run-unset
15 cargo_dryrun=--not-a-cargo-option-please-crash
16
17 case "$#.$1" in
18 2.--real)    dryrun=x     ; cargo_dryrun=''         ; ;;
19 2.--dry-run) dryrun=dryrun; cargo_dryrun='--dry-run'; ;;
20 *)           fail "bad usage" ;;
21 esac
22
23 keyid=0x559AE46C2D6B6D3265E7CBA1E3E3392348B50D39
24
25 branch="$2"
26
27 dryrun () { echo "WOULD  $*"; }
28 x () { echo >&2 "+ $*"; "$@"; }
29
30 trouble=false
31 trouble () { echo >&2 "***TROUBLE***: $*"; trouble=true; }
32
33 #---------- checks ----------
34
35 version=$(perl <Cargo.toml -ne '
36     next unless m{^version\s*=\s*\"([0-9.]+)\"\s*$};
37     print "$1\n" or die $!;
38     exit 0;
39 ')
40
41 case "$version" in
42 '') fail "no version?" ;;
43 esac
44
45 echo "version $version"
46
47 equals () {
48     diff <(git rev-parse refs/heads/$1) <(git rev-parse HEAD) \
49         || trouble "HEAD not equal to $1"
50 }
51
52 equals $branch
53 equals tested
54
55 bad=$(git status --porcelain)
56 if [ "x$bad" != x ]; then
57     printf >&2 '%s\n' "$bad"
58     trouble 'tree is dirty'
59 fi
60
61 tag="otter-$version"
62 tag_exists=$(git for-each-ref "[r]efs/tags/$tag")
63 if [ "x$tag_exists" != x ]; then trouble "tag $tag already exists"; fi
64
65 head -1 CHANGELOG.md | grep "^Version $version" \
66 || trouble "CHANGELOG.md not updated"
67
68 cargo_order='base . cli daemon wasm apitest wdriver'
69 missing=(git ls-files :\*/Cargo.toml :Cargo.toml)
70 for x in $cargo_order; do missing+=(:!$x/Cargo.toml); done
71 missing=$( "${missing[@]}" )
72 if [ "x$missing" != x ]; then trouble "missing cargo package(s) $missing"; fi
73
74 #---------- end of checks ----------
75
76 if $trouble; then
77     $dryrun fail "trouble! checks failed!"
78 else
79     echo 'checks passed'
80 fi
81
82 #---------- actually do the work ----------
83
84 $dryrun git push chiark $branch
85 $dryrun git push origin $branch
86
87 #---------- non-idempotent things ----------
88
89 $dryrun make -j12 publish
90
91 $dryrun git tag -s -u "$keyid" -m "Otter v$version" $tag
92 $dryrun git push chiark $tag
93 $dryrun git push origin $tag
94
95
96 for cargo_dir in $cargo_order; do
97     $dryrun_no_more_cargo \
98     nailing-cargo --no-nail --linkfarm=git --- \
99         sh -xec "
100           find . ! -type l ! -type d ! -path './target/*' -print0 \
101               | xargs -0r rm --
102           cd $cargo_dir; cargo publish $cargo_dryrun
103         "
104     dryrun_no_more_cargo=$dryrun
105
106 done
107
108 #---------- finish ----------
109
110 $dryrun cat <<END
111
112
113 Successfully released to
114   - git tags
115   - all git branches
116   - cargo publish
117
118 Consider
119   - make deploy
120
121 You need to write release announcements
122   - sgo-software-announce
123   - blog
124
125 END