From 450b50cf343d61cc48f067af2a6a89fbde0da1cd Mon Sep 17 00:00:00 2001 From: Gustav Behm Date: Fri, 1 Mar 2024 14:11:32 +0100 Subject: [PATCH] Cache the nodejs-shared package --- .github/workflows/build-test.yaml | 32 +++++++++++----- build/archlinux/nodejs-shared/.gitignore | 4 ++ .../PKGBUILD.gen} | 37 ++++++++++--------- build/archlinux/nodejs-shared/build | 8 ++++ 4 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 build/archlinux/nodejs-shared/.gitignore rename build/archlinux/{node/build-libnode => nodejs-shared/PKGBUILD.gen} (50%) create mode 100755 build/archlinux/nodejs-shared/build diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index fe3eea9..6319d02 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -88,22 +88,34 @@ jobs: chown -R $UNPRIVILEGED:$UNPRIVILEGED . tee -a /etc/sudoers.d/$UNPRIVILEGED <<< "$UNPRIVILEGED ALL = NOPASSWD: $(which pacman)" - - name: Build libnode + + - name: Generate nodejs-shared's PKGBUILD + id: nodejs_shared_pkgbuild run: | - df -h . - sudo -u $UNPRIVILEGED build/archlinux/node/build-libnode - du -sh . - df -h . + PKG=$(build/archlinux/nodejs-shared/PKGBUILD.gen) + echo "pkg=$PKG" >> "$GITHUB_OUTPUT" - - name: Archive nodejs' PKGBUILD.shared + - name: Archive nodejs-shared's PKGBUILD uses: actions/upload-artifact@v4 with: - name: nodejs.PKGBUILD.shared.${{github.sha}} + name: nodejs-shared.PKGBUILD retention-days: 7 - path: "build/archlinux/node/PKGBUILD.shared" + path: "build/archlinux/nodejs-shared/PKGBUILD.shared" + + - name: Restore nodejs-shared package + id: nodejs_shared_cache + uses: actions/cache/restore@v4 + with: + path: build/archlinux/nodejs-shared/${{ steps.nodejs_shared_pkgbuild.outputs.pkg }} + key: ${{ steps.nodejs_shared_pkgbuild.outputs.pkg }} + + - name: Build nodejs-shared + if: steps.nodejs_shared_cache.outputs.cache-hit != 'true' + run: sudo -u $UNPRIVILEGED build/archlinux/nodejs-shared/build + + - name: Install nodejs-shared + run: pacman -U --noconfirm build/archlinux/nodejs-shared/${{ steps.nodejs_shared_pkgbuild.outputs.pkg }} - - name: Install libnode - run: pacman -U --noconfirm build/archlinux/node/nodejs-shared-*.pkg.tar.zst - name: Create PKGBUILD run: sudo -u $UNPRIVILEGED build/archlinux/mk diff --git a/build/archlinux/nodejs-shared/.gitignore b/build/archlinux/nodejs-shared/.gitignore new file mode 100644 index 0000000..12f8b2e --- /dev/null +++ b/build/archlinux/nodejs-shared/.gitignore @@ -0,0 +1,4 @@ +*.pkg.tar.zst + +PKGBUILD.original +PKGBUILD.shared diff --git a/build/archlinux/node/build-libnode b/build/archlinux/nodejs-shared/PKGBUILD.gen similarity index 50% rename from build/archlinux/node/build-libnode rename to build/archlinux/nodejs-shared/PKGBUILD.gen index d569b7c..03aa346 100755 --- a/build/archlinux/node/build-libnode +++ b/build/archlinux/nodejs-shared/PKGBUILD.gen @@ -3,18 +3,22 @@ set -o nounset -o pipefail -o errexit SCRIPT_DIR=$(readlink -f "$0" | xargs dirname) -cd "$SCRIPT_DIR" + +ORIGINAL="$SCRIPT_DIR/PKGBUILD.original" URL="https://gitlab.archlinux.org/archlinux/packaging/packages/nodejs/-/raw/main/PKGBUILD" echo 1>&2 "PKGBUILD URL: $URL" -wget -q -O"PKGBUILD" "$URL" +wget -q -O"$ORIGINAL" "$URL" + +ORIGINAL_SHA256=$(sha256sum "$ORIGINAL" | cut -f1 -d' ') +echo 1>&2 "$(basename "$ORIGINAL") SHA256: $ORIGINAL_SHA256" -echo 1>&2 "PKGBUILD SHA256: $(sha256sum PKGBUILD | cut -f1 -d' ')" +SHARED="$SCRIPT_DIR/PKGBUILD.shared" -cp PKGBUILD PKGBUILD.shared +cp -v "$ORIGINAL" "$SHARED" -sed -i 's/pkgname=nodejs/pkgname=nodejs-shared\nconflicts=('"'"'nodejs'"'"')/' PKGBUILD.shared -sed -i 's,./configure,./configure --shared,' PKGBUILD.shared +sed -i 's/pkgname=nodejs/pkgname=nodejs-shared\nconflicts=('"'"'nodejs'"'"')/' "$SHARED" +sed -i 's,./configure,./configure --shared,' "$SHARED" EXTRA_makedepends= for d in gcc make icu pkgconf debugedit; do @@ -25,18 +29,15 @@ for d in gcc make icu pkgconf debugedit; do done sed -i 's/^makedepends=\(.*\)$/makedepends=\1\nmakedepends+=('"$EXTRA_makedepends"')/' PKGBUILD.shared -SHA256=$(sha256sum PKGBUILD.shared | cut -f1 -d' ') -echo "PKGBUILD.shared SHA256: $SHA256" +if diff "$ORIGINAL" "$SHARED"; then + echo 1>&2 "unexpectedly similar files!" + exit 1 +fi -NCPU=$(grep -c ^processor /proc/cpuinfo) -J=$((2*NCPU)) -export MAKEFLAGS="-j $J" -echo 1>&2 "j: $J" -makepkg -s --noconfirm -p PKGBUILD.shared +SHARED_SHA256=$(sha256sum "$SHARED" | cut -f1 -d' ') +echo "$(basename "$SHARED") SHA256: $SHARED_SHA256" -pkgname=$(. PKGBUILD.shared; echo "$pkgname") -pkgver=$(. PKGBUILD.shared; echo "$pkgver") -pkgrel=$(. PKGBUILD.shared; echo "$pkgrel") -PACKAGE="$pkgname-$pkgver-$pkgrel-x86_64.pkg.tar.zst" +. "$SHARED" -echo 1>&2 "$PACKAGE: $(sha256sum "$PACKAGE" | cut -f1 -d' ')" +PACKAGE="$pkgname-$pkgver-$pkgrel-x86_64.pkg.tar.zst" +echo "$PACKAGE" diff --git a/build/archlinux/nodejs-shared/build b/build/archlinux/nodejs-shared/build new file mode 100755 index 0000000..a148c12 --- /dev/null +++ b/build/archlinux/nodejs-shared/build @@ -0,0 +1,8 @@ +#!/bin/bash + +set -o nounset -o pipefail -o errexit + +SCRIPT_DIR=$(readlink -f "$0" | xargs dirname) +cd "$SCRIPT_DIR" + +makepkg -s --noconfirm -p PKGBUILD.shared