mirror of
https://github.com/radareorg/github-actions.git
synced 2026-11-07 06:25:58 -10:00
202 lines
7.2 KiB
YAML
202 lines
7.2 KiB
YAML
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"
|