-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjustfile
More file actions
186 lines (154 loc) · 6.77 KB
/
Copy pathjustfile
File metadata and controls
186 lines (154 loc) · 6.77 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
PREFIX := env_var_or_default('PREFIX', '/usr/local')
DESTDIR := env_var_or_default('DESTDIR', '')
BINDIR := PREFIX / 'bin'
DATADIR := PREFIX / 'share'
APPID := 'io.github.alyraffauf.Switchyard'
# Show available recipes
default:
@just --list
# Install development dependencies
install-deps:
sudo dnf install golang gtk4-devel glib2-devel gobject-introspection-devel libadwaita-devel just
# Install Flatpak dependencies
install-flatpak-deps:
flatpak install flathub org.gnome.Platform//50 org.gnome.Sdk//50 org.freedesktop.Sdk.Extension.golang//25.08
# Build the application
build:
go build -mod=mod -trimpath -ldflags="-s -w" -o switchyard ./cmd/switchyard
# Install to system
install: build
install -Dm755 switchyard {{DESTDIR}}{{BINDIR}}/switchyard
install -Dm644 data/{{APPID}}.desktop {{DESTDIR}}{{DATADIR}}/applications/{{APPID}}.desktop
install -Dm644 data/{{APPID}}.metainfo.xml {{DESTDIR}}{{DATADIR}}/metainfo/{{APPID}}.metainfo.xml
install -Dm644 data/icons/hicolor/scalable/apps/{{APPID}}.svg {{DESTDIR}}{{DATADIR}}/icons/hicolor/scalable/apps/{{APPID}}.svg
# Uninstall from system
uninstall:
rm -f {{DESTDIR}}{{BINDIR}}/switchyard
rm -f {{DESTDIR}}{{DATADIR}}/applications/{{APPID}}.desktop
rm -f {{DESTDIR}}{{DATADIR}}/metainfo/{{APPID}}.metainfo.xml
rm -f {{DESTDIR}}{{DATADIR}}/icons/hicolor/scalable/apps/{{APPID}}.svg
# Clean build artifacts
clean:
rm -f switchyard
# Update the bundled AdGuard tracking-parameter filter list
update-adguard:
curl -fsSL https://raw.githubusercontent.com/AdguardTeam/AdGuardFilters/master/TrackParamFilter/sections/general_url.txt -o internal/routing/embedded/adguard_filter.txt
@echo "Updated internal/routing/embedded/adguard_filter.txt"
# Set as default browser
set-default:
xdg-mime default {{APPID}}.desktop x-scheme-handler/http
xdg-mime default {{APPID}}.desktop x-scheme-handler/https
@echo "Switchyard is now your default browser"
# Update Go dependencies
update-go-deps:
go mod tidy
scripts/generate-flatpak-go-modules.py
# Run unit tests
test:
go test ./internal/...
# Run tests with coverage report
test-coverage:
@echo "Running tests with coverage..."
go test -coverprofile=coverage.out ./internal/...
go tool cover -func=coverage.out
@echo ""
@echo "To view HTML coverage report, run: go tool cover -html=coverage.out"
# Build and install Flatpak (development version)
flatpak:
[ -f build-repo/config ] || rm -rf build-repo
flatpak run org.flatpak.Builder --user --install --force-clean --repo=build-repo build-dir flatpak/{{APPID}}.Devel.yml
# Build Flatpak and export a .flatpak bundle for distribution
flatpak-bundle: flatpak
flatpak build-bundle build-repo switchyard.flatpak {{APPID}}.Devel
# Build the browser extension (TypeScript + React)
build-extension:
cd webextension && npm ci && npm run build
# Package the already-built extension as a Firefox-targeted directory
package-extension-firefox:
#!/usr/bin/env bash
set -euo pipefail
root="{{justfile_directory()}}"
extdir="${root}/webextension"
outdir="${root}/firefox-extension"
rm -rf "${outdir}"
mkdir -p "${outdir}"
cp -R "${extdir}/build" "${extdir}/icons" "${extdir}/popup.html" "${outdir}/"
rm -f "${outdir}/build/manifest.firefox.json"
cp "${extdir}/manifest.firefox.json" "${outdir}/manifest.json"
echo "Extension packaged: firefox-extension/"
# Package the already-built extension as a Chrome-targeted zip archive
package-extension-chrome:
#!/usr/bin/env bash
set -euo pipefail
root="{{justfile_directory()}}"
extdir="${root}/webextension"
outfile="${root}/switchyard-webextension-chrome.zip"
staging="$(mktemp -d)"
trap 'rm -rf "${staging}"' EXIT
rm -f "${outfile}"
cp -R "${extdir}/build" "${extdir}/icons" "${extdir}/popup.html" "${staging}/"
jq 'del(.key)' "${extdir}/manifest.json" > "${staging}/manifest.json"
cd "${staging}" && zip -r "${outfile}" .
echo "Extension bundled: switchyard-webextension-chrome.zip"
# Build the extension once and package it for both Firefox and Chrome
bundle-extension: build-extension package-extension-firefox package-extension-chrome
# Cut a new release: bump version, commit, tag, and push master + tag
release version:
#!/usr/bin/env bash
set -euo pipefail
version="{{version}}"
tag="v${version}"
metainfo="data/{{APPID}}.metainfo.xml"
manifest="webextension/manifest.json"
firefox_manifest="webextension/manifest.firefox.json"
pkgjson="webextension/package.json"
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
echo "error: '$version' is not valid semver (expected X.Y.Z)" >&2
exit 1
fi
branch="$(git symbolic-ref --short HEAD)"
if [ "$branch" != "master" ]; then
echo "error: must be on master (currently on $branch)" >&2
exit 1
fi
dirty="$(git status --porcelain -- ':!gtk/app.go' ":!${metainfo}" ":!${manifest}" ":!${firefox_manifest}" ":!${pkgjson}")"
if [ -n "$dirty" ]; then
echo "error: working tree has changes outside gtk/app.go, ${metainfo}, ${manifest}, ${firefox_manifest}, ${pkgjson}:" >&2
echo "$dirty" >&2
exit 1
fi
if git rev-parse --verify --quiet "refs/tags/${tag}" >/dev/null; then
echo "error: tag ${tag} already exists" >&2
exit 1
fi
if ! grep -q "<release version=\"${version}\"" "${metainfo}"; then
echo "error: ${metainfo} has no <release version=\"${version}\"> entry" >&2
echo " add a release entry with notes before running 'just release'" >&2
exit 1
fi
just test
sed -i -E "s/^(\s*Version\s*=\s*)\"[^\"]+\"/\1\"${version}\"/" gtk/app.go
if ! grep -qE "Version\s*=\s*\"${version}\"" gtk/app.go; then
echo "error: failed to update Version in gtk/app.go" >&2
exit 1
fi
sed -i -E 's/^(\s*"version"\s*:\s*)"[^"]+"/\1"'"${version}"'"/' "${manifest}"
if ! grep -qE '"version"\s*:\s*"'"${version}"'"' "${manifest}"; then
echo "error: failed to update version in ${manifest}" >&2
exit 1
fi
sed -i -E 's/^(\s*"version"\s*:\s*)"[^"]+"/\1"'"${version}"'"/' "${firefox_manifest}"
if ! grep -qE '"version"\s*:\s*"'"${version}"'"' "${firefox_manifest}"; then
echo "error: failed to update version in ${firefox_manifest}" >&2
exit 1
fi
sed -i -E 's/^(\s*"version"\s*:\s*)"[^"]+"/\1"'"${version}"'"/' "${pkgjson}"
if ! grep -qE '"version"\s*:\s*"'"${version}"'"' "${pkgjson}"; then
echo "error: failed to update version in ${pkgjson}" >&2
exit 1
fi
git add gtk/app.go "${metainfo}" "${manifest}" "${firefox_manifest}" "${pkgjson}"
git commit -m "update for ${tag}"
git tag -a "${tag}" -m "${tag}"
git push origin master
git push origin "${tag}"