-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
87 lines (81 loc) · 3.1 KB
/
action.yaml
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
name: 'Setup bpftool'
description: 'Install bpftool static binaries'
branding:
icon: 'download'
color: 'gray-dark'
inputs:
version:
description: 'Version of bpftool to install'
required: false
default: 'latest'
path:
description: 'Installation path'
required: false
default: '/usr/local/bin'
token:
description: 'A GitHub token (e.g. secrets.GITHUB_TOKEN) to authenticate requests to GitHub API'
required: false
runs:
using: "composite"
steps:
- name: detect arch
id: arch
shell: bash
run: |
case $(uname -m) in
x86_64) echo "arch=amd64" >> $GITHUB_OUTPUT;;
aarch64) echo "arch=arm64" >> $GITHUB_OUTPUT;;
*) echo "Unsupported architecture: $(uname -m)"; exit 1;;
esac
- name: retrieve version
id: version
shell: bash {0}
env:
AUTH_TOKEN: ${{ inputs.token }} # for bash param expansion
run: |
if [[ "${{ inputs.version }}" = "latest" ]]; then
max_attempts=7
attempt=1
retry_delay=1
while [ -z "$version" ]; do
echo "Attempt $attempt: Fetching latest version from GitHub..."
response=$(curl -s ${AUTH_TOKEN:+ -H "authorization: Bearer $AUTH_TOKEN"} https://api.github.com/repos/libbpf/bpftool/releases/latest)
version=$(echo $response | jq -r '.tag_name | select (.!=null)')
attempt=$((attempt + 1))
if [ -z "$version" ]; then
if [ "$attempt" -gt "$max_attempts" ]; then
break
fi
delay=$((2 ** (attempt - 1) * retry_delay))
echo -e "$response\n"
echo "Fetching latest version from GitHub failed. Retrying in $delay seconds..."
sleep "$delay"
fi
done
if [ -z "$version" ]; then
echo "Fetching latest version failed after $max_attempts attempts. GitHub API might be unavailable, rerun this workflow later, exiting!"
exit 1
fi
else
echo "Using custom version '${{ inputs.version }}' defined by user..."
version=${{ inputs.version }}
fi
echo "Version retrieved: '$version'"
echo "version=$version" >> $GITHUB_OUTPUT
- name: cache download
id: cache-download
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
with:
path: ${{ inputs.path }}/bpftool
key: bpftool-${{ steps.version.outputs.version }}-${{ steps.arch.outputs.arch }}
- name: download
if: steps.cache-download.outputs.cache-hit != 'true'
shell: bash
env:
AUTH_TOKEN: ${{ inputs.token }} # for bash param expansion
run: |
curl -s -L ${AUTH_TOKEN:+ -H "authorization: Bearer $AUTH_TOKEN"} https://github.com/libbpf/bpftool/releases/download/${{ steps.version.outputs.version }}/bpftool-${{ steps.version.outputs.version }}-${{ steps.arch.outputs.arch }}.tar.gz | tar xz
sudo install bpftool ${{ inputs.path }}
- name: check installation
shell: bash
run: bpftool version