Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
83 lines (74 loc) · 2.53 KB
/
Copy pathaction.yml
File metadata and controls
83 lines (74 loc) · 2.53 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: "Deb Cache"
description: "Update apt, cache debian packages with their dependencies, and install them."
author: "dsx137"
branding:
icon: "archive"
color: "blue"
inputs:
PACKAGES:
description: "pkg list"
required: true
WORK_DIR:
default: /tmp/deb-cache
PKG_FILE:
default: pkg.txt
runs:
using: "composite"
steps:
- name: Setup Sudo
id: sudo-setup
shell: bash
run: |
if [ "$(id -u)" -eq 0 ]; then
echo "Running as root, sudo not required."
echo "SUDO_CMD=" >> $GITHUB_ENV
else
echo "Running as non-root, sudo is required."
echo "SUDO_CMD=sudo" >> $GITHUB_ENV
fi
- name: Update apt repositories
shell: bash
run: ${{ env.SUDO_CMD }} apt-get update -y
- name: Analyze
id: analyze
shell: bash
run: |
mkdir -p ${{ inputs.WORK_DIR }}
packages=$(tr ',\n' ' ' < <(cat <<EOF
${{ inputs.PACKAGES }}
EOF
) | sed 's/^[ \t]*//;s/[ \t]*$//')
${{ env.SUDO_CMD }} apt-get install --print-uris --yes --reinstall -qq $packages \
| tr -d "'" \
| awk '{ sub(/_.*/, "", $2); print $2, $4 }' > ${{ inputs.WORK_DIR }}/${{ inputs.PKG_FILE }}
cache_key=$(sha256sum ${{ inputs.WORK_DIR }}/${{ inputs.PKG_FILE }} | awk '{print $1}')
echo "cache_key=$cache_key" >> $GITHUB_OUTPUT
echo "packages=$packages" >> $GITHUB_OUTPUT
echo "Cache key: $cache_key"
echo "Packages: $packages"
- name: Cache
uses: actions/cache@v4
id: cache-debs
with:
path: ${{ inputs.WORK_DIR }}/.cache
key: deb-cache-${{ runner.os }}-${{ steps.analyze.outputs.cache_key }}
restore-keys: |
deb-cache-${{ runner.os }}-
- name: Download
if: steps.cache-debs.outputs.cache-hit != 'true'
shell: bash
run: |
echo "Cache miss or restore key used. Downloading required packages..."
mkdir -p ${{ inputs.WORK_DIR }}/.cache
cd ${{ inputs.WORK_DIR }}/.cache/
${{ env.SUDO_CMD }} apt-get download $(awk '{print $1}' ${{ inputs.WORK_DIR }}/${{ inputs.PKG_FILE }})
- name: Install
shell: bash
run: |
echo "Installing packages..."
export DEBIAN_FRONTEND=noninteractive
${{ env.SUDO_CMD }} apt-get install --yes --no-install-recommends -o Dir::Cache::archives="${{ inputs.WORK_DIR }}/.cache/" ${{ steps.analyze.outputs.packages }}
- name: Chmod
shell: bash
run: |
${{ env.SUDO_CMD }} chmod -R 777 ${{ inputs.WORK_DIR }}