@@ -718,3 +718,142 @@ jobs:
718718
719719 echo "Giving up after 2 attempts."
720720 exit 1
721+
722+ build-and-attest-rpms :
723+ name : Build & attest RPM packages
724+ needs : safexec-build-test-attest
725+ runs-on : ubuntu-latest
726+ permissions :
727+ contents : write
728+ id-token : write
729+ attestations : write
730+ actions : read
731+ steps :
732+ - name : Checkout
733+ uses : actions/checkout@v5
734+ with :
735+ fetch-depth : 0
736+
737+ - name : Download safexec build artifacts
738+ uses : actions/download-artifact@v4
739+ with :
740+ name : safexec-binaries
741+ path : safexec/bin
742+
743+ - name : Ensure exec bits
744+ run : |
745+ chmod 755 safexec/bin/safexec-*-linux-musl || true
746+ chmod +x safexec/helpers/rpm.sh
747+
748+ # Resolve version from safexec -v
749+ - name : Resolve version from safexec -v
750+ id : ver
751+ shell : bash
752+ run : |
753+ set -euo pipefail
754+ BIN="safexec/bin/safexec-x86_64-linux-musl"
755+ [[ -x "$BIN" ]] || BIN="safexec/bin/safexec-aarch64-linux-musl"
756+ [[ -x "$BIN" ]] || { echo "safexec binary not found in safexec/bin"; exit 1; }
757+ FIRST_LINE="$("$BIN" -v | head -n1)"
758+ BASE_VER="$(printf '%s\n' "$FIRST_LINE" | awk '{print $2}')"
759+ [[ "$BASE_VER" =~ ^[0-9]+(\.[0-9]+){1,2}$ ]] || { echo "Bad version: $BASE_VER"; exit 1; }
760+ echo "base=$BASE_VER" >> "$GITHUB_OUTPUT"
761+ # For RPM we pass version as VERSION-REL; pick 1 as default release
762+ echo "rpm=${BASE_VER}-1" >> "$GITHUB_OUTPUT"
763+
764+ # Build x86_64 RPM on Rocky 10
765+ - name : Build RPM (x86_64 / Rocky 10)
766+ run : |
767+ set -euo pipefail
768+ docker run --rm -v "$PWD":/src -w /src rockylinux:10 bash -euxo pipefail -c '
769+ # speed up metadata a bit
770+ dnf -y makecache
771+ bash safexec/helpers/rpm.sh --arch amd64 --version '"${{ steps.ver.outputs.rpm }}"'
772+ chown -R 1000:1000 /src/pkg-safexec-amd64-rpm || true
773+ '
774+
775+ # Enable arm64 binfmt
776+ - name : Enable binfmt for arm64
777+ run : docker run --privileged --rm tonistiigi/binfmt --install arm64
778+
779+ # Build aarch64 RPM on Rocky 10 (arm64 container)
780+ - name : Build RPM (aarch64 / Rocky 10)
781+ run : |
782+ set -euo pipefail
783+ docker run --rm --platform=linux/arm64 -v "$PWD":/src -w /src rockylinux:10 bash -euxo pipefail -c '
784+ dnf -y makecache
785+ bash safexec/helpers/rpm.sh --arch arm64 --version '"${{ steps.ver.outputs.rpm }}"'
786+ chown -R 1000:1000 /src/pkg-safexec-arm64-rpm || true
787+ '
788+
789+ - name : Collect RPMs -> safexec/rpm
790+ run : |
791+ set -euo pipefail
792+ mkdir -p safexec/rpm
793+ find pkg-safexec-*-rpm/rpmbuild/RPMS -type f -name "safexec-*.rpm" -print -exec cp -v {} safexec/rpm/ \;
794+ cd safexec/rpm
795+ ls -1 *.rpm
796+ sha256sum *.rpm | sort > SHA256SUMS
797+
798+ - name : Generate SLSA provenance (RPM packages)
799+ uses : actions/attest-build-provenance@v3
800+ with :
801+ subject-path : |
802+ safexec/rpm/*.rpm
803+ safexec/rpm/SHA256SUMS
804+
805+ - name : Upload RPMs as artifacts
806+ uses : actions/upload-artifact@v4
807+ with :
808+ name : safexec-rpms-${{ steps.ver.outputs.rpm }}
809+ path : |
810+ safexec/rpm/*.rpm
811+ safexec/rpm/SHA256SUMS
812+ if-no-files-found : error
813+
814+ - name : Clean packaging worktrees
815+ run : |
816+ sudo chown -R "$(id -u)":"$(id -g)" pkg-safexec-*-rpm 2>/dev/null || true
817+ sudo rm -rf pkg-safexec-*-rpm || true
818+
819+ - name : Commit RPMs back to repo
820+ if : github.ref_type == 'branch'
821+ env :
822+ GITHUB_REF : ${{ github.ref }}
823+ run : |
824+ set -euo pipefail
825+ BRANCH="${GITHUB_REF#refs/heads/}"
826+
827+ git config user.name "github-actions[bot]"
828+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
829+
830+ # keep temp build dirs ignored; allow safexec/rpm to be committed
831+ mkdir -p .git/info
832+ {
833+ echo 'pkg-safexec-*/'
834+ echo 'safexec/bin/'
835+ } >> .git/info/exclude
836+
837+ git fetch --prune origin
838+ git stash push -u -m "ci-artifacts" || true
839+ git checkout -B "${BRANCH}" "origin/${BRANCH}"
840+ git stash pop || true
841+
842+ git add -f safexec/rpm/*.rpm safexec/rpm/SHA256SUMS || true
843+ if git diff --cached --quiet; then
844+ echo "No RPM changes to commit."
845+ exit 0
846+ fi
847+
848+ git commit -m "ci: add RPM packages for ${{ steps.ver.outputs.rpm }}"
849+
850+ for attempt in 1 2; do
851+ git pull --rebase --autostash origin "${BRANCH}" && \
852+ git push origin "HEAD:${BRANCH}" && exit 0
853+ echo "Push attempt ${attempt} failed; retrying…"
854+ sleep 2
855+ git fetch --prune origin
856+ done
857+
858+ echo "Giving up after 2 attempts."
859+ exit 1
0 commit comments