Skip to content

Commit 431c1fc

Browse files
committed
CI: Cache binpkgs for Gentoo
1 parent 19af53a commit 431c1fc

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

.github/workflows/build.yaml

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,19 @@ jobs:
2323
- name: Checkout code
2424
uses: actions/checkout@v2
2525

26+
- name: Restore package cache
27+
if: startsWith(matrix.os, 'gentoo/')
28+
uses: actions/cache/restore@v4
29+
with:
30+
path: pkg-cache
31+
key: never-exists
32+
restore-keys: |
33+
${{ matrix.os }}-pkg-cache-
34+
2635
- name: Build inside Docker
36+
id: docker-build
2737
run: |
38+
PKG_CACHE_DIR=/pkg-cache
2839
PACKAGES_CLANG='clang'
2940
PACKAGES_GCC='gcc'
3041
case "${{ matrix.os }}" in
@@ -60,18 +71,41 @@ jobs:
6071
PACKAGES_GCC='' # included in c-basic
6172
;;
6273
gentoo/*)
74+
PKG_CACHE_DIR='/var/cache/binpkgs'
6375
INIT_CMD='
64-
emerge --sync --quiet
76+
if [ -e /var/cache/binpkgs/gentoo-repo.txz ]; then
77+
rm -rf /var/db/repos/gentoo
78+
tar -C /var/db/repos -xpf /var/cache/binpkgs/gentoo-repo.txz
79+
rm /var/cache/binpkgs/gentoo-repo.txz
80+
emerge --sync --quiet || true # can fail if cache is recent enough
81+
82+
cache_cksum() {
83+
find /var/db/repos/gentoo /var/cache/binpkgs -type f -print0 | sort -z | xargs -0 sha256sum
84+
}
85+
cache_cksum > /tmp/initial-pkg-cache.cksum
86+
else
87+
emerge --sync --quiet
88+
fi
6589
'
6690
INSTALL_CMD="emerge -1 sec-keys/openpgp-keys-gentoo-release && getuto && cat /etc/portage/make.conf && USE='-perl -extra -static-analyzer -compiler-rt -openmp -sanitize -adns -alt-svc -ftp -hsts -http2 -http3 -imap -pop3 -progress-meter -psl -quic -curl_quic_openssl -smtp -tftp -websockets -nls' emerge -vuDtkg1 --noreplace --jobs=\$(nproc) --buildpkg"
67-
PACKAGES="dev-vcs/git dev-build/cmake net-misc/curl dev-libs/jansson dev-libs/libsodium virtual/pkgconfig"
91+
PACKAGES="dev-vcs/git dev-build/cmake net-misc/curl dev-libs/jansson dev-libs/libsodium virtual/pkgconfig app-portage/gentoolkit"
6892
PACKAGES_API="net-libs/libmicrohttpd"
6993
PACKAGES_CLANG="llvm-core/clang"
7094
POSTINSTALL_CMD='
7195
set +ex
7296
source /etc/profile
7397
set -ex
7498
'
99+
CLEANUP_CMD='
100+
if ls -d /var/db/pkg/llvm-core/clang-*; then
101+
[ -e /tmp/initial-pkg-cache.cksum ] && cache_cksum >/tmp/final-pkg-cache.cksum
102+
if ! diff -u /tmp/{initial,final}-pkg-cache.cksum; then
103+
( cd /var/db/repos && tar --sort=name -cpJf /var/cache/binpkgs/gentoo-repo.txz gentoo )
104+
touch /output/SAVE_CACHE
105+
eclean -t 2w packages --changed-deps
106+
fi
107+
fi
108+
'
75109
;;
76110
esac
77111
PACKAGES="$PACKAGES ${{ matrix.config.extra_deps }}"
@@ -93,8 +127,24 @@ jobs:
93127
cmake /workspace -DCMAKE_C_FLAGS='-Wall -Werror' ${{ matrix.config.cmake_args }}
94128
make -j\$(nproc)
95129
./datum_gateway --help
130+
${CLEANUP_CMD}
96131
"
97132
docker run \
133+
-v ./pkg-cache:"${PKG_CACHE_DIR}" \
134+
-v ./output:"/output" \
98135
-v "${{ github.workspace }}:/workspace":ro \
99136
"${{ matrix.os }}" \
100137
/bin/sh -c "${CMD}"
138+
139+
if [ -e output/SAVE_CACHE ]; then
140+
echo 'save_cache=true' >> "$GITHUB_OUTPUT"
141+
else
142+
echo 'save_cache=false' >> "$GITHUB_OUTPUT"
143+
fi
144+
145+
- name: Save package cache
146+
if: steps.docker-build.outputs.save_cache == 'true'
147+
uses: actions/cache/save@v4
148+
with:
149+
path: pkg-cache
150+
key: ${{ matrix.os }}-pkg-cache-${{ github.sha }}

0 commit comments

Comments
 (0)