chiark / gitweb /
New utility script make-release
[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=''    ; 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
29 trouble=false
30 trouble () { echo >&2 "***TROUBLE***: $*"; trouble=true; }
31
32 #---------- checks ----------
33
34 version=$(perl <Cargo.toml -ne '
35     next unless m{^version\s*=\s*\"([0-9.]+)\"\s*$};
36     print "$1\n" or die $!;
37     exit 0;
38 ')
39
40 case "$version" in
41 '') fail "no version?" ;;
42 esac
43
44 echo "version $version"
45
46 equals () {
47     diff <(git rev-parse refs/heads/$1) <(git rev-parse HEAD) \
48         || trouble "HEAD not equal to $1"
49 }
50
51 equals $branch
52 equals tested
53
54 bad=$(git status --porcelain)
55 if [ "x$bad" != x ]; then
56     printf >&2 '%s\n' "$bad"
57     trouble 'tree is dirty'
58 fi
59
60 tag="otter-$version"
61 tag_exists=$(git for-each-ref "[r]efs/tags/$tag")
62 if [ "x$tag_exists" != x ]; then trouble "tag $tag already exists"; fi
63
64
65 cargo_order='base . daemon wasm apitest wdriver'
66 missing=(git ls-files :\*/Cargo.toml :Cargo.toml)
67 for x in $cargo_order; do missing+=(:!$x/Cargo.toml); done
68 missing=$( "${missing[@]}" )
69 if [ "x$missing" != x ]; then trouble "missing cargo package(s) $missing"; fi
70
71 #---------- end of checks ----------
72
73 if $trouble; then
74     $dryrun fail "trouble! checks failed!"
75 else
76     echo 'checks passed'
77 fi
78
79 #---------- actually do the work ----------
80
81 $dryrun git push chiark $branch
82 $dryrun git push origin $branch
83
84 #---------- non-idempotent things ----------
85
86 $dryrun make -j12 publish
87
88 $dryrun git tag -s -u "$keyid" -m "Otter v$version"
89 $dryrun git push chiark $tag
90 $dryrun git push origin $tag
91
92
93 for cargo_dir in $cargo_order; do
94     $dryrun_no_more_cargo \
95     nailing-cargo --no-nail --linkfarm=git --- \
96         sh -xec "cd $cargo_dir; cargo publish $cargo_dryrun"
97     dryrun_no_more_cargo=$dryrun
98 done
99
100 #---------- finish ----------
101
102 $dryrun cat <<END
103 Successfully released to
104   - git tags
105   - all git branches
106   - cargo publish
107
108 You need to write release announcements
109   - sgo-software-announce
110   - blog
111 END