23
23
- name : Checkout code
24
24
uses : actions/checkout@v2
25
25
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
+
26
35
- name : Build inside Docker
36
+ id : docker-build
27
37
run : |
38
+ PKG_CACHE_DIR=/pkg-cache
28
39
PACKAGES_CLANG='clang'
29
40
PACKAGES_GCC='gcc'
30
41
case "${{ matrix.os }}" in
@@ -60,18 +71,41 @@ jobs:
60
71
PACKAGES_GCC='' # included in c-basic
61
72
;;
62
73
gentoo/*)
74
+ PKG_CACHE_DIR='/var/cache/binpkgs'
63
75
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
65
89
'
66
90
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 "
68
92
PACKAGES_API="net-libs/libmicrohttpd"
69
93
PACKAGES_CLANG="llvm-core/clang"
70
94
POSTINSTALL_CMD='
71
95
set +ex
72
96
source /etc/profile
73
97
set -ex
74
98
'
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
+ '
75
109
;;
76
110
esac
77
111
PACKAGES="$PACKAGES ${{ matrix.config.extra_deps }}"
@@ -93,8 +127,24 @@ jobs:
93
127
cmake /workspace -DCMAKE_C_FLAGS='-Wall -Werror' ${{ matrix.config.cmake_args }}
94
128
make -j\$(nproc)
95
129
./datum_gateway --help
130
+ ${CLEANUP_CMD}
96
131
"
97
132
docker run \
133
+ -v ./pkg-cache:"${PKG_CACHE_DIR}" \
134
+ -v ./output:"/output" \
98
135
-v "${{ github.workspace }}:/workspace":ro \
99
136
"${{ matrix.os }}" \
100
137
/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