Skip to content

Commit

Permalink
Cache the nodejs-shared package
Browse files Browse the repository at this point in the history
  • Loading branch information
rootmos committed Mar 1, 2024
1 parent 6648c97 commit 450b50c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
32 changes: 22 additions & 10 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions build/archlinux/nodejs-shared/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.pkg.tar.zst

PKGBUILD.original
PKGBUILD.shared
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
8 changes: 8 additions & 0 deletions build/archlinux/nodejs-shared/build
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 450b50c

Please sign in to comment.