-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
201 lines (189 loc) · 7.25 KB
/
Copy pathaction.yml
File metadata and controls
201 lines (189 loc) · 7.25 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: 'Install Radare2'
description: 'Install radare2 from release packages or build from git source'
branding:
icon: 'terminal'
color: 'yellow'
inputs:
version:
description: 'Radare2 version (e.g., "6.1.2"). Empty for latest release or latest git.'
required: false
default: ''
from-git:
description: 'Build from git source instead of using release packages'
required: false
default: 'false'
prefix:
description: 'Installation prefix. Defaults to /usr on Linux, /usr/local on macOS, and RUNNER_TEMP/radare2 on Windows.'
required: false
default: '/usr'
outputs:
version:
description: 'Installed radare2 version'
value: ${{ steps.verify.outputs.version }}
prefix:
description: 'Installation prefix'
value: ${{ steps.prefix.outputs.prefix }}
runs:
using: 'composite'
steps:
- name: Resolve prefix
id: prefix
shell: bash
env:
R2_PREFIX: ${{ inputs.prefix }}
run: |
PREFIX="${R2_PREFIX:-/usr}"
case "$RUNNER_OS:$PREFIX" in
macOS:/usr) PREFIX="/usr/local" ;;
Windows:/usr) PREFIX="$RUNNER_TEMP/radare2" ;;
esac
echo "prefix=$PREFIX" >> "$GITHUB_OUTPUT"
- name: Validate release prefix
if: inputs.from-git != 'true' && runner.os != 'Windows'
shell: bash
env:
R2_PREFIX: ${{ steps.prefix.outputs.prefix }}
run: |
case "$RUNNER_OS" in
Linux) EXPECTED_PREFIX="/usr" ;;
macOS) EXPECTED_PREFIX="/usr/local" ;;
esac
if [ "$R2_PREFIX" != "$EXPECTED_PREFIX" ]; then
echo "::error::Custom prefixes are only supported for git builds on Unix; release packages install to $EXPECTED_PREFIX"
exit 1
fi
- name: Resolve version
id: resolve
shell: bash
env:
R2V_INPUT: ${{ inputs.version }}
FROM_GIT: ${{ inputs.from-git }}
run: |
R2V="$R2V_INPUT"
if [ -z "$R2V" ] && [ "$FROM_GIT" != "true" ]; then
# Resolve the tag from the releases/latest redirect: unlike the gh api,
# this needs no token and cannot return HTML instead of JSON
URL=$(curl -fsSL --retry 3 -o /dev/null -w '%{url_effective}' https://github.com/radareorg/radare2/releases/latest) || true
case "$URL" in
*/tag/*) R2V="${URL##*/tag/}" ;;
*)
echo "::error::Failed to resolve latest radare2 release version"
exit 1
;;
esac
echo "Resolved latest release: $R2V"
fi
echo "r2v=$R2V" >> "$GITHUB_OUTPUT"
# --- BUILD FROM GIT (Unix) ---
- name: Build from git (Unix)
if: inputs.from-git == 'true' && runner.os != 'Windows'
shell: bash
env:
R2V: ${{ steps.resolve.outputs.r2v }}
R2_PREFIX: ${{ steps.prefix.outputs.prefix }}
run: |
BUILD_DIR="$(mktemp -d "${RUNNER_TEMP:-/tmp}/r2build.XXXXXX")"
trap 'rm -rf "$BUILD_DIR"' EXIT
CLONEARGS=(--depth=1)
if [ -n "$R2V" ]; then
CLONEARGS+=(--branch "$R2V")
fi
git clone "${CLONEARGS[@]}" https://github.com/radareorg/radare2.git "$BUILD_DIR"
cd "$BUILD_DIR"
export CFLAGS="-O2 -Wno-unused-result"
./sys/install.sh --install "--prefix=$R2_PREFIX"
if [ -d "$R2_PREFIX/bin" ]; then
echo "$R2_PREFIX/bin" >> "$GITHUB_PATH"
fi
# --- BUILD FROM GIT (Windows) ---
- name: Build from git (Windows)
if: inputs.from-git == 'true' && runner.os == 'Windows'
shell: powershell
env:
R2V: ${{ steps.resolve.outputs.r2v }}
R2_PREFIX: ${{ steps.prefix.outputs.prefix }}
run: |
$ErrorActionPreference = 'Stop'
$cloneArgs = @('clone', '--depth=1')
if ($env:R2V) { $cloneArgs += @('--branch', $env:R2V) }
$buildDir = Join-Path $env:RUNNER_TEMP ([System.IO.Path]::GetRandomFileName())
try {
& git @cloneArgs 'https://github.com/radareorg/radare2.git' $buildDir
Set-Location $buildDir
pip install meson ninja
$prefix = $env:R2_PREFIX
meson setup --buildtype=release --prefix="$prefix" build
ninja -C build
ninja -C build install
$resolvedBin = (Resolve-Path "$prefix\bin").Path
$resolvedBin | Out-File -Append -Encoding utf8 $env:GITHUB_PATH
} finally {
Set-Location $env:RUNNER_TEMP
if (Test-Path $buildDir) {
Remove-Item -Path $buildDir -Recurse -Force
}
}
# --- INSTALL FROM RELEASE (Linux) ---
- name: Install from release (Linux)
if: inputs.from-git != 'true' && runner.os == 'Linux'
shell: bash
env:
R2V: ${{ steps.resolve.outputs.r2v }}
run: |
ARCH=$(dpkg --print-architecture 2>/dev/null || echo amd64)
BASE="https://github.com/radareorg/radare2/releases/download/${R2V}"
cd "$RUNNER_TEMP"
curl -fsSL --retry 3 -O "${BASE}/radare2_${R2V}_${ARCH}.deb" -O "${BASE}/radare2-dev_${R2V}_${ARCH}.deb"
sudo dpkg -i "radare2_${R2V}_${ARCH}.deb" "radare2-dev_${R2V}_${ARCH}.deb"
# --- INSTALL FROM RELEASE (macOS) ---
- name: Install from release (macOS)
if: inputs.from-git != 'true' && runner.os == 'macOS'
shell: bash
env:
R2V: ${{ steps.resolve.outputs.r2v }}
run: |
case "$(uname -m)" in
arm64) PKG_ARCH="arm64" ;;
*) PKG_ARCH="x64" ;;
esac
BASE="https://github.com/radareorg/radare2/releases/download/${R2V}"
cd "$RUNNER_TEMP"
curl -fsSL --retry 3 "${BASE}/radare2-${PKG_ARCH}-${R2V}.pkg" -o r2.pkg
sudo installer -pkg r2.pkg -target /
# --- INSTALL FROM RELEASE (Windows) ---
- name: Install from release (Windows)
if: inputs.from-git != 'true' && runner.os == 'Windows'
shell: powershell
env:
R2V: ${{ steps.resolve.outputs.r2v }}
R2_PREFIX: ${{ steps.prefix.outputs.prefix }}
run: |
$ErrorActionPreference = 'Stop'
$R2V = $env:R2V
$arch = $env:PROCESSOR_ARCHITECTURE
switch ($arch) {
'ARM64' { $pkgArch = 'w64-arm64' }
'x86' { $pkgArch = 'w32' }
default { $pkgArch = 'w64' }
}
$url = "https://github.com/radareorg/radare2/releases/download/$R2V/radare2-$R2V-$pkgArch.zip"
$dest = Join-Path $env:RUNNER_TEMP 'radare2.zip'
Invoke-WebRequest -Uri $url -OutFile $dest -UseBasicParsing
$prefix = $env:R2_PREFIX
if (Test-Path $prefix) { Remove-Item -Path $prefix -Recurse -Force }
Expand-Archive -Path $dest -DestinationPath $prefix -Force
# Flatten the zip's single top-level directory unless bin/ is already at the root
$subdirs = Get-ChildItem -Path $prefix -Directory
if ($subdirs.Count -eq 1 -and -not (Test-Path "$prefix\bin")) {
Get-ChildItem -Path $subdirs[0].FullName | Move-Item -Destination $prefix -Force
Remove-Item -Path $subdirs[0].FullName -Recurse -Force
}
$resolvedBin = (Resolve-Path "$prefix\bin").Path
$resolvedBin | Out-File -Append -Encoding utf8 $env:GITHUB_PATH
# --- VERIFY ---
- name: Verify installation
id: verify
shell: bash
run: |
radare2 -v
echo "version=$(radare2 -qv)" >> "$GITHUB_OUTPUT"