Skip to content

Commit 436f898

Browse files
vmillet-devclaude
andauthored
Release check: clean install and update 1.0.0 to 1.0.1 tested in CI (#1447)
packages.yml packages the release binary as 1.0.0 and 1.0.1 with a key made for the run, installs 1.0.0 (NSIS, AppImage), refuses a 1.0.1 altered by one byte, then installs the whole one through the application's updater. Closes #1273 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U9wKqFskQrYXJ3B9dcPcRQ
1 parent 9d03e6a commit 436f898

3 files changed

Lines changed: 259 additions & 0 deletions

File tree

‎.github/scripts/installed.sh‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
# Whether version $1 is the one installed by `packages.yml`: the AppImage in place is that
3+
# version's file (Linux), or the per-user install says that version (Windows). An update under
4+
# Windows finishes in an installer of its own: waited for, two minutes at most.
5+
set -euo pipefail
6+
expected=$1
7+
case "$expected" in
8+
1.0.0) packages=old ;;
9+
1.0.1) packages=new ;;
10+
*) echo "::error::no packages for $expected"; exit 2 ;;
11+
esac
12+
13+
if [ "$RUNNER_OS" = Linux ]; then
14+
installed="$RUNNER_TEMP/installed/DevNotes.AppImage"
15+
want=$(sha256sum "$packages"/*.AppImage | cut -d' ' -f1)
16+
have=$(sha256sum "$installed" | cut -d' ' -f1)
17+
if [ "$want" != "$have" ] || [ ! -x "$installed" ]; then
18+
echo "::error::the AppImage in place is not $expected"
19+
exit 1
20+
fi
21+
echo "installed: $expected"
22+
exit 0
23+
fi
24+
25+
# The uninstall entry the NSIS installer writes under HKCU, a field of it.
26+
entry() {
27+
pwsh -NoProfile -Command "(Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' -ErrorAction SilentlyContinue | Where-Object DisplayName -eq 'DevNotes').$1" | tr -d '\r"'
28+
}
29+
for _ in $(seq 1 120); do
30+
found=$(entry DisplayVersion)
31+
folder=$(entry InstallLocation)
32+
if [ "$found" = "$expected" ] && [ -f "$folder/devnotes.exe" ] && [ -f "$folder/identity/names.txt" ]; then
33+
echo "installed: $expected in $folder"
34+
exit 0
35+
fi
36+
sleep 1
37+
done
38+
echo "::error::installed: '${found:-nothing}', expected $expected"
39+
exit 1

‎.github/workflows/packages.yml‎

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
name: Packages
2+
3+
# The packages a release publishes, proven before a release depends on them (plan § 4.3 point 5):
4+
# built and signed as `release.yml` builds them, but with a key made for the run; installed on a
5+
# clean runner as 1.0.0; offered 1.0.1 by a `latest.json` served on the runner, first altered by
6+
# one byte — refused, nothing changes — then whole — installed. Both versions package the same
7+
# binary: what is tested is the package, the manifest, the signature and the client.
8+
on:
9+
pull_request:
10+
branches: [main, 'dev/**']
11+
paths:
12+
- 'Cargo.lock'
13+
- 'crates/app/Cargo.toml'
14+
- 'crates/app/packaging/**'
15+
- 'crates/platform/src/updater/**'
16+
- 'crates/platform/examples/update.rs'
17+
- 'scripts/latest-json.mjs'
18+
- '.github/actions/package/**'
19+
- '.github/workflows/packages.yml'
20+
- '.github/workflows/release.yml'
21+
workflow_dispatch:
22+
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.ref }}
25+
cancel-in-progress: true
26+
27+
permissions:
28+
contents: read
29+
30+
env:
31+
CARGO_TERM_COLOR: always
32+
33+
jobs:
34+
install-and-update:
35+
name: Install and update (${{ matrix.os }})
36+
runs-on: ${{ matrix.os }}
37+
timeout-minutes: 75
38+
defaults:
39+
run:
40+
shell: bash
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
os: [ubuntu-22.04, windows-latest]
45+
env:
46+
SERVED: ${{ github.workspace }}/served
47+
ORIGIN: http://127.0.0.1:8765
48+
steps:
49+
- uses: actions/checkout@v7
50+
51+
- uses: ./.github/actions/setup-rust
52+
with:
53+
shared-key: packages-${{ matrix.os }}
54+
save-if: 'true'
55+
56+
- uses: actions/setup-node@v7
57+
with:
58+
node-version-file: .nvmrc
59+
60+
# Before the versions change: the client is built against the lockfile as committed.
61+
- run: cargo build -p app --release --locked
62+
63+
- run: cargo build -p platform --example update --release --locked
64+
65+
- name: A signing key for this run alone
66+
id: key
67+
run: |
68+
cargo install --locked cargo-packager@0.11.8
69+
cargo packager signer generate --ci --path "$RUNNER_TEMP/test.key" --password test-only
70+
echo "public=$(cat "$RUNNER_TEMP/test.key.pub")" >> "$GITHUB_OUTPUT"
71+
{
72+
echo 'TEST_PRIVATE_KEY<<KEY_END'
73+
cat "$RUNNER_TEMP/test.key"
74+
echo
75+
echo 'KEY_END'
76+
} >> "$GITHUB_ENV"
77+
78+
# The one line of `[workspace.package]` that starts with `version`; Cargo.lock follows.
79+
- name: Version 1.0.0
80+
run: sed -i 's/^version = ".*"/version = "1.0.0"/' Cargo.toml && cargo metadata --format-version 1 > /dev/null
81+
82+
- uses: ./.github/actions/package
83+
with:
84+
private-key: ${{ env.TEST_PRIVATE_KEY }}
85+
password: test-only
86+
out: old
87+
88+
- name: Version 1.0.1
89+
run: sed -i 's/^version = ".*"/version = "1.0.1"/' Cargo.toml && cargo metadata --format-version 1 > /dev/null
90+
91+
- uses: ./.github/actions/package
92+
with:
93+
private-key: ${{ env.TEST_PRIVATE_KEY }}
94+
password: test-only
95+
out: new
96+
97+
# Two manifests for 1.0.1: one whose package is altered by one byte after signing, one
98+
# whole. Only the platform of this runner is checked; the manifest script wants both.
99+
- name: Serve 1.0.1, altered and whole
100+
run: |
101+
echo '- A test release' > "$RUNNER_TEMP/notes.md"
102+
for kind in altered whole; do
103+
mkdir -p "$SERVED/$kind"
104+
cp new/* "$SERVED/$kind/"
105+
# The manifest script refuses a release without Windows: a stand-in, never fetched.
106+
if [ "$RUNNER_OS" = Linux ]; then
107+
echo stand-in > "$SERVED/$kind/devnotes_1.0.1_x64-setup.exe"
108+
echo stand-in > "$SERVED/$kind/devnotes_1.0.1_x64-setup.exe.sig"
109+
fi
110+
node scripts/latest-json.mjs --dir "$SERVED/$kind" --version 1.0.1 \
111+
--base "$ORIGIN/$kind" --notes "$RUNNER_TEMP/notes.md"
112+
done
113+
if [ "$RUNNER_OS" = Windows ]; then
114+
package=$(ls "$SERVED/altered" | grep -- '-setup\.exe$')
115+
else
116+
package=$(ls "$SERVED/altered" | grep '\.AppImage$')
117+
fi
118+
python3 -c "import sys; p=sys.argv[1]; b=bytearray(open(p,'rb').read()); b[len(b)//2]^=1; open(p,'wb').write(b)" \
119+
"$SERVED/altered/$package"
120+
echo "altered: $package"
121+
(cd "$SERVED" && python3 -m http.server 8765 --bind 127.0.0.1 > "$RUNNER_TEMP/server.log" 2>&1 &)
122+
for _ in $(seq 1 30); do curl -sf "$ORIGIN/whole/latest.json" > /dev/null && break; sleep 1; done
123+
curl -sf "$ORIGIN/whole/latest.json"
124+
125+
- name: A clean install of 1.0.0
126+
run: |
127+
if [ "$RUNNER_OS" = Windows ]; then
128+
pwsh -NoProfile -Command "Start-Process '$(cygpath -w "$(ls old/*-setup.exe)")' -ArgumentList '/S' -Wait"
129+
else
130+
mkdir -p "$RUNNER_TEMP/installed"
131+
cp old/*.AppImage "$RUNNER_TEMP/installed/DevNotes.AppImage"
132+
chmod +x "$RUNNER_TEMP/installed/DevNotes.AppImage"
133+
fi
134+
.github/scripts/installed.sh 1.0.0
135+
136+
- name: The altered 1.0.1 is refused, 1.0.0 stays
137+
run: |
138+
set +e
139+
APPIMAGE="$RUNNER_TEMP/installed/DevNotes.AppImage" target/release/examples/update 1.0.0 \
140+
"$ORIGIN/altered/latest.json" '${{ steps.key.outputs.public }}'
141+
status=$?
142+
set -e
143+
if [ "$status" != 2 ]; then
144+
echo "::error::the altered package was not refused (exit $status)"
145+
exit 1
146+
fi
147+
.github/scripts/installed.sh 1.0.0
148+
149+
- name: The whole 1.0.1 is installed
150+
run: |
151+
APPIMAGE="$RUNNER_TEMP/installed/DevNotes.AppImage" target/release/examples/update 1.0.0 \
152+
"$ORIGIN/whole/latest.json" '${{ steps.key.outputs.public }}'
153+
.github/scripts/installed.sh 1.0.1
154+
155+
- name: Uninstall
156+
if: always() && runner.os == 'Windows'
157+
run: |
158+
taskkill //IM devnotes.exe //F 2>/dev/null || true
159+
folder=$(pwsh -NoProfile -Command "(Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' -ErrorAction SilentlyContinue | Where-Object DisplayName -eq 'DevNotes').InstallLocation" | tr -d '\r"')
160+
uninstaller="$folder/uninstall.exe"
161+
if [ -f "$uninstaller" ]; then
162+
pwsh -NoProfile -Command "Start-Process '$(cygpath -w "$uninstaller")' -ArgumentList '/S' -Wait"
163+
fi
164+
165+
- uses: actions/upload-artifact@v7
166+
if: failure()
167+
with:
168+
name: packages-${{ matrix.os }}
169+
path: |
170+
old
171+
new
172+
${{ runner.temp }}/server.log
173+
retention-days: 7

‎crates/platform/examples/update.rs‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! The updater of the application, run on an installed package by `packages.yml`:
2+
//! `update <running version> <latest.json URL> <public key>`. It checks, downloads, verifies and
3+
//! installs as the update prompt does; exits 2 when the signature refuses the file, 3 when
4+
//! nothing newer is offered.
5+
6+
use std::process::ExitCode;
7+
8+
use platform::updater::{DownloadError, Source};
9+
10+
fn main() -> ExitCode {
11+
let arguments: Vec<String> = std::env::args().skip(1).collect();
12+
let [version, endpoint, public_key] = arguments.as_slice() else {
13+
eprintln!("usage: update <running version> <latest.json URL> <public key>");
14+
return ExitCode::from(64);
15+
};
16+
let updater = platform::updater::system(&Source {
17+
version,
18+
endpoint,
19+
public_key,
20+
});
21+
match updater.check() {
22+
Ok(Some(update)) => println!("offered: {}", update.version),
23+
Ok(None) => {
24+
eprintln!("nothing newer than {version}");
25+
return ExitCode::from(3);
26+
}
27+
Err(error) => {
28+
eprintln!("check failed: {error}");
29+
return ExitCode::FAILURE;
30+
}
31+
}
32+
match updater.download(&|_| {}) {
33+
Ok(()) => println!("downloaded and verified"),
34+
Err(DownloadError::Refused(reason)) => {
35+
eprintln!("refused: {reason}");
36+
return ExitCode::from(2);
37+
}
38+
Err(DownloadError::Failed(reason)) => {
39+
eprintln!("download failed: {reason}");
40+
return ExitCode::FAILURE;
41+
}
42+
}
43+
// Under Windows the process ends in there, the installer running on its own.
44+
updater.install_and_relaunch();
45+
println!("installed");
46+
ExitCode::SUCCESS
47+
}

0 commit comments

Comments
 (0)