Skip to content

Commit

Permalink
feat: Build RPMs with mock
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpenedblade committed May 22, 2023
1 parent 53b1f7f commit fadd1bc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 42 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@ jobs:

- name: "Build"
run: |
mkdir -p ~/rpmbuild
echo "$RPM_SIGNING_KEY" > ./rpm_signing_key
docker run -t -v "$PWD":/repo fedora:38 /bin/bash -c "/repo/build-packages.sh"
mkdir -p /output
docker run -t --privileged -v "$PWD":/repo -v /output:/output fedora:38 /bin/bash -c "/repo/build-packages.sh"
env:
RPM_SIGNING_KEY: ${{ secrets.RPM_SIGNING_KEY }}

- name: "Check Packages"
run: |
stat --printf='' ${{ github.workspace }}/output/RPMS/*/kernel*
stat --printf='' ${{ github.workspace }}/output/RPMS/*/t2linux-config*
stat --printf='' ${{ github.workspace }}/output/RPMS/*/t2linux-repo*
stat --printf='' /output/kernel*.rpm
stat --printf='' /output/t2linux-config*.rpm
stat --printf='' /output/t2linux-repo*.rpm
- name: "Release"
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
${{ github.workspace }}/output/RPMS/*/*
/output/*.rpm
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Update repo
if: startsWith(github.ref, 'refs/tags/')
run: |
mkdir /tmp/repo
docker run -t -v "$PWD":/repo -v "/tmp/repo":/tmp/repo fedora:38 /bin/bash -c "/repo/build-repo.sh"
mkdir /rpm-repo
docker run -t -v /output:/output -v /rpm-repo:/rpm-repo fedora:38 /bin/bash -c "/repo/build-repo.sh"
cp -r /tmp/repo ./deploy
- name: Upload
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/update-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
with:
latest: true
fileName: "*.rpm"
out-file-path: "output/RPMS/x86_64/"
out-file-path: "/output/"

- name: Update repo
run: |
mkdir /tmp/repo
docker run -t -v "$PWD":/repo -v "/tmp/repo":/tmp/repo fedora:38 /bin/bash -c "/repo/build-repo.sh"
cp -r /tmp/repo ./deploy
docker run -t -v /output:/output -v /rpm-repo:/rpm-repo fedora:38 /bin/bash -c "/repo/build-repo.sh"
cp -r /rpm-repo ./deploy
- name: Upload
uses: netlify/actions/cli@master
Expand Down
8 changes: 4 additions & 4 deletions build-packages.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/bin/bash

echo "=====INSTALLING DEPENDENCIES====="
dnf install -y --quiet koji fedora-packager git curl pesign rpmdevtools rpm-sign rpm-build
dnf install -y --quiet koji git curl pesign rpmdevtools rpm-sign rpm-build mock

echo "=====IMPORTING KEYS====="
gpg --import /repo/rpm_signing_key
rm -rfv /repo/rpm_signing_key
echo -e "%_signature gpg\n%_gpg_name T2Linux Fedora" > ~/.rpmmacros

echo "=====BUILDING====="
rpmdev-setuptree
mkdir -p /output
/repo/scripts/t2linux-fedora.sh
/repo/scripts/kernel.sh
rpm --addsign /root/rpmbuild/RPMS/x86_64/*.rpm
rpm --addsign /output/*.rpm

# Copy artifacts to shared volume
cd "/repo"
mkdir -p ./output
mkdir -p ./output/RPMS
cp -rfv /root/rpmbuild/RPMS/* ./output/RPMS/
cp -rfv /output/* ./output/RPMS/
6 changes: 3 additions & 3 deletions build-repo.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dnf install -y --quiet createrepo
mkdir -p /tmp/repo
cd /tmp/repo
cp /repo/output/RPMS/*/*.rpm .
mkdir -p /rpm-repo
cd /rpm-repo
cp /output/*.rpm .
createrepo .
21 changes: 8 additions & 13 deletions scripts/build-rpm-from-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@ if [ -n "$KOJI_VERSION" ]; then
mkdir -p /tmp/koji-download && cd /tmp/koji-download
koji download-build --arch=src "$KOJI_VERSION"
rpmdev-extract "$KOJI_VERSION".src.rpm
mv -f "$KOJI_VERSION".src/"$PACKAGE_NAME".spec /root/rpmbuild/SPECS/
mv "$KOJI_VERSION".src/* /root/rpmbuild/SOURCES/
fi

echo "=====PREPARING SOURCES====="
cp -f "$BASE_DIR"/"$PACKAGE_NAME"/*.spec /root/rpmbuild/SPECS/
cp -fr "$BASE_DIR"/"$PACKAGE_NAME"/* /root/rpmbuild/SOURCES/

echo "=====INSTALLING DEPENDENCIES====="
cd /root/rpmbuild/SPECS/
dnf -y --quiet builddep "$PACKAGE_NAME".spec
mkdir -p "$BASE_DIR"/"$PACKAGE_NAME"
mv -n "$KOJI_VERSION".src/* "$BASE_DIR"/"$PACKAGE_NAME"
fi

echo "=====BUILDING PACKAGE====="
cd /root/rpmbuild/SPECS/
rpmbuild -bb "$PACKAGE_NAME".spec
cd $BASE_DIR/$PACKAGE_NAME
spectool -g ./$PACKAGE_NAME.spec
mock --buildsrpm --spec ./$PACKAGE_NAME.spec --sources . --resultdir ./_mock
mock --rebuild ./_mock/*.src.rpm --resultdir ./_mock
cp ./_mock/*.rpm /output
22 changes: 11 additions & 11 deletions scripts/kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PATCHES_GIT=https://github.com/t2linux/linux-t2-patches
PATCHES_COMMIT=3a43f2fa1c4afec28f1bffe2aa13e3f4366ecce1

echo "=====INSTALLING DEPENDENCIES====="
dnf install -y --quiet ncurses-devel libbpf fedpkg rpmdevtools ccache openssl-devel libkcapi libkcapi-devel libkcapi-static libkcapi-tools
dnf install -y --quiet ncurses-devel libbpf fedpkg ccache openssl-devel libkcapi libkcapi-devel libkcapi-static libkcapi-tools

cd "/root/rpmbuild"/SPECS

Expand All @@ -16,17 +16,16 @@ koji download-build --arch=src kernel-${FEDORA_KERNEL_VERSION}

echo "=====EXTRACTING SOURCES====="
rpmdev-extract kernel-${FEDORA_KERNEL_VERSION}.src.rpm
mv kernel-*.src/kernel.spec /root/rpmbuild/SPECS/
cp -r kernel-*.src/* /root/rpmbuild/SOURCES/
mkdir -p /kernel-build
mv -n kernel-*.src/* /kernel-build

echo "=====PREPARING SOURCES===="
cd /root/rpmbuild/SPECS
cd /kernel-build
# Fedora devs are against merging kernel-local for all architectures when keys are not properly specified, so we have to patch it in.
sed -i "s@for i in %{all_arch_configs}@for i in *.config@g" kernel.spec
sed -i 's/# define buildid .local/%define buildid .t2/g' kernel.spec
# sed -i 's/%define specrelease 200%{?buildid}%{?dist}/%define specrelease 202%{?buildid}%{?dist}/' kernel.spec
# sed -i 's/%define pkgrelease 200/%define pkgrelease 202/' kernel.spec
dnf -y --quiet builddep kernel.spec

echo "======DOWNLOADING PATCHES====="
rm -rf /tmp/download /tmp/src
Expand All @@ -35,11 +34,12 @@ git clone --single-branch --branch main ${PATCHES_GIT}
cd *
git checkout ${PATCHES_COMMIT}

cd ~/rpmbuild/SPECS
# cat /tmp/download/*/extra_config > /root/rpmbuild/SOURCES/kernel-local
cat /tmp/download/*/extra_config > /root/rpmbuild/SOURCES/kernel-local
cat /tmp/download/*/*.patch > /root/rpmbuild/SOURCES/linux-kernel-test.patch
cd /kernel-build
cat /tmp/download/*/extra_config > kernel-local
cat /tmp/download/*/*.patch > linux-kernel-test.patch

echo "=====BUILDING====="
cd /root/rpmbuild/SPECS
rpmbuild -bb --target=x86_64 .//kernel.spec
cd /kernel-build
mock --buildsrpm --spec ./kernel.spec --sources . --resultdir ./_mock
mock --rebuild ./_mock/*.src.rpm --resultdir ./_mock
cp ./_mock/*.rpm /output

0 comments on commit fadd1bc

Please sign in to comment.