From 99eb5677ecdd1e394c1c05bc2ce0cd5c16eeda00 Mon Sep 17 00:00:00 2001 From: sharpenedblade Date: Fri, 13 Oct 2023 17:43:50 -0700 Subject: [PATCH] Build packages in temp dir and cleanup on exit --- .github/workflows/build.yml | 4 ++-- .github/workflows/deploy.yaml | 4 ++-- .gitignore | 2 +- build-packages.sh | 33 +++++++++++++++++++++++++-------- create-repo.sh | 6 ++++-- kernel/kernel.sh | 24 ++++++++++++++---------- 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4336750..55bac62 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,14 +55,14 @@ jobs: uses: actions/upload-artifact@v3 with: name: packages - path: _output/*.rpm + path: builddir/packages/*.rpm - name: "Release" if: startsWith(github.ref, 'refs/tags/v') uses: softprops/action-gh-release@v1 with: files: | - _output/*.rpm + builddir/packages/*.rpm deploy: needs: ["build"] diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 883beb9..708c30b 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -20,7 +20,7 @@ jobs: with: latest: true fileName: "*" - out-file-path: "_output" + out-file-path: "builddir/packages" - name: "Build DNF Repo" run: | @@ -38,5 +38,5 @@ jobs: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} with: - publish-dir: _output/dnf-repo + publish-dir: builddir/dnf-repo production-deploy: ${{ startsWith(github.ref, 'refs/tags/v') }} diff --git a/.gitignore b/.gitignore index 88ddcdf..e2be6ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -_output/ +builddir/ diff --git a/build-packages.sh b/build-packages.sh index 1dc8de3..c04a962 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -1,18 +1,35 @@ #!/usr/bin/bash set -e -packages=( "t2linux-config" "t2linux-repo" "t2linux-audio" "kernel") +packages=( "t2linux-config" "t2linux-repo" "t2linux-audio" "kernel" ) + +mkdir -p /repo/builddir +builddir=$(mktemp -d -p "/repo/builddir"); export builddir +function cleanup { + rm -rf "$builddir" +} +trap cleanup EXIT -mkdir -p /repo/_output for current_package in "${packages[@]}"; do + + [[ -d "/repo/$current_package" ]] || exit 10 + + export package_builddir="$builddir/$current_package" + mkdir -p "$package_builddir" + + cp -fr "/repo/$current_package"/* "$package_builddir" if [ "$current_package" == "kernel" ]; then /repo/kernel/kernel.sh fi - cd /repo/"$current_package" || echo "ERROR: Package $current_package not found" - spectool -g "$current_package".spec - mock --buildsrpm --spec "$current_package".spec --sources . --resultdir /repo/_output + + export specfile="$package_builddir/$current_package.spec" + [[ -f "$specfile" ]] || exit 11 + + spectool -g -C "$package_builddir" "$specfile" + mock --buildsrpm --spec "$specfile" --sources "$package_builddir" --resultdir "$builddir" done -mock --rebuild --chain /repo/_output/*.src.rpm --localrepo /repo/_output/mock_repo -cp -f /repo/_output/mock_repo/results/*/*/*.rpm /repo/_output -rm -rf /repo/_output/*.log +mock --rebuild --chain "$builddir"/*.src.rpm --localrepo "$builddir" +mkdir -p /repo/builddir/packages +cp -f "$builddir"/results/*/*/*.rpm /repo/builddir/packages/ +cleanup diff --git a/create-repo.sh b/create-repo.sh index ec205b6..41dc691 100755 --- a/create-repo.sh +++ b/create-repo.sh @@ -1,4 +1,5 @@ #!/usr/bin/bash +set -e SIGNING_KEY_UID=$( \ echo "$SIGNING_KEY" \ @@ -11,7 +12,8 @@ echo "$SIGNING_KEY" | gpg --import unset SIGNING_KEY # shellcheck disable=SC2164 -mkdir -p /repo/_output/dnf-repo && cd /repo/_output/dnf-repo -cp ../*.rpm . && rm ./*.src.rpm +mkdir -p /repo/builddir/dnf-repo && cd /repo/builddir/dnf-repo +cp /repo/builddir/packages/*.rpm . +rm ./*.src.rpm rpm --addsign ./*.rpm createrepo . diff --git a/kernel/kernel.sh b/kernel/kernel.sh index 665f7b4..5563455 100755 --- a/kernel/kernel.sh +++ b/kernel/kernel.sh @@ -1,20 +1,24 @@ #!/usr/bin/bash -FEDORA_KERNEL_VERSION=6.5.6-200.fc38 -cd /repo/kernel -koji download-build --quiet --arch=src "kernel-${FEDORA_KERNEL_VERSION}" -rpmdev-extract -q "kernel-${FEDORA_KERNEL_VERSION}".src.rpm -mv -n "kernel-${FEDORA_KERNEL_VERSION}".src/* . +set -e + +KERNEL_VERSION=6.5.6-200.fc38 + +cd "$package_builddir" +koji download-build --quiet --arch=src "kernel-$KERNEL_VERSION" +rpmdev-extract -q -C "$package_builddir" "kernel-$KERNEL_VERSION.src.rpm" +mv -n "kernel-$KERNEL_VERSION.src"/* . +rm -r "kernel-$KERNEL_VERSION.src.rpm" "kernel-$KERNEL_VERSION.src" # 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@for i in %{all_arch_configs}@for i in *.config@g" "$package_builddir/kernel.spec" # Set buildid to .t2 -sed -i 's/# define buildid .local/%define buildid .t2/g' kernel.spec +sed -i 's/# define buildid .local/%define buildid .t2/g' "$package_builddir/kernel.spec" # Disable debug kernels -sed -i "/%define with_debug /c %define with_debug 0" kernel.spec +sed -i "/%define with_debug /c %define with_debug 0" "$package_builddir/kernel.spec" -cat linux-t2-patches/extra_config > kernel-local -cat linux-t2-patches/*.patch > linux-kernel-test.patch +cat "$package_builddir/linux-t2-patches/extra_config" > "$package_builddir/kernel-local" +cat "$package_builddir/linux-t2-patches"/*.patch > "$package_builddir/linux-kernel-test.patch" cd ..