From 59a729d5f4cf33c94fce0e42124bb151aa6c2cd2 Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Wed, 3 Jun 2026 01:55:32 +0300 Subject: [PATCH] ci(github): bake version into COPR spec (#1905) --- .github/workflows/publish-copr.yaml | 28 +++++++++++++--------------- pkg/copr/README.md | 12 ++++++------ pkg/copr/zeal.spec | 25 ++++++++++--------------- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/.github/workflows/publish-copr.yaml b/.github/workflows/publish-copr.yaml index 684bf79d..e530af0c 100644 --- a/.github/workflows/publish-copr.yaml +++ b/.github/workflows/publish-copr.yaml @@ -158,28 +158,26 @@ jobs: git archive --prefix="zeal-${VERSION}/" HEAD \ | gzip -9 > "${HOME}/rpmbuild/SOURCES/zeal-${VERSION}.tar.gz" - # Replace the spec's %changelog with a single dated entry. + # Bake the version and bundled cpp-httplib version into the spec. A --define + # would be lost when COPR rebuilds the SRPM, resetting the version to 0.0.0. spec="${HOME}/rpmbuild/SPECS/zeal.spec" sed '/^%changelog/q' pkg/copr/zeal.spec > "$spec" + sed -i "s/^Version:.*/Version: ${VERSION}/" "$spec" + + if [ -f src/contrib/cpp-httplib/httplib.h ]; then + httplib_version=$(sed -n 's/^#define CPPHTTPLIB_VERSION "\([^"]*\)".*/\1/p' \ + src/contrib/cpp-httplib/httplib.h | head -n1) + if [ -n "$httplib_version" ]; then + sed -i "s|^Provides:.*bundled(cpp-httplib).*|Provides: bundled(cpp-httplib) = ${httplib_version}|" "$spec" + fi + fi + { printf '* %s %s - %s-1\n' "$(LC_ALL=C date '+%a %b %d %Y')" "$PACKAGER" "$VERSION" printf -- '- Build of %s.\n' "$VERSION" } >> "$spec" - # Pass the bundled cpp-httplib version (from its header) to the spec's - # bundled() Provides. Omitted if not found, leaving it unversioned. - httplib_version="" - if [ -f src/contrib/cpp-httplib/httplib.h ]; then - httplib_version=$(sed -n 's/^#define CPPHTTPLIB_VERSION "\([^"]*\)".*/\1/p' \ - src/contrib/cpp-httplib/httplib.h | head -n1) - fi - - defines=(--define "_topdir ${HOME}/rpmbuild" --define "zeal_version ${VERSION}") - if [ -n "$httplib_version" ]; then - defines+=(--define "httplib_version ${httplib_version}") - fi - - rpmbuild -bs "$spec" "${defines[@]}" + rpmbuild -bs "$spec" --define "_topdir ${HOME}/rpmbuild" srpm=$(find "${HOME}/rpmbuild/SRPMS" -name "zeal-${VERSION}-1*.src.rpm" | head -n1) if [ -z "$srpm" ]; then diff --git a/pkg/copr/README.md b/pkg/copr/README.md index f63a6e78..4433e585 100644 --- a/pkg/copr/README.md +++ b/pkg/copr/README.md @@ -20,9 +20,10 @@ nightly run skips when `main` has not advanced since its last build. CMake installs the binary, desktop file, metainfo, and icons under the prefix. toml++ comes from `tomlplusplus-devel`; cpp-httplib stays bundled in `src/contrib`. -`Version:` is a placeholder. The workflow sets it with `--define "zeal_version "`: -the tag for releases, a `git describe` snapshot for nightlies (which sorts above -the last release and below the next). +`Version:` is a placeholder the workflow rewrites in the spec before building the +SRPM (not via `--define`, which COPR drops when it rebuilds the SRPM): the tag for +releases, a `git describe` snapshot for nightlies (which sorts above the last +release and below the next). ## Chroots @@ -51,8 +52,7 @@ VERSION=$(git describe --tags --abbrev=0 | sed 's/^v//') mkdir -p ~/rpmbuild/SOURCES ~/rpmbuild/SPECS git archive --prefix="zeal-$VERSION/" "v$VERSION" | gzip -9 \ > ~/rpmbuild/SOURCES/zeal-$VERSION.tar.gz -cp pkg/copr/zeal.spec ~/rpmbuild/SPECS/ -rpmbuild -bs ~/rpmbuild/SPECS/zeal.spec \ - --define "_topdir $HOME/rpmbuild" --define "zeal_version $VERSION" +sed "s/^Version:.*/Version: $VERSION/" pkg/copr/zeal.spec > ~/rpmbuild/SPECS/zeal.spec +rpmbuild -bs ~/rpmbuild/SPECS/zeal.spec --define "_topdir $HOME/rpmbuild" mock ~/rpmbuild/SRPMS/zeal-$VERSION-1*.src.rpm ``` diff --git a/pkg/copr/zeal.spec b/pkg/copr/zeal.spec index c03b898d..aed03d99 100644 --- a/pkg/copr/zeal.spec +++ b/pkg/copr/zeal.spec @@ -1,18 +1,17 @@ # RPM spec for Zeal, built on Fedora COPR. # -# The Version tag is a placeholder overridden by the release automation, which -# passes --define "zeal_version " when building the source RPM (see -# .github/workflows/publish-copr.yaml). A plain build with no override produces -# 0.0.0, matching the AUR PKGBUILD convention. CMake already installs the binary, -# .desktop file, AppStream metainfo, and icons under the prefix on Linux -# (see assets/freedesktop/CMakeLists.txt), so %%cmake_install needs no extra glue. -# toml++ is taken from the distro (tomlplusplus-devel). cpp-httplib stays bundled -# in src/contrib because the system versions span too wide a range to rely on; its -# bundled() Provides version is injected by the workflow via -# --define "httplib_version ", read from the bundled header. +# The automation rewrites the Version line (and the bundled(cpp-httplib) Provides) +# in this spec before building the source RPM (see .github/workflows/publish-copr.yaml). +# They are baked in rather than passed via --define, because COPR rebuilds the SRPM +# without those defines and the version would reset to 0.0.0. A plain build with no +# rewrite produces 0.0.0. CMake already installs the binary, .desktop file, AppStream +# metainfo, and icons under the prefix on Linux (see assets/freedesktop/CMakeLists.txt), +# so %%cmake_install needs no extra glue. toml++ comes from the distro +# (tomlplusplus-devel); cpp-httplib stays bundled in src/contrib because the system +# versions span too wide a range to rely on. Name: zeal -Version: %{?zeal_version}%{!?zeal_version:0.0.0} +Version: 0.0.0 Release: 1%{?dist} Summary: Simple offline documentation browser @@ -45,11 +44,7 @@ BuildRequires: libxkbcommon-devel Requires: hicolor-icon-theme -%if "%{?httplib_version}" != "" -Provides: bundled(cpp-httplib) = %{httplib_version} -%else Provides: bundled(cpp-httplib) -%endif %description Zeal is a simple offline documentation browser inspired by Dash. It offers