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,43 @@ 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
+ ls /var/db/repos/gentoo
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
+
87
+ emerge --sync --quiet || true # can fail if cache is recent enough
88
+ else
89
+ emerge --sync --quiet
90
+ fi
65
91
'
66
92
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"
93
+ PACKAGES="dev-vcs/git dev-build/cmake net-misc/curl dev-libs/jansson dev-libs/libsodium virtual/pkgconfig app-portage/gentoolkit "
68
94
PACKAGES_API="net-libs/libmicrohttpd"
69
95
PACKAGES_CLANG="llvm-core/clang"
70
96
POSTINSTALL_CMD='
71
97
set +ex
72
98
source /etc/profile
73
99
set -ex
74
100
'
101
+ CLEANUP_CMD='
102
+ if ls -d /var/db/pkg/llvm-core/clang-*; then
103
+ [ -e /tmp/initial-pkg-cache.cksum ] && cache_cksum >/tmp/final-pkg-cache.cksum
104
+ if ! diff -u /tmp/{initial,final}-pkg-cache.cksum; then
105
+ ( cd /var/db/repos && tar --sort=name -cpJf /var/cache/binpkgs/gentoo-repo.txz gentoo )
106
+ touch /output/SAVE_CACHE
107
+ eclean -t 2w packages --changed-deps
108
+ fi
109
+ fi
110
+ '
75
111
;;
76
112
esac
77
113
PACKAGES="$PACKAGES ${{ matrix.config.extra_deps }}"
@@ -93,8 +129,24 @@ jobs:
93
129
cmake /workspace -DCMAKE_C_FLAGS='-Wall -Werror' ${{ matrix.config.cmake_args }}
94
130
make -j\$(nproc)
95
131
./datum_gateway --help
132
+ ${CLEANUP_CMD}
96
133
"
97
134
docker run \
135
+ -v ./pkg-cache:"${PKG_CACHE_DIR}" \
136
+ -v ./output:"/output" \
98
137
-v "${{ github.workspace }}:/workspace":ro \
99
138
"${{ matrix.os }}" \
100
139
/bin/sh -c "${CMD}"
140
+
141
+ if [ -e output/SAVE_CACHE ]; then
142
+ echo 'save_cache=true' >> "$GITHUB_OUTPUT"
143
+ else
144
+ echo 'save_cache=false' >> "$GITHUB_OUTPUT"
145
+ fi
146
+
147
+ - name : Save package cache
148
+ if : steps.docker-build.outputs.save_cache == 'true'
149
+ uses : actions/cache/save@v4
150
+ with :
151
+ path : pkg-cache
152
+ key : ${{ matrix.os }}-pkg-cache-${{ github.sha }}
0 commit comments