From dc06696e06f3e443a87ae207ce07266629ef073f Mon Sep 17 00:00:00 2001 From: NitroDiesel <228459919+NitroDiesel@users.noreply.github.com> Date: Fri, 13 Nov 2026 21:06:44 +0800 Subject: [PATCH] Harden CI installs, check version copies, add portable settings CI: retry apt installs when the Ubuntu mirror is unreachable and cap every job at 60 minutes, after a mirror outage failed or hung three Linux jobs. scripts/version.sh check, run in CI, fails when any of the hand-edited version copies disagrees with Cargo.toml; bump rewrites the plain strings. Windows: a settings.conf beside rufust.exe is used instead of %APPDATA%, so a portable copy can carry its preferences. .gitattributes keeps upstream's unchanged sources and the fixture generator out of GitHub's language statistics. Co-Authored-By: Claude --- .gitattributes | 4 ++ .github/workflows/ci.yml | 8 +++- .github/workflows/release.yml | 12 ++++-- README.md | 4 +- apps/rufust/src/settings.rs | 47 +++++++++++++++++++-- docs/PROJECT_CONTEXT.md | 6 +++ docs/WINDOWS.md | 3 +- packaging/windows/README.txt | 4 +- scripts/ci/apt-install.sh | 20 +++++++++ scripts/version.sh | 78 +++++++++++++++++++++++++++++++++++ 10 files changed, 173 insertions(+), 13 deletions(-) create mode 100644 .gitattributes create mode 100755 scripts/ci/apt-install.sh create mode 100755 scripts/version.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8c61c18 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +# Keep GitHub's language statistics to the project's own code. These folders +# hold upstream Rufus's unchanged sources and a one-off test-fixture generator. +crates/rufust-helper/assets/** linguist-vendored +scripts/fixtures/** linguist-vendored diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95d6d04..4e1c381 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,7 @@ env: jobs: quality: runs-on: ubuntu-24.04 + timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - uses: dtolnay/rust-toolchain@bc540ba06a4ccee415bb241490e0b25ee8e7d315 @@ -18,13 +19,14 @@ jobs: components: rustfmt, clippy - name: System dependencies run: | - sudo apt-get update - sudo apt-get install -y pkg-config libfontconfig1-dev libfreetype-dev \ + scripts/ci/apt-install.sh pkg-config libfontconfig1-dev libfreetype-dev \ libxkbcommon-dev libwayland-dev libx11-dev libxcb1-dev \ desktop-file-utils appstream libxml2-utils parted dosfstools qemu-utils libnbd-bin bzip2 \ xvfb xauth xdotool x11-utils imagemagick libgl1-mesa-dri \ libxkbcommon-x11-0 libxcursor1 libx11-xcb1 libxi6 \ libwayland-client0 libwayland-egl1 libgl1 libegl1 btrfs-progs strace + - name: Version consistency + run: scripts/version.sh check - name: Format run: cargo fmt --all -- --check - name: Test @@ -73,6 +75,7 @@ jobs: windows: name: Windows runs-on: windows-2022 + timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - uses: dtolnay/rust-toolchain@bc540ba06a4ccee415bb241490e0b25ee8e7d315 @@ -99,6 +102,7 @@ jobs: distro-builds: runs-on: ubuntu-24.04 + timeout-minutes: 60 strategy: fail-fast: false matrix: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f5d4c43..b2ba56f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,13 +26,13 @@ jobs: debian: name: Debian package runs-on: ubuntu-24.04 + timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - uses: dtolnay/rust-toolchain@bc540ba06a4ccee415bb241490e0b25ee8e7d315 - name: Install packaging dependencies run: | - sudo apt-get update - sudo apt-get install -y \ + scripts/ci/apt-install.sh \ debhelper devscripts fakeroot pkg-config \ libfontconfig1-dev libfreetype-dev libxkbcommon-dev \ libwayland-dev libx11-dev libxcb1-dev @@ -72,6 +72,7 @@ jobs: fedora: name: Fedora package runs-on: ubuntu-24.04 + timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - name: Build and validate Fedora installer @@ -129,6 +130,7 @@ jobs: arch: name: Arch package runs-on: ubuntu-24.04 + timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - name: Prepare source archive @@ -197,12 +199,12 @@ jobs: appimage: name: Portable AppImage runs-on: ubuntu-24.04 + timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - name: Install AppImage validation tools run: | - sudo apt-get update - sudo apt-get install -y \ + scripts/ci/apt-install.sh \ appstream binutils desktop-file-utils file libxkbcommon-x11-0 \ libxml2-utils xvfb zsync - name: Build against glibc 2.28 @@ -298,6 +300,7 @@ jobs: windows: name: Windows installer and portable executable runs-on: windows-2022 + timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - uses: dtolnay/rust-toolchain@bc540ba06a4ccee415bb241490e0b25ee8e7d315 @@ -379,6 +382,7 @@ jobs: startsWith(github.ref, 'refs/heads/release/v') needs: [debian, fedora, arch, appimage, windows] runs-on: ubuntu-24.04 + timeout-minutes: 60 permissions: contents: write id-token: write diff --git a/README.md b/README.md index 7fd5164..49ff06d 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,9 @@ For Windows 10/11 (x64), pick one download and check it against `SHA256SUMS`: - **Installer:** `rufust-*-windows-x86_64-setup.exe` installs Rufust in Program Files with a Start menu entry and an uninstaller (Settings → Apps). - **Portable:** run `rufust-*-windows-x86_64.exe` directly from anywhere, such - as a USB stick. Nothing is installed. + as a USB stick. Nothing is installed. To keep your settings with it, put an + empty file named `settings.conf` beside the exe; otherwise they are saved + in your Windows profile. ```powershell Get-FileHash .\rufust-*-windows-x86_64* -Algorithm SHA256 diff --git a/apps/rufust/src/settings.rs b/apps/rufust/src/settings.rs index d6b98ee..132c366 100644 --- a/apps/rufust/src/settings.rs +++ b/apps/rufust/src/settings.rs @@ -1,7 +1,10 @@ //! Preferences kept across launches as `key=value` lines in //! `$XDG_CONFIG_HOME/rufust/settings.conf` on Linux and -//! `%APPDATA%Rufustsettings.conf` on Windows. +//! `%APPDATA%\Rufust\settings.conf` on Windows, or a `settings.conf` that already +//! sits beside `rufust.exe` (portable use). +#[cfg(windows)] +use std::path::Path; use std::path::PathBuf; use crate::units::{SizeUnit, SpeedUnit}; @@ -100,9 +103,24 @@ fn path_in(dir: &str) -> Option { if dir == LEGACY_CONFIG_DIR { return None; } - let base = std::env::var_os("APPDATA") - .map(PathBuf::from) - .filter(|path| path.is_absolute())?; + windows_path( + std::env::current_exe().ok().as_deref(), + std::env::var_os("APPDATA").map(PathBuf::from), + ) +} + +/// A `settings.conf` beside the executable makes that copy portable: it is +/// read and written there, so preferences travel with a USB stick. Without +/// one, settings live under `%APPDATA%`. +#[cfg(windows)] +fn windows_path(exe: Option<&Path>, appdata: Option) -> Option { + let beside = exe + .and_then(Path::parent) + .map(|folder| folder.join("settings.conf")); + if let Some(beside) = beside.filter(|path| path.is_file()) { + return Some(beside); + } + let base = appdata.filter(|path| path.is_absolute())?; Some(base.join("Rufust").join("settings.conf")) } @@ -141,4 +159,25 @@ mod tests { [WueOption::Regional] ); } + + #[cfg(windows)] + #[test] + fn a_settings_file_beside_the_executable_is_portable() { + let folder = std::env::temp_dir().join(format!("rufust-portable-{}", std::process::id())); + std::fs::create_dir_all(&folder).expect("folder"); + let exe = folder.join("rufust.exe"); + let appdata = PathBuf::from(r"C:\Users\someone\AppData\Roaming"); + assert_eq!( + windows_path(Some(&exe), Some(appdata.clone())), + Some(appdata.join("Rufust").join("settings.conf")) + ); + let beside = folder.join("settings.conf"); + std::fs::write(&beside, "").expect("marker"); + assert_eq!( + windows_path(Some(&exe), Some(appdata)), + Some(beside.clone()) + ); + assert_eq!(windows_path(Some(&exe), None), Some(beside)); + std::fs::remove_dir_all(&folder).expect("cleanup"); + } } diff --git a/docs/PROJECT_CONTEXT.md b/docs/PROJECT_CONTEXT.md index a3d991c..1da8bf8 100644 --- a/docs/PROJECT_CONTEXT.md +++ b/docs/PROJECT_CONTEXT.md @@ -398,6 +398,12 @@ information, metadata, executable permissions, unprivileged contents, direct version launch, extraction fallback, Xvfb GUI startup, and loader compatibility on Debian, Fedora, and Arch. +Every copy of the version is checked against `Cargo.toml` by +`scripts/version.sh check` in CI. `scripts/version.sh bump X.Y.Z` rewrites the +plain version strings; the changelog entries (Debian, RPM, AppStream, the +"Changes in" section of `CAPABILITIES.md`, this baseline, and the release +notes) are written by hand, and the check names any that are missing. + Release publication supports a `v*` tag or a matching `release/v` branch. The release branch path exists so an authenticated repository agent can publish through the reviewed workflow without locally stored GitHub credentials. diff --git a/docs/WINDOWS.md b/docs/WINDOWS.md index 5bab3ff..d21453c 100644 --- a/docs/WINDOWS.md +++ b/docs/WINDOWS.md @@ -96,7 +96,8 @@ get-info access, which needs no elevation. - File chooser: the common Open dialog, owned by the workbench window. - Theme: `RUFUST_THEME`, else the "app mode" (`AppsUseLightTheme`) setting. -- Settings: `%APPDATA%\Rufust\settings.conf`. +- Settings: `%APPDATA%\Rufust\settings.conf`, or a `settings.conf` that + already sits beside `rufust.exe`, which makes that copy portable. - Regional options for the Windows User Experience dialog: the system and user locales, display language, keyboard layout, and time zone key name, read from Windows as upstream does. diff --git a/packaging/windows/README.txt b/packaging/windows/README.txt index 601712c..c22f183 100644 --- a/packaging/windows/README.txt +++ b/packaging/windows/README.txt @@ -28,7 +28,9 @@ Rufust can: - format drives as FAT, FAT32 (any size), exFAT, NTFS, or UDF, with an optional bad-block test. -Settings are kept in %APPDATA%\Rufust\settings.conf. +Settings are kept in %APPDATA%\Rufust\settings.conf. To keep them with a +portable copy instead, put an empty file named settings.conf next to +rufust.exe before starting it. The executable is not code-signed yet, so Windows SmartScreen may ask you to confirm the first launch. Verify the download against SHA256SUMS from the diff --git a/scripts/ci/apt-install.sh b/scripts/ci/apt-install.sh new file mode 100755 index 0000000..375c8b5 --- /dev/null +++ b/scripts/ci/apt-install.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Install apt packages on a CI runner, retrying when the mirror is unreachable. +# Usage: scripts/ci/apt-install.sh ... +set -euo pipefail + +options=(-o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30) +for attempt in 1 2 3 4 5; do + # `apt-get update` exits 0 when it only warns about unreachable indexes, so + # the install decides whether the attempt worked. + if sudo apt-get "${options[@]}" update && + sudo apt-get "${options[@]}" install -y "$@"; then + exit 0 + fi + if [ "$attempt" -lt 5 ]; then + echo "apt attempt $attempt failed; retrying in $((attempt * 30))s" >&2 + sleep $((attempt * 30)) + fi +done +echo "apt could not install the packages after 5 attempts" >&2 +exit 1 diff --git a/scripts/version.sh b/scripts/version.sh new file mode 100755 index 0000000..0c6ed47 --- /dev/null +++ b/scripts/version.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +# Keep every copy of the release version in step with Cargo.toml. +# +# scripts/version.sh check fail if any file disagrees (CI runs this) +# scripts/version.sh bump X.Y.Z rewrite the plain version strings +# +# `bump` leaves the changelog entries to you: Debian, RPM, AppStream, the +# "Changes in" section of docs/CAPABILITIES.md, and the baseline and release +# notes. `check` then names any that are still missing. +set -euo pipefail +cd "$(dirname "$0")/.." + +current() { + sed -n 's/^version = "\([0-9][0-9.]*\)"\r\{0,1\}$/\1/p' Cargo.toml | head -n 1 +} + +# file|extended regex that must match, with @V@ standing for the version. +entries() { + cat <<'LIST' +apps/rufust/ui/appwindow.slint|app-version: "@V@" +.github/workflows/release.yml|PACKAGE_VERSION: @V@ +packaging/arch/PKGBUILD|^pkgver=@V@ +packaging/rpm/rufust.spec|^Version: +@V@ +packaging/windows/rufust.iss|/DVersion=@V@ +docs/BUILDING.md|/DVersion=@V@ +docs/BUILDING.md|rufust\.AppImage @V@ +packaging/rpm/rufust.spec|^\* .* - @V@-1 +packaging/debian/changelog|^rufust \(@V@-1\) +packaging/metainfo/io.github.nitrodiesel.rufust.metainfo.xml|&2; exit 1; } + while IFS='|' read -r file pattern; do + pattern="${pattern//@V@/${version//./\.}}" + if ! grep -Eq -- "$pattern" "$file"; then + echo "$file: nothing matches '$pattern'" >&2 + failed=1 + fi + done < <(entries) + # The newest changelog entries must be this version, not just mention it. + head -n 1 packaging/debian/changelog | grep -q "($version-1)" || + { echo "packaging/debian/changelog: newest entry is not $version-1" >&2; failed=1; } + grep -m 1 '