-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
93 lines (81 loc) · 2.64 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
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
84
85
86
87
88
89
90
91
92
93
name: Add APT repository and key
description: Add an APT repository (with its key) for installing packages
inputs:
uri:
description: URI of the APT repository
required: true
key:
description: URL or path to the GPG public key
default: ''
suite:
description: Suite of the APT repository
default: ''
cache:
description: Cache any downloaded prerequisite packages
default: true
branding:
icon: plus-square
color: orange
runs:
using: "composite"
steps:
- name: Prepare
id: prep
run: |
prerequisites=""
if [[ "${{ inputs.uri }}" == "https://"* ]] || [[ "${{ inputs.key }}" == "https://"* ]]; then
prerequisites+=" ca-certificates"
fi
if [[ "${{ inputs.key }}" == "http://"* ]] || [[ "${{ inputs.key }}" == "https://"* ]]; then
prerequisites+=" wget"
fi
echo "prerequisites=$prerequisites" >> "$GITHUB_OUTPUT"
shell: bash
- name: Install prerequisites
if: ${{ steps.prep.outputs.prerequisites }}
uses: gerlero/apt-install@v1
with:
packages: ${{ steps.prep.outputs.prerequisites }}
upgrade: false
install-recommends: false
cache: ${{ inputs.cache }}
- name: Begin
run: |
sudo() {
if [ $(id -u) -eq 0 ]; then
"$@"
else
command sudo "$@"
fi
}
if [ -n "${{ inputs.key }}" ]; then
echo ::group::Add APT key
mkdir -p "${{ runner.temp }}"
staging_key="${{ runner.temp }}/add-apt-repository.asc"
if [[ ${{ inputs.key }} == "http://"* ]] || [[ ${{ inputs.key }} == "https://"* ]]; then
wget -O "$staging_key" -- "${{ inputs.key }}"
else
cp "${{ inputs.key }}" "$staging_key"
fi
sudo mkdir -p /etc/apt/keyrings
final_key=/etc/apt/keyrings/add-apt-repository-$(sha256sum "$staging_key" | cut -d' ' -f1).asc
sudo mv "$staging_key" "$final_key"
echo ::endgroup::
fi
echo ::group::Add APT repository
if [ -n "${{ inputs.key }}" ]; then
options=" [signed-by=$final_key]"
else
options=""
fi
if [ -n "${{ inputs.suite }}" ]; then
suite=${{ inputs.suite }}
else
suite=$(sed -ne 's/^VERSION_CODENAME=//p' /etc/os-release)
fi
line="deb$options ${{ inputs.uri }} $suite main"
file=/etc/apt/sources.list.d/add-apt-repository.list
grep --quiet --line-regexp --fixed-strings "$line" "$file" \
|| echo "$line" | sudo tee --append "$file"
echo ::endgroup::
shell: bash