-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yml
40 lines (40 loc) · 1.23 KB
/
action.yml
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
name: 'Apt-Cache-Action'
description: Cache Apt Packages
author: Eeems
branding:
icon: archive
color: orange
inputs:
packages:
description: List of packages to install and cache
required: true
path:
description: Location to cache deb files
required: false
default: .aptcache
runs:
using: composite
steps:
- name: Setup Apt for caching
shell: bash
run: |
sudo apt-get update -yq
aptHash(){ echo "$1-$(apt-cache policy "$1" | grep -oP '(?<=Candidate:\s)(.+)')"; }
echo "packagesHash=$(echo "${{ inputs.packages }}" | xargs -rn1 | tr '\n' '-' | md5sum | cut -f 1 -d ' ')" >> $GITHUB_ENV
- name: Cache deb files
uses: actions/cache@v4
with:
path: ${{ inputs.path }}
key: apt-cache-${{ env.packagesHash }}
restore-keys: |
apt-cache-
- name: Restore deb files from cache
shell: bash
run: |
sudo apt-get clean -yq
if compgen -G "${{ inputs.path }}/*.deb" > /dev/null; then
sudo cp -l ${{ inputs.path }}/*.deb /var/cache/apt/archives
fi
sudo apt-get install -yq ${{ inputs.packages }}
mkdir -p ${{ inputs.path }}
sudo cp -l /var/cache/apt/archives/*.deb ${{ inputs.path }}