mirror of
https://github.com/radareorg/github-actions.git
synced 2026-11-07 06:25:58 -10:00
187 lines
6.2 KiB
YAML
187 lines
6.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'
|
|
required: false
|
|
default: '/usr'
|
|
|
|
outputs:
|
|
version:
|
|
description: 'Installed radare2 version'
|
|
value: ${{ steps.resolve.outputs.r2v }}
|
|
prefix:
|
|
description: 'Installation prefix'
|
|
value: ${{ steps.prefix.outputs.prefix }}
|
|
|
|
runs:
|
|
using: 'composite'
|
|
steps:
|
|
- name: Resolve version
|
|
id: resolve
|
|
shell: bash
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
R2V_INPUT: ${{ inputs.version }}
|
|
FROM_GIT: ${{ inputs.from-git }}
|
|
run: |
|
|
set -e
|
|
R2V="$R2V_INPUT"
|
|
if [ -z "$R2V" ] && [ "$FROM_GIT" != "true" ]; then
|
|
R2V=$(gh api repos/radareorg/radare2/releases/latest --jq .tag_name) || true
|
|
if [ -z "$R2V" ]; then
|
|
echo "::error::Failed to resolve latest radare2 release version"
|
|
exit 1
|
|
fi
|
|
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: ${{ inputs.prefix }}
|
|
run: |
|
|
set -e
|
|
CLONEARGS="--depth=1"
|
|
if [ -n "$R2V" ]; then
|
|
CLONEARGS="$CLONEARGS --branch $R2V"
|
|
fi
|
|
git clone $CLONEARGS https://github.com/radareorg/radare2.git /tmp/_r2build
|
|
cd /tmp/_r2build
|
|
export CFLAGS="-O2 -Wno-unused-result"
|
|
./sys/install.sh "$R2_PREFIX"
|
|
cd /
|
|
rm -rf /tmp/_r2build
|
|
|
|
# --- 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: ${{ inputs.prefix }}
|
|
run: |
|
|
$ErrorActionPreference = 'Stop'
|
|
$cloneArgs = @('clone', '--depth=1')
|
|
if ($env:R2V) { $cloneArgs += @('--branch', $env:R2V) }
|
|
$buildDir = Join-Path $env:RUNNER_TEMP '_r2build'
|
|
& git @cloneArgs 'https://github.com/radareorg/radare2.git' $buildDir
|
|
Set-Location $buildDir
|
|
pip install meson ninja
|
|
$prefix = $env:R2_PREFIX
|
|
if (-not $prefix -or $prefix -eq '/usr') {
|
|
$prefix = Join-Path $env:RUNNER_TEMP 'radare2'
|
|
}
|
|
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
|
|
Set-Location $env:RUNNER_TEMP
|
|
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: |
|
|
set -e
|
|
ARCH=$(dpkg --print-architecture 2>/dev/null || echo amd64)
|
|
BASE="https://github.com/radareorg/radare2/releases/download/${R2V}"
|
|
cd /tmp
|
|
wget -q "${BASE}/radare2_${R2V}_${ARCH}.deb"
|
|
wget -q "${BASE}/radare2-dev_${R2V}_${ARCH}.deb"
|
|
sudo dpkg -i "radare2_${R2V}_${ARCH}.deb"
|
|
sudo dpkg -i "radare2-dev_${R2V}_${ARCH}.deb"
|
|
rm -f radare2*.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: |
|
|
set -e
|
|
ARCH=$(uname -m)
|
|
case "$ARCH" in
|
|
arm64|aarch64) PKG_ARCH="arm64" ;;
|
|
*) PKG_ARCH="x64" ;;
|
|
esac
|
|
BASE="https://github.com/radareorg/radare2/releases/download/${R2V}"
|
|
cd /tmp
|
|
curl -fSL "${BASE}/radare2-${PKG_ARCH}-${R2V}.pkg" -o r2.pkg
|
|
sudo installer -pkg r2.pkg -target /
|
|
rm -f r2.pkg
|
|
|
|
# --- 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: ${{ inputs.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 (-not $prefix -or $prefix -eq '/usr') {
|
|
$prefix = Join-Path $env:RUNNER_TEMP 'radare2'
|
|
}
|
|
if (Test-Path $prefix) { Remove-Item -Path $prefix -Recurse -Force }
|
|
Expand-Archive -Path $dest -DestinationPath $prefix -Force
|
|
# Flatten nested subdirectory if present
|
|
$subdirs = Get-ChildItem -Path $prefix -Directory
|
|
if ($subdirs.Count -eq 1) {
|
|
$subdir = $subdirs[0]
|
|
Get-ChildItem -Path $subdir.FullName | Move-Item -Destination $prefix -Force
|
|
Remove-Item -Path $subdir.FullName -Recurse -Force
|
|
}
|
|
$resolvedBin = (Resolve-Path "$prefix\bin").Path
|
|
$resolvedBin | Out-File -Append -Encoding utf8 $env:GITHUB_PATH
|
|
|
|
# --- EXPORT PREFIX ---
|
|
- name: Export prefix
|
|
id: prefix
|
|
shell: bash
|
|
env:
|
|
R2_PREFIX: ${{ inputs.prefix }}
|
|
run: |
|
|
PREFIX="$R2_PREFIX"
|
|
if [ "$RUNNER_OS" = "Windows" ] && [ "$PREFIX" = "/usr" ]; then
|
|
PREFIX="$RUNNER_TEMP/radare2"
|
|
fi
|
|
echo "prefix=$PREFIX" >> "$GITHUB_OUTPUT"
|
|
|
|
# --- VERIFY ---
|
|
- name: Verify installation
|
|
shell: bash
|
|
run: radare2 -v
|