|
| 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 |
0 commit comments