Initial commit.

new file:   action.yml
	new file:   run.sh
This commit is contained in:
awalsh128 2021-09-19 12:38:54 -07:00
parent f37807c790
commit b48a00753b
2 changed files with 71 additions and 0 deletions

20
action.yml Normal file
View file

@ -0,0 +1,20 @@
name: 'Cached APT Install'
description: 'Install APT based packages and cache them for future runs.'
inputs:
packages:
description: 'Space delimited list of packages to install.'
required: true
default: ''
runs:
using: "composite"
steps:
- name: Cache Packages
uses: actions/cache@v2
id: cached-apt-install-packages
with:
path: "~/cached-apt-install-packages"
key: cached-apt-install-packages
- name: Install Packages
run: ${{ github.action_path }}/install.sh "~/cached-apt-install-packages" "${{ inputs.packages }}"
shell: bash

51
run.sh Executable file
View file

@ -0,0 +1,51 @@
#!/bin/bash -x
cache_dir=$1
packages="${@:2}"
if [ ! -d "$cache_dir" ]; then
echo "Cache directory '$cache_dir' does not exist."
exit 1
fi
if [ $packages = "" ]; then
echo "Packages argument cannot be empty."
exit 2
fi
for dir in `ls $cache_dir`; do
remove=true
for package in $packages; do
if [ $dir == $package ]; then
remove=false
break
fi
done
[ $remove ] && rm -fr $cache_dir/$dir
done
for package in $packages; do
package_dir=$cache_dir/$package
if [ -d $package_dir ]; then
echo "Restoring $package from cache $package_dir..."
sudo cp --verbose --force --recursive $package_dir/* /
sudo apt-get --yes --only-upgrade install $package
else
echo "Clean install $package and caching to $package_dir..."
sudo apt-get --yes install $package
echo "Caching $package to $package_dir..."
mkdir --parents $package_dir
# Pipe all package files (no folders) to copy command.
sudo dpkg -L $package |
while IFS= read -r f; do
if test -f $f; then echo $f; fi;
done |
xargs cp -p -t $package_dir
fi
done