Repository navigation
Expand file tree
/
Copy pathjustfile
More file actions
272 lines (251 loc) · 13.1 KB
/
Copy pathjustfile
File metadata and controls
272 lines (251 loc) · 13.1 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
263
264
265
266
267
268
269
270
271
272
set shell := ["bash", "-euo", "pipefail", "-c"]
set dotenv-load
# Cloudflare credentials (set these as environment variables)
CF_ZONE_ID := env_var_or_default("CF_ZONE_ID", "")
CF_API_TOKEN := env_var_or_default("CF_API_TOKEN", "")
CF_HOST := env_var_or_default("CF_HOST", "")
host := os()
version := `sed -n 's/^version: \([^+]*\)+.*/\1/p' pubspec.yaml`
default:
@just --list
# Analyze (errors/warnings fatal, infos tolerated) and run the tests
test:
flutter analyze --no-fatal-infos
flutter test
# Print the code version and the latest tag
version:
@echo "code: {{version}}"
@echo "tag: $(git describe --tags --abbrev=0 2>/dev/null || echo none)"
# Run for development: macos | linux | android | ios | web (default: current platform)
dev target=host:
#!/usr/bin/env bash
set -euo pipefail
case "{{target}}" in
macos) flutter run -d macos ;;
linux) flutter run -d linux ;;
android) flutter run -d Pixel ;;
ios) open -a Simulator; flutter run -d iPhone ;;
web)
export CHROME_EXECUTABLE=/Applications/Chromium.app/Contents/MacOS/Chromium
flutter run -d chrome --web-port 8080 ;;
*) echo "unknown target: {{target}} (macos | linux | android | ios | web)"; exit 1 ;;
esac
# Build a release artifact: macos | android | android-bundle | ios | linux | web (default: current platform)
build target=host:
#!/usr/bin/env bash
set -euo pipefail
case "{{target}}" in
macos)
flutter build macos --release
./scripts/macos_verify_signature.sh build/macos/Build/Products/Release/Manent.app ;;
android)
flutter build apk --release --split-per-abi --obfuscate --split-debug-info=build/symbols/android ;;
android-bundle)
flutter build appbundle --release --obfuscate --split-debug-info=build/symbols/android ;;
ios)
flutter build ipa --release --obfuscate --split-debug-info=build/symbols/ios
cp build/ios/ipa/*.ipa dist/ ;;
linux)
# Runtime dependency: mpv-libs (Fedora) / libmpv2 (Debian/Ubuntu)
flutter build linux --release
tar -czf dist/manent-{{version}}-linux-x64.tar.gz -C "$(ls -d build/linux/*/release/bundle)" .
echo -e "\nArtifact saved in dist/manent-{{version}}-linux-x64.tar.gz" ;;
web)
flutter build web --release ;;
*) echo "unknown target: {{target}} (macos | android | android-bundle | ios | linux | web)"; exit 1 ;;
esac
# Wrap a build into distro packages; same packaging as the github workflow: linux (deb+rpm, needs fpm)
package target=host: (build target)
#!/usr/bin/env bash
set -euo pipefail
[[ "{{target}}" == "linux" ]] || { echo "unknown target: {{target}} (linux)"; exit 1; }
BUNDLE_DIR=$(ls -d build/linux/*/release/bundle)
PKG=build/linux-pkg
rm -rf "$PKG"
mkdir -p "$PKG"/usr/lib/manent "$PKG"/usr/bin \
"$PKG"/usr/share/applications "$PKG"/usr/share/icons/hicolor/1024x1024/apps
cp -r "$BUNDLE_DIR"/. "$PKG"/usr/lib/manent/
ln -s ../lib/manent/manent "$PKG"/usr/bin/manent
cp linux/packaging/manent.desktop "$PKG"/usr/share/applications/
cp assets/icon.png "$PKG"/usr/share/icons/hicolor/1024x1024/apps/manent.png
fpm -f -s dir -t deb -n manent -v "{{version}}" -a native \
--description "Sync encrypted notes and files between devices via Nostr" \
--url "https://github.com/dtonon/manent" \
--depends libmpv2 --depends libsecret-1-0 --depends pulseaudio-utils \
-p dist/manent-{{version}}-linux-x64.deb -C "$PKG" usr
fpm -f -s dir -t rpm -n manent -v "{{version}}" -a native \
--description "Sync encrypted notes and files between devices via Nostr" \
--url "https://github.com/dtonon/manent" \
--depends mpv-libs --depends libsecret --depends pulseaudio-utils \
-p dist/manent-{{version}}-linux-x64.rpm -C "$PKG" usr
echo -e "\nArtifacts saved in dist/manent-{{version}}-linux-x64.{deb,rpm}"
# Build on the github runners: linux | windows
gh_build target:
@[[ "{{target}}" == "linux" || "{{target}}" == "windows" ]] || { echo "unknown target: {{target}} (linux | windows)"; exit 1; }
gh workflow run {{target}}-release.yml --ref master
@echo -e "\nFollow the build with: gh run watch"
# Fetch a github build into dist/ as manent-<version>-<target>-x64.*: linux | windows (default: latest successful run)
gh_fetch target run_id="":
#!/usr/bin/env bash
set -euo pipefail
[[ "{{target}}" == "linux" || "{{target}}" == "windows" ]] || { echo "unknown target: {{target}} (linux | windows)"; exit 1; }
id="{{run_id}}"
[[ -n "$id" ]] || id=$(gh run list --workflow={{target}}-release.yml --status success -L1 --json databaseId -q '.[0].databaseId')
[[ -n "$id" ]] || { echo "no successful {{target}} run found"; exit 1; }
tmp=$(mktemp -d)
gh run download "$id" -n manent-{{target}}-x64 -D "$tmp"
rm -f dist/manent-{{version}}-{{target}}-x64.*
mv "$tmp"/manent-{{version}}-{{target}}-x64.* dist/
rm -rf "$tmp"
ls -1 dist/manent-{{version}}-{{target}}-x64.*
# Wait for the github build triggered by the current tag and fetch it into dist/: linux | windows
gh_wait target:
#!/usr/bin/env bash
set -euo pipefail
[[ "{{target}}" == "linux" || "{{target}}" == "windows" ]] || { echo "unknown target: {{target}} (linux | windows)"; exit 1; }
tag="v{{version}}"
id=$(gh run list --workflow={{target}}-release.yml --event push --branch "$tag" -L1 --json databaseId -q '.[0].databaseId')
[[ -n "$id" ]] || { echo "no {{target}} run for $tag, dispatch one with: just gh_build {{target}}"; exit 1; }
echo "Waiting for the {{target}} build of $tag (run $id)..."
gh run watch "$id" --exit-status > /dev/null || { echo "{{target}} build failed: $(gh run view "$id" --json url -q .url)"; exit 1; }
just gh_fetch {{target}} "$id"
# Second isolated instance (own bundle id → own data dir/prefs), handy for sync tests
test_instance_macos:
rm -rf dist/Manent-Test.app
cp -R build/macos/Build/Products/Release/Manent.app dist/Manent-Test.app
plutil -replace CFBundleIdentifier -string com.dtonon.manent.test dist/Manent-Test.app/Contents/Info.plist
plutil -replace CFBundleName -string Manent-Test dist/Manent-Test.app/Contents/Info.plist
codesign --force --deep --sign - dist/Manent-Test.app
open dist/Manent-Test.app
# Build the local release artifacts as dist/manent-<version>-* (linux/windows come from CI, see gh_wait)
dist: (build "macos") (build "android") (build "web")
#!/usr/bin/env bash
set -euo pipefail
rm -f dist/manent-{{version}}-*
tar --format zip --options zip:compression=deflate,zip:compression-level=9 -cf dist/manent-{{version}}-web.zip -s '|^build/web|manent-{{version}}-web|' build/web
ditto -c -k --keepParent build/macos/Build/Products/Release/Manent.app dist/manent-{{version}}-macos.zip
for apk in build/app/outputs/flutter-apk/app-*-release.apk; do
abi=$(basename "$apk" | sed 's/^app-\(.*\)-release\.apk$/\1/')
cp "$apk" "dist/manent-{{version}}-android-$abi.apk"
done
ls -1 dist/manent-{{version}}-*
# Add an entry to the changelog: just log "Fix video playback on Linux"
log entry:
#!/usr/bin/env bash
set -euo pipefail
grep -q '^## \[Unreleased\]' CHANGELOG.md || { echo "no Unreleased section in CHANGELOG.md"; exit 1; }
ENTRY={{quote(entry)}} awk '
/^## \[Unreleased\]/ {print; print ""; print "- " ENVIRON["ENTRY"]; ins=1; next}
ins && /^$/ {next}
ins && /^## / {print ""; print; ins=0; next}
ins {print; ins=0; next}
{print}
' CHANGELOG.md > CHANGELOG.md.tmp && mv CHANGELOG.md.tmp CHANGELOG.md
echo "Unreleased is now:"
awk '/^## \[Unreleased\]/{f=1;next} /^## \[/{f=0} f' CHANGELOG.md
# Bump the version and changelog, commit and tag (no push)
release VERSION:
#!/usr/bin/env bash
set -euo pipefail
v="{{VERSION}}"
[[ "$v" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "version must be X.Y.Z"; exit 1; }
[[ -z "$(git status --porcelain)" ]] || { echo "working tree not clean"; exit 1; }
! git rev-parse -q --verify "refs/tags/v$v" >/dev/null || { echo "tag v$v exists"; exit 1; }
grep -q '^## \[Unreleased\]' CHANGELOG.md || { echo "no Unreleased section in CHANGELOG.md"; exit 1; }
[[ -n "$(awk '/^## \[Unreleased\]/{f=1;next} /^## \[/{f=0} f && /^- /' CHANGELOG.md)" ]] || { echo "no entries under Unreleased in CHANGELOG.md"; exit 1; }
just test
build=$(sed -n 's/^version: .*+//p' pubspec.yaml)
sed -i '' "s/^version: .*/version: $v+$((build + 1))/" pubspec.yaml
sed -i '' "s/^## \[Unreleased\]/## [Unreleased]\n\n## [$v] - $(date +%Y-%m-%d)/" CHANGELOG.md
git add pubspec.yaml CHANGELOG.md
git commit -m "Release v$v"
git tag -a "v$v" -m "v$v"
echo "Released v$v, push with: git push --follow-tags"
# Create the GitHub release for the current version with all the artifacts attached; `just publish draft` for a draft
publish MODE="":
#!/usr/bin/env bash
set -euo pipefail
v="{{version}}"; tag="v$v"
[[ -z "$(git status --porcelain)" ]] || { echo "working tree not clean"; exit 1; }
git rev-parse -q --verify "refs/tags/$tag" >/dev/null || { echo "tag $tag not found, run: just release $v"; exit 1; }
[[ -n "$(git ls-remote --tags origin "$tag")" ]] || { echo "tag $tag not on origin, run: git push --follow-tags"; exit 1; }
notes="$(awk -v h="## [$v]" 'index($0,h)==1{f=1;next} /^## \[/{f=0} f' CHANGELOG.md)"
just dist
just gh_wait linux
just gh_wait windows
ls -1 dist/manent-"$v"-*
if gh release view "$tag" > /dev/null 2>&1; then
gh release edit "$tag" --title "$tag" --notes "$notes"
gh release upload "$tag" dist/manent-"$v"-* --clobber
else
draft=""
[[ "{{MODE}}" != "draft" ]] || draft="--draft"
gh release create "$tag" dist/manent-"$v"-* --title "$tag" --notes "$notes" $draft
fi
# Release, push, publish and deploy the web app in one go: `just ship X.Y.Z [draft] [host]`
ship VERSION MODE="" HOST="":
#!/usr/bin/env bash
set -euo pipefail
mode="{{MODE}}"; host="{{HOST}}"
[[ "$mode" == "draft" || -z "$mode" ]] || { host="$mode"; mode=""; }
just release {{VERSION}}
git push --follow-tags
just publish "$mode"
if [[ -n "$host" ]]; then
echo -e "\nDeploying the web app to $host..."
rsync -av --delete --progress build/web/ "$host":~/manent/
just purge-web-cache
else
echo -e "\nRemember to deploy the web app: just deploy web <host>"
fi
# Undo the last release: `just undo release` (local only) | `just undo ship` (also deletes the github release and remote tag)
undo action:
#!/usr/bin/env bash
set -euo pipefail
v="{{version}}"; tag="v$v"
[[ "{{action}}" == "release" || "{{action}}" == "ship" ]] || { echo "unknown action: {{action}} (release | ship)"; exit 1; }
[[ "$(git log -1 --format=%s)" == "Release $tag" ]] || { echo "last commit is not 'Release $tag', nothing to undo"; exit 1; }
[[ -z "$(git status --porcelain)" ]] || { echo "working tree not clean"; exit 1; }
on_origin="$(git ls-remote --tags origin "$tag")"
if [[ "{{action}}" == "release" ]]; then
[[ -z "$on_origin" ]] || { echo "tag $tag is already on origin, use: just undo ship"; exit 1; }
read -r -p "Undo local release $tag (drop the tag and reset the last commit)? [y/N] " a
[[ "$a" == "y" || "$a" == "Y" ]] || exit 1
else
read -r -p "Undo shipped $tag (delete the github release and remote tag, force-push the removal)? [y/N] " a
[[ "$a" == "y" || "$a" == "Y" ]] || exit 1
! gh release view "$tag" > /dev/null 2>&1 || gh release delete "$tag" --yes
[[ -z "$on_origin" ]] || git push origin ":refs/tags/$tag"
fi
! git rev-parse -q --verify "refs/tags/$tag" > /dev/null || git tag -d "$tag"
git reset --hard HEAD~1
if [[ "{{action}}" == "ship" ]]; then
git push --force-with-lease origin master
echo "Shipped $tag undone; note that anyone who already fetched the tag keeps it"
else
echo "Release $tag undone"
fi
# Deploy to a live environment: android (adb) | web (rsync to HOST)
deploy target host="":
#!/usr/bin/env bash
set -euo pipefail
case "{{target}}" in
android)
just build android
echo -e "\nDeploying application..."
adb install build/app/outputs/flutter-apk/app-arm64-v8a-release.apk ;;
web)
[[ -n "{{host}}" ]] || { echo "usage: just deploy web <host>"; exit 1; }
just build web
echo -e "\nDeploying application..."
rsync -av --delete --progress build/web/ {{host}}:~/manent/
just purge-web-cache ;;
*) echo "unknown target: {{target}} (android | web)"; exit 1 ;;
esac
purge-web-cache:
@echo -e "\nPurging Cloudflare cache... for zone {{CF_ZONE_ID}}"
@curl -s -X POST "https://api.cloudflare.com/client/v4/zones/{{CF_ZONE_ID}}/purge_cache" \
-H "Authorization: Bearer {{CF_API_TOKEN}}" \
-H "Content-Type: application/json" \
--data '{"purge_everything": true}' \
| jq -r 'if .success then "✅ Cache purged successfully" else "‼️ Error: " + (.errors[0].message // "Unknown error") end'