chiark / gitweb /
make-release: Fix git tag rune
[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
66 cargo_order='base . daemon wasm apitest wdriver'
67 missing=(git ls-files :\*/Cargo.toml :Cargo.toml)
68 for x in $cargo_order; do missing+=(:!$x/Cargo.toml); done
69 missing=$( "${missing[@]}" )
70 if [ "x$missing" != x ]; then trouble "missing cargo package(s) $missing"; fi
71
72 #---------- end of checks ----------
73
74 if $trouble; then
75     $dryrun fail "trouble! checks failed!"
76 else
77     echo 'checks passed'
78 fi
79
80 #---------- actually do the work ----------
81
82 $dryrun git push chiark $branch
83 $dryrun git push origin $branch
84
85 #---------- non-idempotent things ----------
86
87 $dryrun make -j12 publish
88
89 $dryrun git tag -s -u "$keyid" -m "Otter v$version" $tag
90 $dryrun git push chiark $tag
91 $dryrun git push origin $tag
92
93
94 for cargo_dir in $cargo_order; do
95     $dryrun_no_more_cargo \
96     nailing-cargo --no-nail --linkfarm=git --- \
97         sh -xec "cd $cargo_dir; cargo publish $cargo_dryrun"
98     dryrun_no_more_cargo=$dryrun
99 done
100
101 #---------- finish ----------
102
103 $dryrun cat <<END
104
105
106 Successfully released to
107   - git tags
108   - all git branches
109   - cargo publish
110
111 Consider
112   - make deploy
113
114 You need to write release announcements
115   - sgo-software-announce
116   - blog
117
118 END