-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.yml
More file actions
42 lines (42 loc) · 1.3 KB
/
action.yml
File metadata and controls
42 lines (42 loc) · 1.3 KB
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
42
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)(.+)')"; }
export -f aptHash
hash=$(echo "${{ inputs.packages }}" | xargs -rI {} bash -c 'aptHash {}' | tr '\n' '-' | md5sum | cut -f 1 -d ' ')
echo "packagesHash=${hash}" >> $GITHUB_ENV
- name: Cache deb files
uses: actions/cache@v5
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 }}