forked from printfn/fend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·262 lines (220 loc) · 8.16 KB
/
deploy.sh
File metadata and controls
executable file
·262 lines (220 loc) · 8.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
cd ..
USAGE="Usage: ./deploy.sh [flags] <version>
<version> should be the new version number to release, e.g. 0.1.0
Flags:
-h --help show this help screen"
NEW_VERSION=""
while [[ "$#" != 0 ]]; do
arg="$1"
if [[ "$arg" == "-h" || "$arg" == "--help" ]]; then
echo "$USAGE"
exit
elif [[ "$arg" =~ ^- ]]; then
echo "error: unknown option '$arg'" >&2
exit 1
elif [[ "$NEW_VERSION" == "" ]]; then
NEW_VERSION="$arg"
else
echo "error: too many arguments" >&2
exit 1
fi
shift
done
if [[ "$NEW_VERSION" == "" ]] ; then
echo "$USAGE" >&2
exit 1
fi
fail() {
echo "$1"
exit 1
}
checkversion() {
echo "$1" | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$" >/dev/null \
|| fail "Invalid version"
}
confirm() {
echo "$1"
read -r -p "Press enter to confirm, or Ctrl-C to cancel"
echo
}
manualstep() {
echo
echo "Manual step:"
confirm "$1"
}
gitdiff() {
local gitdir="$1"
local expected_add_count="$2"
local expected_del_count="$3"
# checks the expected number of lines + files are different
local added_lines
added_lines="$(git -C "$gitdir" --no-pager diff|grep -c '^+')"
if [[ "$added_lines" != "$expected_add_count" ]]; then
fail "Expected $expected_add_count lines+files to be different (+)"
fi
local removed_lines
removed_lines="$(git -C "$gitdir" --no-pager diff|grep -c '^-')"
if [[ "$removed_lines" != "$expected_del_count" ]]; then
fail "Expected $expected_del_count lines+files to be different (-)"
fi
}
checkversion "$NEW_VERSION"
current_branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$current_branch" != "main" ]]; then
echo "Error: not on main branch"
fi
OLD_VERSION="$(cargo run --package fend --quiet -- version)"
if ! command -v "wasm-pack" >/dev/null; then
fail "Please install wasm-pack"
fi
confirm "Releasing update $OLD_VERSION -> $NEW_VERSION. \
Update the README file and other documentation if necessary."
echo "Updating Cargo.lock" # also ensures the internet connection works
cargo update
echo "Running cargo fmt..."
cargo fmt -- --check
echo "Making sure we are logged in to npm..."
npm adduser # `npm whoami` returns success even if the auth token is invalid/expired
echo "Making sure we are logged in to crates.io..."
cargo owner --list fend >/dev/null
PATH="${XDG_DATA_HOME-$HOME/.local/share}/cargo/bin:$PATH"
echo "Ensure that we are using Rustup"
rustc_cmd=$(command -v rustc)
if [[ ! "$rustc_cmd" =~ .(cargo|rustup)/bin/rustc$ ]]; then
fail "Using $rustc_cmd which does not seem to be from Rustup"
fi
echo "Making sure the git repository is clean..."
# from https://stackoverflow.com/a/5143914
git update-index --refresh &>/dev/null || true
if ! git diff-index --quiet HEAD --; then
fail "The local repository has uncommitted changes"
fi
echo "Bumping version numbers..."
# fend workspace Cargo.toml x2
sed "s/^version = \"$OLD_VERSION\"$/version = \"$NEW_VERSION\"/" \
Cargo.toml | \
sed "s/^fend-core = { version = \"$OLD_VERSION\"/fend-core = { version = \"$NEW_VERSION\"/" >temp
mv temp Cargo.toml
gitdiff "" 3 3
manualstep "Add changelog to CHANGELOG.md"
echo "Extracted changelog:"
CHANGELOG=$(tr "\n" "\1" <CHANGELOG.md \
| grep --text -o "### v$NEW_VERSION .*### v$OLD_VERSION" \
| tr "\1" "\n" \
| tail +3 \
| sed "\$d" \
| sed "\$d")
echo "$CHANGELOG"
manualstep "Make sure this is the correct changelog"
echo "Building and running tests..."
cargo clippy --workspace --all-targets --all-features
cargo build
cargo run -- version
cargo test --all
echo "'cargo run -- version'"
cargo run -q -- version
cargo run -q -- version | grep "$NEW_VERSION" \
|| fail "cargo run -- version returned the wrong version"
echo "Committing..."
git add -A
git --no-pager diff --cached
echo "'git commit -am \"Release version $NEW_VERSION\"'"
git commit -am "Release version $NEW_VERSION"
RELEASE_COMMIT_HASH=$(git rev-parse main)
git status
echo "'git push origin main'"
git push origin main
echo "Waiting for CI to start..."
sleep 5
GH_RUN_ID=$(gh run list --json databaseId,headSha --jq ".[] \
| select(.headSha == \"$RELEASE_COMMIT_HASH\") | .databaseId")
manualstep "Wait for GitHub CI to pass"
echo "cargo publish for fend-core"
(cd core && cargo publish)
echo "Sleeping for 30 seconds to let crates.io update"
sleep 30
echo "cargo publish for fend"
(cd cli && cargo publish)
echo "Tag and push tag to GitHub"
git tag "v$NEW_VERSION"
git push --tags
echo "Building NPM package fend-wasm"
rm -rfv wasm/pkg
(cd wasm && wasm-pack build)
grep 'fend_wasm_bg.js' wasm/pkg/package.json
(cd wasm/pkg && npm publish --dry-run 2>&1)|grep "total files:"|grep 6
echo "Publishing npm package"
(cd wasm/pkg && npm publish)
echo "Building NPM package fend-wasm-web"
rm -rfv wasm/pkgweb
(cd wasm && wasm-pack build --target web --out-dir pkgweb)
echo "Renaming package to 'fend-wasm-web' and removing 'sideEffects: false'..."
jq "setpath([\"name\"]; \"fend-wasm-web\") | del(.sideEffects)" \
wasm/pkgweb/package.json >temp
mv temp wasm/pkgweb/package.json
(cd wasm/pkgweb && npm publish)
TMPDIR="$(mktemp -d)"
if [[ ! -d "$TMPDIR" ]]; then
>&2 echo "Failed to create temp directory"
exit 1
fi
echo "Created temporary directory $TMPDIR"
manualstep "Ensure GitHub CI has finished and all artifacts are available"
echo "Downloading Github artifacts..."
gh run download "$GH_RUN_ID" --dir "$TMPDIR/artifacts"
echo "Zipping artifacts..."
# --junk-paths prevents directory names from being stored in the zip file,
# so the binary is stored at the top level
zip --junk-paths "$TMPDIR/artifacts/fend-$NEW_VERSION-linux-x86_64-gnu.zip" \
"$TMPDIR/artifacts/fend-$NEW_VERSION-linux-x86_64-gnu/fend"
zip --junk-paths "$TMPDIR/artifacts/fend-$NEW_VERSION-linux-aarch64-gnu.zip" \
"$TMPDIR/artifacts/fend-$NEW_VERSION-linux-aarch64-gnu/fend"
zip --junk-paths "$TMPDIR/artifacts/fend-$NEW_VERSION-linux-x86_64-musl.zip" \
"$TMPDIR/artifacts/fend-$NEW_VERSION-linux-x86_64-musl/fend"
zip --junk-paths "$TMPDIR/artifacts/fend-$NEW_VERSION-macos-aarch64.zip" \
"$TMPDIR/artifacts/fend-$NEW_VERSION-macos-aarch64/fend"
zip --junk-paths "$TMPDIR/artifacts/fend-$NEW_VERSION-windows-x64-exe.zip" \
"$TMPDIR/artifacts/fend-$NEW_VERSION-windows-x64-exe/fend.exe"
cp "$TMPDIR/artifacts/fend-$NEW_VERSION-windows-x64-msi/fend-windows-x64.msi" \
"$TMPDIR/artifacts/fend-$NEW_VERSION-windows-x64.msi"
cp "$TMPDIR/artifacts/man-page/fend.1" \
"$TMPDIR/artifacts/fend.1"
echo "Creating GitHub release..."
CHANGELOG2=$'Changes in this version:\n\n'"$CHANGELOG"
gh release --repo printfn/fend \
create "v$NEW_VERSION" --title "Version $NEW_VERSION" \
--notes "$CHANGELOG2" \
--draft \
"$TMPDIR/artifacts/fend-$NEW_VERSION-linux-x86_64-gnu.zip" \
"$TMPDIR/artifacts/fend-$NEW_VERSION-linux-aarch64-gnu.zip" \
"$TMPDIR/artifacts/fend-$NEW_VERSION-linux-x86_64-musl.zip" \
"$TMPDIR/artifacts/fend-$NEW_VERSION-macos-aarch64.zip" \
"$TMPDIR/artifacts/fend-$NEW_VERSION-windows-x64-exe.zip" \
"$TMPDIR/artifacts/fend-$NEW_VERSION-windows-x64.msi" \
"$TMPDIR/artifacts/fend.1"
manualstep "Open https://github.com/printfn/fend/releases and check \
that the new release is correct. If it is, go ahead and publish it."
HASH=$(curl -L -o - "https://github.com/printfn/fend/archive/refs/tags/v$NEW_VERSION.tar.gz" \
| shasum -a 256 - \
| grep -o '[a-f0-9]\{64\}')
# AUR release
git clone ssh://aur@aur.archlinux.org/fend.git "$TMPDIR/fend-aur"
git -C "$TMPDIR/fend-aur" config user.name printfn
git -C "$TMPDIR/fend-aur" config user.email printfn@users.noreply.github.com
sed "s/$OLD_VERSION/$NEW_VERSION/g" "$TMPDIR/fend-aur/.SRCINFO" \
| sed "s/[a-f0-9]\{64\}/$HASH/" >"$TMPDIR/fend-aur/.SRCINFO_NEW"
sed "s/$OLD_VERSION/$NEW_VERSION/" "$TMPDIR/fend-aur/PKGBUILD" \
| sed "s/[a-f0-9]\{64\}/$HASH/" >"$TMPDIR/fend-aur/PKGBUILD_NEW"
mv "$TMPDIR/fend-aur/.SRCINFO_NEW" "$TMPDIR/fend-aur/.SRCINFO"
mv "$TMPDIR/fend-aur/PKGBUILD_NEW" "$TMPDIR/fend-aur/PKGBUILD"
gitdiff "$TMPDIR/fend-aur" 7 7 # 5 lines in 2 files
TZ=UTC git -C "$TMPDIR/fend-aur" commit -am "fend $OLD_VERSION -> $NEW_VERSION"
git -C "$TMPDIR/fend-aur" --no-pager log --pretty=full HEAD~.. \
| grep '^Author: printfn <printfn@users.noreply.github.com>$'
git -C "$TMPDIR/fend-aur" --no-pager log --pretty=full HEAD~.. \
| grep '^Commit: printfn <printfn@users.noreply.github.com>$'
git -C "$TMPDIR/fend-aur" push origin master
rm -rf "$TMPDIR"