diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2eebf22 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,83 @@ +# SPDX-License-Identifier: MIT +# Release binaries for Linux x86_64 and arm64: Debian package, AppImage and a tarball of the +# command-line tool. On a vX.Y.Z tag they are attached to the GitHub release (created here if +# tools/release.sh has not created it yet); a manual run keeps them as workflow artifacts. +name: Release + +on: + push: + tags: ["v*"] + workflow_dispatch: + +permissions: + contents: write + +jobs: + linux: + name: Linux ${{ matrix.arch }} + strategy: + fail-fast: false + matrix: + include: + - arch: x86_64 + runner: ubuntu-24.04 + - arch: arm64 + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 # tags are needed for the version description + + - name: Dependencies + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + build-essential cmake ninja-build pkg-config gettext file desktop-file-utils \ + libcurl4-openssl-dev libarchive-dev nlohmann-json3-dev doctest-dev \ + libglib2.0-dev libgtkmm-4.0-dev librsvg2-common + + - name: Build and test + run: | + cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \ + -DOPENPU_WERROR=ON -DOPENPU_UI_GTK=ON + cmake --build build + ctest --test-dir build --output-on-failure + + - name: Debian package + run: | + cd build && cpack -G DEB + dpkg-deb -I openpu_*.deb + + - name: Command-line tool + run: | + version=$(build/src/cli/openpu-cli --version | awk '{print $2}') + mkdir -p "dist/openpu-cli-$version-linux-${{ matrix.arch }}" + cp build/src/cli/openpu-cli LICENSE README.md "dist/openpu-cli-$version-linux-${{ matrix.arch }}/" + strip "dist/openpu-cli-$version-linux-${{ matrix.arch }}/openpu-cli" + tar -C dist -czf "openpu-cli-$version-linux-${{ matrix.arch }}.tar.gz" "openpu-cli-$version-linux-${{ matrix.arch }}" + + - name: AppImage + run: tools/appimage.sh "$PWD/build-appimage" + + - name: Collect + run: | + mkdir -p out + mv build/openpu_*.deb openpu-cli-*.tar.gz OpenPU-*.AppImage out/ + (cd out && sha256sum * > SHA256SUMS-linux-${{ matrix.arch }}.txt && ls -l) + + - uses: actions/upload-artifact@v4 + with: + name: openpu-linux-${{ matrix.arch }} + path: out/* + + - name: Attach to the release + if: startsWith(github.ref, 'refs/tags/v') + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ github.ref_name }} + run: | + gh release view "$TAG" >/dev/null 2>&1 || + gh release create "$TAG" --verify-tag --title "OpenPU ${TAG#v}" --notes-from-tag || + gh release view "$TAG" >/dev/null # the other architecture may have created it meanwhile + gh release upload "$TAG" out/* --clobber diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ef2f33..02247d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,17 @@ complete; every release is an annotated git tag `vX.Y.Z` (see `tools/release.sh` - Application icon: an original shield with a "PU" monogram, as SVG, HVIF (embedded in the Haiku executable) and PNG from 16 to 512 px (installed in the hicolor icon theme on Linux), generated by `tools/make_icons.py`. +- Debian package through CPack (dependencies from `dpkg-shlibdeps`, `udisks2` recommended) and + AppStream metadata (`io.github.openpu.OpenPU.metainfo.xml`). +- `tools/appimage.sh`: AppImage of the GTK interface and `openpu-cli` (linuxdeploy + GTK plugin). +- `Release` GitHub workflow: Debian package, AppImage and `openpu-cli` tarball for Linux x86_64 + and arm64, attached to the release of every `vX.Y.Z` tag. + +### Changed +- The GTK interface looks for its translations in `../share/locale` next to the executable first, + so that relocatable installs (AppImage) are translated. +- `tools/release.sh` adds the release to the AppStream metadata and updates a GitHub release + that the release workflow created first. ### Fixed - Translations were installed in `//LC_MESSAGES` instead of the locale directory. diff --git a/CMakeLists.txt b/CMakeLists.txt index 8646aa6..f4f7491 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,3 +55,7 @@ if(OPENPU_BUILD_TESTS) enable_testing() add_subdirectory(tests) endif() + +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Haiku") # Haiku packages are built from a HaikuPorts recipe + include(cmake/Packaging.cmake) +endif() diff --git a/README.md b/README.md index 30c99b2..46402c0 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,9 @@ It is an alternative to the official "Peugeot Update" application (Windows/macOS - [x] Haiku: core library, CLI and USB support (Storage Kit), validated in a Haiku R1/beta6 VM - [x] Haiku UI (Interface Kit): complete workflow, preferences, new-version check - [x] GitHub Actions continuous integration (Linux x86_64 + arm64) -- [ ] Linux packages: `.deb`, Flatpak and AppImage; Haiku: `.hpkg` -- [ ] x86_64 + arm64 binaries attached to every release (from 1.0.0 on) +- [x] Debian package (`cpack -G DEB`) +- [ ] AppImage (`tools/appimage.sh`, not validated yet), Flatpak; Haiku: `.hpkg` +- [ ] x86_64 + arm64 binaries attached to every release (from 1.0.0 on): release workflow ready ## Architecture ``` @@ -54,6 +55,20 @@ tools/e2e-usb.sh ../build-openpu/debug/src/cli/openpu-cli --license X.key update When running from the build tree, `OPENPU_LOCALEDIR=../build-openpu/debug/locale` lets the interface find its translations. +## Packages (Linux) +```sh +cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DOPENPU_UI_GTK=ON +cmake --build build && (cd build && cpack -G DEB) # build/openpu__.deb +tools/appimage.sh # ./OpenPU--.AppImage +``` +The Debian package gets its dependencies from `dpkg-shlibdeps` and recommends `udisks2`, which +formats and mounts the USB stick. `tools/appimage.sh` downloads linuxdeploy and its GTK plugin +into `~/.cache/openpu-appimage`. + +The `Release` GitHub workflow builds the Debian package, the AppImage and a `openpu-cli` tarball +for x86_64 and arm64. On a `vX.Y.Z` tag it attaches them to the release, and a manual run keeps +them as workflow artifacts. + ## Building (Haiku) ```sh pkgman install cmake ninja curl_devel libarchive_devel nlohmann_json gettext gettext_libintl_devel diff --git a/cmake/Packaging.cmake b/cmake/Packaging.cmake new file mode 100644 index 0000000..7507b57 --- /dev/null +++ b/cmake/Packaging.cmake @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: MIT +# Debian package (cpack -G DEB). Dependencies are computed by dpkg-shlibdeps from the binaries, +# so the package matches the distribution it was built on. +set(CPACK_PACKAGE_NAME openpu) +set(CPACK_PACKAGE_VENDOR "OpenPU contributors") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Download Peugeot head unit updates and prepare the USB stick") +set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/yann64/openpu") +set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE) +set(CPACK_PACKAGE_INSTALL_DIRECTORY openpu) +set(CPACK_STRIP_FILES ON) + +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) # openpu__.deb +set(CPACK_DEBIAN_PACKAGE_SECTION utils) +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "OpenPU contributors ") +set(CPACK_DEBIAN_PACKAGE_DESCRIPTION + "Download Peugeot head unit updates and prepare the USB stick\n\ + OpenPU downloads the firmware and navigation map updates of Peugeot head units\n\ + (NAC, RCC, AIO, Crony) and prepares the installation USB stick: FAT32\n\ + formatting, license and update files. Graphical interface (GTK 4) and\n\ + command-line tool. Independent project, not affiliated with Stellantis or Peugeot.") +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) +# UDisks2 formats and mounts the stick; without it only `openpu-cli write-dir` works. +set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "udisks2") + +set(CPACK_SOURCE_GENERATOR TGZ) +set(CPACK_SOURCE_IGNORE_FILES "/\\\\.git/" "/build/" "\\\\.swp$") + +include(CPack) diff --git a/data/io.github.openpu.OpenPU.metainfo.xml b/data/io.github.openpu.OpenPU.metainfo.xml new file mode 100644 index 0000000..9d52922 --- /dev/null +++ b/data/io.github.openpu.OpenPU.metainfo.xml @@ -0,0 +1,37 @@ + + + + io.github.openpu.OpenPU + MIT + MIT + OpenPU + Download head unit updates and prepare the USB stick + Télécharger les mises à jour de l'autoradio et préparer la clé USB + +

+ OpenPU downloads the firmware and navigation map updates of Peugeot head units (NAC, RCC, + AIO, Crony) and prepares the installation USB stick: FAT32 formatting, license and update + files. Downloads resume where they stopped. +

+

+ Independent project, not affiliated with Stellantis or Peugeot. +

+
+ io.github.openpu.OpenPU.desktop + https://github.com/yann64/openpu + https://github.com/yann64/openpu/issues + + yann64 and the OpenPU contributors + + + + Utility + + + always + + + + + +
diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index d1719aa..319692b 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -1,3 +1,4 @@ add_executable(openpu-cli main.cpp) target_link_libraries(openpu-cli PRIVATE openpu_core openpu_warnings) -install(TARGETS openpu-cli RUNTIME DESTINATION bin) +include(GNUInstallDirs) +install(TARGETS openpu-cli RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/ui-gtk/CMakeLists.txt b/src/ui-gtk/CMakeLists.txt index fe3e62d..c1f1254 100644 --- a/src/ui-gtk/CMakeLists.txt +++ b/src/ui-gtk/CMakeLists.txt @@ -16,6 +16,8 @@ target_compile_options(openpu PRIVATE -Wno-shadow -Wno-conversion) install(TARGETS openpu RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES io.github.openpu.OpenPU.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) +install(FILES ${PROJECT_SOURCE_DIR}/data/io.github.openpu.OpenPU.metainfo.xml + DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo) # Application icon (data/icons, generated by tools/make_icons.py), installed in the hicolor theme # and mirrored in the build tree so that an uninstalled binary finds it too. diff --git a/src/ui-gtk/main.cpp b/src/ui-gtk/main.cpp index 523992b..8a407a6 100644 --- a/src/ui-gtk/main.cpp +++ b/src/ui-gtk/main.cpp @@ -5,9 +5,32 @@ #include #include +#include +#include +#include #include #include +namespace { + +/// Translations directory: OPENPU_LOCALEDIR (build tree), else /share/locale next to the +/// executable when it exists (relocatable installs such as the AppImage), else the configured one. +std::string localeDir() +{ + if (const char* dir = std::getenv("OPENPU_LOCALEDIR")) // NOLINT(concurrency-mt-unsafe): no thread yet + return dir; + std::error_code ec; + const auto exe = std::filesystem::read_symlink("/proc/self/exe", ec); + if (!ec) { + const auto dir = exe.parent_path().parent_path() / "share" / "locale"; + if (std::filesystem::is_directory(dir, ec)) + return dir.string(); + } + return OPENPU_LOCALEDIR; +} + +} // namespace + int main(int argc, char* argv[]) { // A language chosen in the settings overrides the session language (gettext reads LANGUAGE). @@ -19,9 +42,7 @@ int main(int argc, char* argv[]) // dismissed: the window reports unreadable settings itself } (void)std::setlocale(LC_ALL, ""); // NOLINT(concurrency-mt-unsafe): no thread yet - // OPENPU_LOCALEDIR lets a build-tree binary find its translations. - const char* localeDir = std::getenv("OPENPU_LOCALEDIR"); // NOLINT(concurrency-mt-unsafe) - bindtextdomain(GETTEXT_PACKAGE, localeDir != nullptr ? localeDir : OPENPU_LOCALEDIR); + bindtextdomain(GETTEXT_PACKAGE, localeDir().c_str()); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); diff --git a/tools/appimage.sh b/tools/appimage.sh new file mode 100755 index 0000000..57bf36a --- /dev/null +++ b/tools/appimage.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Builds OpenPU--.AppImage (GTK interface + openpu-cli) with linuxdeploy and its GTK +# plugin, in the current directory. Runs on x86_64 and aarch64; no FUSE needed. +# +# usage: tools/appimage.sh [build-dir] +# The linuxdeploy tools are downloaded once into $OPENPU_APPIMAGE_TOOLS (default ~/.cache/openpu-appimage). +set -eu + +SRC=$(cd "$(dirname "$0")/.." && pwd) +BUILD=${1:-$SRC/../build-openpu/appimage} +OUT=$(pwd) +ARCH=$(uname -m) +TOOLS=${OPENPU_APPIMAGE_TOOLS:-$HOME/.cache/openpu-appimage} +LINUXDEPLOY=$TOOLS/linuxdeploy-$ARCH.AppImage +GTK_PLUGIN=$TOOLS/linuxdeploy-plugin-gtk.sh + +mkdir -p "$TOOLS" +fetch() { # url file + [ -s "$2" ] || { curl -fsSL -o "$2.part" "$1" && mv "$2.part" "$2"; } + chmod +x "$2" +} +fetch "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-$ARCH.AppImage" "$LINUXDEPLOY" +fetch "https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh" "$GTK_PLUGIN" + +cmake -S "$SRC" -B "$BUILD" -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \ + -DOPENPU_UI_GTK=ON -DOPENPU_BUILD_TESTS=OFF +cmake --build "$BUILD" +APPDIR=$BUILD/AppDir +rm -rf "$APPDIR" +DESTDIR=$APPDIR cmake --install "$BUILD" --strip + +VERSION=$("$APPDIR/usr/bin/openpu-cli" --version | awk '{print $2}') +ID=io.github.openpu.OpenPU +cd "$OUT" +# linuxdeploy finds its plugins next to itself or in PATH. +PATH=$TOOLS:$PATH APPIMAGE_EXTRACT_AND_RUN=1 DEPLOY_GTK_VERSION=4 LINUXDEPLOY_OUTPUT_VERSION=$VERSION \ + "$LINUXDEPLOY" --appdir "$APPDIR" --plugin gtk --output appimage \ + --executable "$APPDIR/usr/bin/openpu" --executable "$APPDIR/usr/bin/openpu-cli" \ + --desktop-file "$APPDIR/usr/share/applications/$ID.desktop" \ + --icon-file "$APPDIR/usr/share/icons/hicolor/256x256/apps/$ID.png" +ls -l "$OUT"/OpenPU-*.AppImage diff --git a/tools/release.sh b/tools/release.sh index a5d642c..c20d58a 100644 --- a/tools/release.sh +++ b/tools/release.sh @@ -25,7 +25,11 @@ grep -q "^project(openpu VERSION $VERSION " CMakeLists.txt || { echo "cannot upd sed -i "s/^## \[Unreleased\]$/## [Unreleased]\n\n## [$VERSION] - $TODAY/" CHANGELOG.md sed -i "s|^\[Unreleased\]: \(.*\)/compare/v[0-9.]*\.\.\.HEAD$|[Unreleased]: \1/compare/v$VERSION...HEAD\n[$VERSION]: \1/releases/tag/v$VERSION|" CHANGELOG.md -git add CMakeLists.txt CHANGELOG.md +# AppStream metadata lists the releases, newest first. +sed -i "s|^ $| \n |" data/io.github.openpu.OpenPU.metainfo.xml +grep -q "&2; exit 1; } + +git add CMakeLists.txt CHANGELOG.md data/io.github.openpu.OpenPU.metainfo.xml # RELEASE_TRAILER: optional trailer lines appended to the release commit message (e.g. co-authors). git commit -q -m "release: v$VERSION" ${RELEASE_TRAILER:+-m "$RELEASE_TRAILER"} # Plain string comparison (not a regex: "[" and "." in the heading would be special). @@ -43,7 +47,12 @@ done GH=$(command -v gh || command -v gh.exe || true) [ -z "$GH" ] && [ -x "/c/Program Files/GitHub CLI/gh.exe" ] && GH="/c/Program Files/GitHub CLI/gh.exe" if [ -n "$GH" ]; then - printf '%s\n' "$NOTES" | "$GH" release create "v$VERSION" --verify-tag --title "OpenPU $VERSION" --notes-file - + # The release workflow may have created the release already (to attach the binaries). + if "$GH" release view "v$VERSION" >/dev/null 2>&1; then + printf '%s\n' "$NOTES" | "$GH" release edit "v$VERSION" --title "OpenPU $VERSION" --notes-file - + else + printf '%s\n' "$NOTES" | "$GH" release create "v$VERSION" --verify-tag --title "OpenPU $VERSION" --notes-file - + fi else echo "gh not found: create the GitHub release for v$VERSION by hand" >&2 fi