From 84c56243a2e598abf776ab49553e307054d11539 Mon Sep 17 00:00:00 2001 From: Lokesh Mandvekar Date: Tue, 4 Mar 2025 17:50:44 +0530 Subject: [PATCH] [skip-ci] Packit/RPM: Display upstream commit SHA in all rpm builds Packit's `pre-sync` action allows modification of spec file prior to dist-git PR creation. This is already being done on containers-common rpm to update c/storage and c/image verions tags in spec. This commit will allow `podman version` to show `Git Commit: $SHA` for copr as well as koji builds. Ref: https://raw.githubusercontent.com/containers/common/refs/heads/main/.packit.yaml Signed-off-by: Lokesh Mandvekar --- .packit.sh => .packit-copr-rpm.sh | 13 ++----------- .packit-rpm-git-commit.sh | 17 +++++++++++++++++ .packit.yaml | 4 ++-- rpm/podman.spec | 8 +++----- 4 files changed, 24 insertions(+), 18 deletions(-) rename .packit.sh => .packit-copr-rpm.sh (83%) create mode 100644 .packit-rpm-git-commit.sh diff --git a/.packit.sh b/.packit-copr-rpm.sh similarity index 83% rename from .packit.sh rename to .packit-copr-rpm.sh index 7d28a45108..9200eaf6e5 100644 --- a/.packit.sh +++ b/.packit-copr-rpm.sh @@ -4,15 +4,9 @@ # action in .packit.yaml. These steps only work on copr builds, not on official # Fedora builds. -set -eox pipefail +set -exo pipefail -PACKAGE=podman - -# Set path to rpm spec file -SPEC_FILE=rpm/$PACKAGE.spec - -# Get short sha -GIT_COMMIT=$(git rev-parse HEAD) +. .packit-rpm-git-commit.sh # Get Version from HEAD VERSION=$(grep '^const RawVersion' version/rawversion/version.go | cut -d\" -f2) @@ -40,6 +34,3 @@ sed -i "s/^Source0:.*.tar.gz/Source0: $PACKAGE-$VERSION.tar.gz/" $SPEC_FILE # Update setup macro to use the correct build dir sed -i "s/^%autosetup.*/%autosetup -Sgit -n %{name}-$VERSION/" $SPEC_FILE - -# Update LDFLAGS to show commit id for Copr builds -sed -i "s/##GIT_COMMIT##/$GIT_COMMIT/" $SPEC_FILE diff --git a/.packit-rpm-git-commit.sh b/.packit-rpm-git-commit.sh new file mode 100644 index 0000000000..be09811230 --- /dev/null +++ b/.packit-rpm-git-commit.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# Updates the rpm spec with the upstream git SHA. Works for both copr and koji +# builds via Packit actions. See .packit.yaml for usage. + +set -exo pipefail + +PACKAGE=podman + +# Set path to rpm spec file +SPEC_FILE=rpm/$PACKAGE.spec + +# Get short sha +GIT_COMMIT=$(git rev-parse HEAD) + +# Update LDFLAGS to show commit id for Copr builds +sed -i "s/^GIT_COMMIT=*/GIT_COMMIT=\"$GIT_COMMIT\"/" $SPEC_FILE diff --git a/.packit.yaml b/.packit.yaml index 637e02041b..ed34119424 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -20,8 +20,8 @@ srpm_build_deps: - make actions: - fix-spec-file: - - "bash .packit.sh" + fix-spec-file: "bash .packit-copr-rpm.sh" + pre-sync: "bash .packit-rpm-git-commit.sh" jobs: - job: copr_build diff --git a/rpm/podman.spec b/rpm/podman.spec index 02df5efe59..68fbae4503 100644 --- a/rpm/podman.spec +++ b/rpm/podman.spec @@ -238,12 +238,10 @@ LDFLAGS="-X %{ld_libpod}/define.buildInfo=${SOURCE_DATE_EPOCH:-$(date +%s)} \ -X %{ld_libpod}/config._etcDir=%{_sysconfdir} \ -X %{ld_project}/pkg/systemd/quadlet._binDir=%{_bindir}" -%if %{defined copr_build} -# ##GIT_COMMIT## is set by `.packit.sh` in Packit's Copr RPM build jobs. -# Has no effect on Koji builds. -GIT_COMMIT="##GIT_COMMIT##" +# This variable will be set by Packit actions. See .packit.yaml in the root dir +# of the repo (upstream as well as Fedora dist-git). +GIT_COMMIT="" LDFLAGS="$LDFLAGS -X %{ld_libpod}/define.gitCommit=$GIT_COMMIT" -%endif # build rootlessport first %gobuild -o bin/rootlessport ./cmd/rootlessport