forked from daaku/gh-action-apt-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction
executable file
·41 lines (36 loc) · 1.22 KB
/
action
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash
set -euo pipefail
shopt -s dotglob nullglob
trap 'echo "${0} line ${LINENO} Status: ${?}"' ERR
CACHE_DIR=$HOME/.apt-cache
CACHE_TAR=$CACHE_DIR/root.tar.zstd
CACHE_LOG=$CACHE_DIR/log
CACHE_FILES=$CACHE_DIR/files
APT_CACHE_KEY=$(echo "$INPUTS_PACKAGES|$INPUTS_VERSION" | md5sum | awk '{print $1}')
do_pre() {
echo "APT_CACHE_KEY=$APT_CACHE_KEY" >>$GITHUB_ENV
}
do_post() {
if [[ -e $CACHE_TAR ]]; then
echo Cache hit, restoring from cache.
sudo tar xf $CACHE_TAR -C /
else
echo Cache miss, installing and caching packages.
mkdir -p $CACHE_DIR
sudo apt update
sudo DEBIAN_FRONTEND=noninteractive apt --yes install $INPUTS_PACKAGES | tee $CACHE_LOG
local installed
installed=$(cat $CACHE_LOG | grep Unpacking | awk '{print $2}')
if [[ -z $installed ]]; then
echo WARNING: no packages installed.
# create empty tar file to ensure cache hit flow
tar cf $CACHE_TAR --zstd -T /dev/null
else
# collect list of regular files installed by packages, trim leading /
echo "$installed" | xargs dpkg -L |
while IFS='\n' read -r f; do [[ -f "$f" ]] && echo "${f:1}"; done >$CACHE_FILES
tar cf $CACHE_TAR --zstd -C / -T $CACHE_FILES
fi
fi
}
do_$@