mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 16:19:37 +00:00
update: add dev release support and update cross build
This commit is contained in:
2
.github/workflows/aur.yml
vendored
2
.github/workflows/aur.yml
vendored
@@ -15,6 +15,8 @@ permissions:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-aur:
|
publish-aur:
|
||||||
|
# Не публикуем dev/pre-release теги в AUR
|
||||||
|
if: "!contains(github.ref_name, '-')"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: aur
|
environment: aur
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
125
.github/workflows/release.yml
vendored
125
.github/workflows/release.yml
vendored
@@ -4,6 +4,11 @@ on:
|
|||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- "v*"
|
- "v*"
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: "Tag to build and upload assets for (e.g. v0.6.5)"
|
||||||
|
required: true
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@@ -13,12 +18,21 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# При ручном запуске чекаутим нужный тег
|
||||||
|
ref: ${{ github.event.inputs.tag || github.ref }}
|
||||||
|
|
||||||
- name: Prepare Release Notes
|
- name: Prepare Release Notes
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
# При ручном запуске берём версию из инпута, иначе из тега
|
||||||
|
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
||||||
|
tag="${{ github.event.inputs.tag }}"
|
||||||
|
tag="${tag#v}"
|
||||||
|
else
|
||||||
tag="${GITHUB_REF_NAME#v}"
|
tag="${GITHUB_REF_NAME#v}"
|
||||||
|
fi
|
||||||
notes_file=".github/release-notes.md"
|
notes_file=".github/release-notes.md"
|
||||||
if grep -q "^## \\[${tag}\\]" CHANGELOG.md; then
|
if grep -q "^## \\[${tag}\\]" CHANGELOG.md; then
|
||||||
awk -v ver="$tag" '
|
awk -v ver="$tag" '
|
||||||
@@ -42,83 +56,74 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
# GNU/Linux
|
# ── Linux GNU ──────────────────────────────────────────────────────
|
||||||
# x86_64
|
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: x86_64-unknown-linux-gnu
|
target: x86_64-unknown-linux-gnu
|
||||||
asset_name: dcr-x86_64-unknown-linux-gnu
|
|
||||||
|
|
||||||
# ARM64
|
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: aarch64-unknown-linux-gnu
|
target: aarch64-unknown-linux-gnu
|
||||||
asset_name: dcr-aarch64-unknown-linux-gnu
|
apt: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
|
||||||
|
env_cc: CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
|
||||||
|
env_linker: CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
|
||||||
|
|
||||||
# Musl/Linux
|
# ── Linux Musl ─────────────────────────────────────────────────────
|
||||||
# x86_64
|
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: x86_64-unknown-linux-musl
|
target: x86_64-unknown-linux-musl
|
||||||
asset_name: dcr-x86_64-unknown-linux-musl
|
apt: musl-tools
|
||||||
|
env_cc: CC_x86_64_unknown_linux_musl=musl-gcc
|
||||||
|
env_linker: CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc
|
||||||
|
|
||||||
# ARM64
|
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: aarch64-unknown-linux-musl
|
target: aarch64-unknown-linux-musl
|
||||||
asset_name: dcr-aarch64-unknown-linux-musl
|
musl_cross: aarch64-linux-musl-cross
|
||||||
|
env_cc: CC_aarch64_unknown_linux_musl=aarch64-linux-musl-gcc
|
||||||
|
env_linker: CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-gcc
|
||||||
|
|
||||||
# MacOS
|
# ── macOS ──────────────────────────────────────────────────────────
|
||||||
# x86_64 (Intel Mac, macOS 10.12+)
|
|
||||||
- os: macos-15-intel
|
- os: macos-15-intel
|
||||||
target: x86_64-apple-darwin
|
target: x86_64-apple-darwin
|
||||||
asset_name: dcr-x86_64-apple-darwin
|
|
||||||
|
|
||||||
# ARM64 (Apple Silicon Mac, macOS 11+)
|
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
target: aarch64-apple-darwin
|
target: aarch64-apple-darwin
|
||||||
asset_name: dcr-aarch64-apple-darwin
|
|
||||||
|
|
||||||
# Windows MSVC
|
# ── Windows MSVC ───────────────────────────────────────────────────
|
||||||
# x86_64
|
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
target: x86_64-pc-windows-msvc
|
target: x86_64-pc-windows-msvc
|
||||||
asset_name: dcr-x86_64-pc-windows-msvc.exe
|
|
||||||
|
|
||||||
# ARM64
|
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
target: aarch64-pc-windows-msvc
|
target: aarch64-pc-windows-msvc
|
||||||
asset_name: dcr-aarch64-pc-windows-msvc.exe
|
|
||||||
|
|
||||||
# Windows GNU
|
# ── Windows GNU ────────────────────────────────────────────────────
|
||||||
# x86_64
|
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
target: x86_64-pc-windows-gnu
|
target: x86_64-pc-windows-gnu
|
||||||
asset_name: dcr-x86_64-pc-windows-gnu.exe
|
|
||||||
|
|
||||||
# Windows LLVM
|
# gnullvm исключён: LLVM MinGW не предустановлен на GitHub Actions
|
||||||
# x86_64
|
|
||||||
- os: windows-latest
|
|
||||||
target: x86_64-pc-windows-gnullvm
|
|
||||||
asset_name: dcr-x86_64-pc-windows-gnullvm.exe
|
|
||||||
|
|
||||||
|
|
||||||
# ARM64
|
|
||||||
- os: windows-latest
|
|
||||||
target: aarch64-pc-windows-gnullvm
|
|
||||||
asset_name: dcr-aarch64-pc-windows-gnullvm.exe
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
needs: notes
|
needs: notes
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ github.event.inputs.tag || github.ref }}
|
||||||
|
|
||||||
- name: Download Release Notes
|
- name: Download Release Notes
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: release-notes
|
name: release-notes
|
||||||
path: .github
|
path: .github
|
||||||
|
|
||||||
- name: Install Linux Cross Compilation Tools
|
- name: Install apt packages
|
||||||
if: runner.os == 'Linux'
|
if: runner.os == 'Linux' && matrix.apt != ''
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu musl-tools
|
sudo apt-get install -y ${{ matrix.apt }}
|
||||||
|
|
||||||
|
- name: Install musl.cc cross-toolchain
|
||||||
|
if: matrix.musl_cross != ''
|
||||||
|
run: |
|
||||||
|
curl -fsSL "https://musl.cc/${{ matrix.musl_cross }}.tgz" | \
|
||||||
|
sudo tar -xz -C /opt
|
||||||
|
echo "/opt/${{ matrix.musl_cross }}/bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
- name: Setup Rust
|
- name: Setup Rust
|
||||||
uses: dtolnay/rust-toolchain@stable
|
uses: dtolnay/rust-toolchain@stable
|
||||||
@@ -126,22 +131,56 @@ jobs:
|
|||||||
targets: ${{ matrix.target }}
|
targets: ${{ matrix.target }}
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --release --target ${{ matrix.target }}
|
shell: bash
|
||||||
|
env:
|
||||||
|
MATRIX_ENV_CC: ${{ matrix.env_cc }}
|
||||||
|
MATRIX_ENV_LINKER: ${{ matrix.env_linker }}
|
||||||
|
run: |
|
||||||
|
if [[ -n "${MATRIX_ENV_CC:-}" ]]; then
|
||||||
|
export "${MATRIX_ENV_CC?}"
|
||||||
|
fi
|
||||||
|
if [[ -n "${MATRIX_ENV_LINKER:-}" ]]; then
|
||||||
|
export "${MATRIX_ENV_LINKER?}"
|
||||||
|
fi
|
||||||
|
cargo build --release --target ${{ matrix.target }}
|
||||||
|
|
||||||
|
- name: Derive version string
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
||||||
|
RAW_TAG="${{ github.event.inputs.tag }}"
|
||||||
|
else
|
||||||
|
RAW_TAG="${GITHUB_REF_NAME}"
|
||||||
|
fi
|
||||||
|
echo "RELEASE_TAG=${RAW_TAG}" >> "$GITHUB_ENV"
|
||||||
|
echo "RELEASE_VERSION=${RAW_TAG#v}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
- name: Derive asset name (Unix)
|
||||||
|
if: runner.os != 'Windows'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "ASSET_NAME=dcr-${{ matrix.target }}-${RELEASE_VERSION}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
- name: Derive asset name (Windows)
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
"ASSET_NAME=dcr-${{ matrix.target }}-$($env:RELEASE_VERSION).exe" >> $env:GITHUB_ENV
|
||||||
|
|
||||||
- name: Prepare Artifact (Unix)
|
- name: Prepare Artifact (Unix)
|
||||||
if: runner.os != 'Windows'
|
if: runner.os != 'Windows'
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: cp target/${{ matrix.target }}/release/dcr "$ASSET_NAME"
|
||||||
cp target/${{ matrix.target }}/release/dcr ${{ matrix.asset_name }}
|
|
||||||
|
|
||||||
- name: Prepare Artifact (Windows)
|
- name: Prepare Artifact (Windows)
|
||||||
if: runner.os == 'Windows'
|
if: runner.os == 'Windows'
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: Copy-Item "target/${{ matrix.target }}/release/dcr.exe" "$env:ASSET_NAME"
|
||||||
Copy-Item "target/${{ matrix.target }}/release/dcr.exe" "${{ matrix.asset_name }}"
|
|
||||||
|
|
||||||
- name: Upload Release Asset
|
- name: Upload Release Asset
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
files: ${{ matrix.asset_name }}
|
tag_name: ${{ env.RELEASE_TAG }}
|
||||||
|
files: ${{ env.ASSET_NAME }}
|
||||||
body_path: .github/release-notes.md
|
body_path: .github/release-notes.md
|
||||||
|
prerelease: ${{ contains(env.RELEASE_TAG, '-') }}
|
||||||
59
install.ps1
59
install.ps1
@@ -1,7 +1,8 @@
|
|||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
$RepoUrl = 'https://github.com/dexoron/dcr'
|
$RepoUrl = 'https://github.com/dexoron/dcr'
|
||||||
$ApiUrl = 'https://api.github.com/repos/dexoron/dcr/releases/latest'
|
$ApiLatest = 'https://api.github.com/repos/dexoron/dcr/releases/latest'
|
||||||
|
$ApiAll = 'https://api.github.com/repos/dexoron/dcr/releases'
|
||||||
$InstallPath = Join-Path $env:LOCALAPPDATA 'dcr'
|
$InstallPath = Join-Path $env:LOCALAPPDATA 'dcr'
|
||||||
$BinPath = Join-Path $env:USERPROFILE '.local\bin'
|
$BinPath = Join-Path $env:USERPROFILE '.local\bin'
|
||||||
$BinaryPath = Join-Path $InstallPath 'dcr.exe'
|
$BinaryPath = Join-Path $InstallPath 'dcr.exe'
|
||||||
@@ -17,6 +18,20 @@ function Require-Cmd($name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Select-Channel {
|
||||||
|
Write-Host "Choose channel:"
|
||||||
|
Write-Host " 1) Latest stable release (default)"
|
||||||
|
Write-Host " 2) Latest dev (pre-release)"
|
||||||
|
$choice = Read-Host "Enter 1 or 2 [1]"
|
||||||
|
if ([string]::IsNullOrWhiteSpace($choice)) { $choice = '1' }
|
||||||
|
|
||||||
|
switch ($choice) {
|
||||||
|
'1' { return 'stable' }
|
||||||
|
'2' { return 'dev' }
|
||||||
|
default { Fail 'Unknown option' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Select-Mode {
|
function Select-Mode {
|
||||||
Write-Host "Choose installation mode:"
|
Write-Host "Choose installation mode:"
|
||||||
Write-Host " 1) Download prebuilt binary from GitHub Release (recommended)"
|
Write-Host " 1) Download prebuilt binary from GitHub Release (recommended)"
|
||||||
@@ -38,18 +53,35 @@ function Get-Target {
|
|||||||
return 'x86_64-pc-windows-msvc'
|
return 'x86_64-pc-windows-msvc'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Fetch-ReleaseJson($channel) {
|
||||||
|
if ($channel -eq 'dev') {
|
||||||
|
Info "Looking for latest dev (pre-release)..."
|
||||||
|
$releases = Invoke-RestMethod -Method Get -Uri $ApiAll
|
||||||
|
$pre = $releases | Where-Object { $_.prerelease -eq $true } | Select-Object -First 1
|
||||||
|
if (-not $pre) { Fail "No dev (pre-release) found on GitHub" }
|
||||||
|
return $pre
|
||||||
|
} else {
|
||||||
|
return Invoke-RestMethod -Method Get -Uri $ApiLatest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Install-FromRelease {
|
function Install-FromRelease {
|
||||||
param([string]$target)
|
param([string]$target, [string]$channel)
|
||||||
|
|
||||||
New-Item -ItemType Directory -Path $InstallPath -Force | Out-Null
|
New-Item -ItemType Directory -Path $InstallPath -Force | Out-Null
|
||||||
|
|
||||||
$assetName = "dcr-$target.exe"
|
$release = Fetch-ReleaseJson $channel
|
||||||
Info "Fetching latest release..."
|
$tag = $release.tag_name
|
||||||
$release = Invoke-RestMethod -Method Get -Uri $ApiUrl
|
$version = $tag.TrimStart('v')
|
||||||
|
|
||||||
|
# Имя бинарника: dcr-<triple>-<version>.exe
|
||||||
|
$assetName = "dcr-$target-$version.exe"
|
||||||
|
|
||||||
|
Info "Fetching release $tag (channel: $channel)..."
|
||||||
|
|
||||||
$asset = $release.assets | Where-Object { $_.name -eq $assetName } | Select-Object -First 1
|
$asset = $release.assets | Where-Object { $_.name -eq $assetName } | Select-Object -First 1
|
||||||
if (-not $asset) {
|
if (-not $asset) {
|
||||||
Fail "Asset $assetName not found in release $($release.tag_name)"
|
Fail "Asset $assetName not found in release $tag"
|
||||||
}
|
}
|
||||||
|
|
||||||
Info "Downloading $assetName..."
|
Info "Downloading $assetName..."
|
||||||
@@ -58,7 +90,7 @@ function Install-FromRelease {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Install-FromSource {
|
function Install-FromSource {
|
||||||
param([string]$target)
|
param([string]$target, [string]$channel)
|
||||||
|
|
||||||
Require-Cmd 'git'
|
Require-Cmd 'git'
|
||||||
Require-Cmd 'cargo'
|
Require-Cmd 'cargo'
|
||||||
@@ -67,7 +99,15 @@ function Install-FromSource {
|
|||||||
if (Test-Path $tmp) { Remove-Item -Recurse -Force $tmp }
|
if (Test-Path $tmp) { Remove-Item -Recurse -Force $tmp }
|
||||||
|
|
||||||
Info 'Cloning repository...'
|
Info 'Cloning repository...'
|
||||||
|
if ($channel -eq 'dev') {
|
||||||
|
# Пробуем ветку dev
|
||||||
|
$result = git clone --depth 1 --branch dev $RepoUrl $tmp 2>&1
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
git clone --depth 1 $RepoUrl $tmp | Out-Null
|
git clone --depth 1 $RepoUrl $tmp | Out-Null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
git clone --depth 1 $RepoUrl $tmp | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
Info 'Building release binary...'
|
Info 'Building release binary...'
|
||||||
Push-Location $tmp
|
Push-Location $tmp
|
||||||
@@ -100,13 +140,14 @@ function Setup-Path {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Info 'Starting DCR installation'
|
Info 'Starting DCR installation'
|
||||||
|
$channel = Select-Channel
|
||||||
$mode = Select-Mode
|
$mode = Select-Mode
|
||||||
$target = Get-Target
|
$target = Get-Target
|
||||||
|
|
||||||
if ($mode -eq 'build') {
|
if ($mode -eq 'build') {
|
||||||
Install-FromSource -target $target
|
Install-FromSource -target $target -channel $channel
|
||||||
} else {
|
} else {
|
||||||
Install-FromRelease -target $target
|
Install-FromRelease -target $target -channel $channel
|
||||||
}
|
}
|
||||||
|
|
||||||
Setup-Path
|
Setup-Path
|
||||||
|
|||||||
142
install.sh
142
install.sh
@@ -6,7 +6,8 @@ INSTALL_PATH="$HOME/.local/share/dcr"
|
|||||||
BINPATH="$HOME/.local/bin"
|
BINPATH="$HOME/.local/bin"
|
||||||
LOGFILE="$HOME/.cache/dcr-install.log"
|
LOGFILE="$HOME/.cache/dcr-install.log"
|
||||||
REPO_URL="https://github.com/dexoron/dcr"
|
REPO_URL="https://github.com/dexoron/dcr"
|
||||||
GITHUB_API="https://api.github.com/repos/dexoron/dcr/releases/latest"
|
GITHUB_API_LATEST="https://api.github.com/repos/dexoron/dcr/releases/latest"
|
||||||
|
GITHUB_API_ALL="https://api.github.com/repos/dexoron/dcr/releases"
|
||||||
|
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
@@ -24,6 +25,9 @@ error() { echo -e "${RED}✖ $1${NC}"; }
|
|||||||
|
|
||||||
trap 'error "Error on line $LINENO"; exit 1' ERR
|
trap 'error "Error on line $LINENO"; exit 1' ERR
|
||||||
|
|
||||||
|
INSTALL_MODE=""
|
||||||
|
CHANNEL=""
|
||||||
|
|
||||||
check_os() {
|
check_os() {
|
||||||
case "$(uname -s)" in
|
case "$(uname -s)" in
|
||||||
Linux|Darwin) ;;
|
Linux|Darwin) ;;
|
||||||
@@ -42,8 +46,6 @@ detect_target() {
|
|||||||
Darwin:arm64|Darwin:aarch64) TARGET_TRIPLE="aarch64-apple-darwin" ;;
|
Darwin:arm64|Darwin:aarch64) TARGET_TRIPLE="aarch64-apple-darwin" ;;
|
||||||
*) error "Unsupported platform: $os/$arch"; exit 1 ;;
|
*) error "Unsupported platform: $os/$arch"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
ASSET_NAME="dcr-${TARGET_TRIPLE}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_common_dependencies() {
|
check_common_dependencies() {
|
||||||
@@ -55,10 +57,102 @@ check_build_dependencies() {
|
|||||||
command -v cargo >/dev/null 2>&1 || { error "cargo is not installed"; exit 1; }
|
command -v cargo >/dev/null 2>&1 || { error "cargo is not installed"; exit 1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select_channel() {
|
||||||
|
echo "Choose channel:"
|
||||||
|
echo " 1) Latest stable release (default)"
|
||||||
|
echo " 2) Latest dev (pre-release)"
|
||||||
|
read -r -p "Enter 1 or 2 [1]: " choice
|
||||||
|
|
||||||
|
case "${choice:-1}" in
|
||||||
|
1) CHANNEL="stable" ;;
|
||||||
|
2) CHANNEL="dev" ;;
|
||||||
|
*) error "Unknown option"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
select_install_mode() {
|
||||||
|
echo "Choose installation mode:"
|
||||||
|
echo " 1) Download prebuilt binary from GitHub Release (recommended)"
|
||||||
|
echo " 2) Build from git"
|
||||||
|
read -r -p "Enter 1 or 2 [1]: " choice
|
||||||
|
|
||||||
|
case "${choice:-1}" in
|
||||||
|
1) INSTALL_MODE="release" ;;
|
||||||
|
2) INSTALL_MODE="build" ;;
|
||||||
|
*) error "Unknown option"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Возвращает JSON нужного релиза в stdout
|
||||||
|
fetch_release_json() {
|
||||||
|
if [[ "$CHANNEL" == "dev" ]]; then
|
||||||
|
log "Looking for latest dev (pre-release)..."
|
||||||
|
local json
|
||||||
|
json="$(curl -fsSL "$GITHUB_API_ALL")"
|
||||||
|
# Первый pre-release в списке
|
||||||
|
local result
|
||||||
|
result="$(printf '%s' "$json" | python3 - <<'EOF'
|
||||||
|
import sys, json
|
||||||
|
releases = json.load(sys.stdin)
|
||||||
|
pre = [r for r in releases if r.get("prerelease", False)]
|
||||||
|
if not pre:
|
||||||
|
print("{}", end="")
|
||||||
|
else:
|
||||||
|
print(json.dumps(pre[0]), end="")
|
||||||
|
EOF
|
||||||
|
)"
|
||||||
|
if [[ -z "$result" || "$result" == "{}" ]]; then
|
||||||
|
error "No dev (pre-release) found on GitHub"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
printf '%s' "$result"
|
||||||
|
else
|
||||||
|
curl -fsSL "$GITHUB_API_LATEST"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
download_binary() {
|
||||||
|
local release_json tag version asset_name download_url
|
||||||
|
|
||||||
|
release_json="$(fetch_release_json)"
|
||||||
|
|
||||||
|
tag="$(printf '%s\n' "$release_json" | \
|
||||||
|
sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p' | head -n1)"
|
||||||
|
if [[ -z "$tag" ]]; then
|
||||||
|
error "Failed to determine release version"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Версия без ведущего 'v'
|
||||||
|
version="${tag#v}"
|
||||||
|
# Имя бинарника: dcr-<triple>-<version>
|
||||||
|
asset_name="dcr-${TARGET_TRIPLE}-${version}"
|
||||||
|
|
||||||
|
log "Fetching release ${tag} (channel: ${CHANNEL})..."
|
||||||
|
|
||||||
|
download_url="$(printf '%s\n' "$release_json" | \
|
||||||
|
sed -n "s#.*\"browser_download_url\": \"\([^\"]*/${asset_name}\)\".*#\1#p" | head -n1)"
|
||||||
|
|
||||||
|
if [[ -z "$download_url" ]]; then
|
||||||
|
error "Asset ${asset_name} not found in release ${tag}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$INSTALL_PATH"
|
||||||
|
curl -fL "$download_url" -o "$INSTALL_PATH/dcr"
|
||||||
|
chmod +x "$INSTALL_PATH/dcr"
|
||||||
|
success "Binary ${asset_name} downloaded (${tag})"
|
||||||
|
}
|
||||||
|
|
||||||
prepare_sources() {
|
prepare_sources() {
|
||||||
log "Fetching sources..."
|
log "Fetching sources..."
|
||||||
rm -rf "$TMPDIR"
|
rm -rf "$TMPDIR"
|
||||||
git clone --depth 1 "$REPO_URL" "$TMPDIR"
|
git clone --depth 1 "$REPO_URL" "$TMPDIR"
|
||||||
|
if [[ "$CHANNEL" == "dev" ]]; then
|
||||||
|
# Клонируем dev ветку, если она есть
|
||||||
|
git clone --depth 1 --branch dev "$REPO_URL" "$TMPDIR" 2>/dev/null || \
|
||||||
|
git clone --depth 1 "$REPO_URL" "$TMPDIR"
|
||||||
|
fi
|
||||||
success "Sources fetched"
|
success "Sources fetched"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,34 +162,6 @@ build_binary() {
|
|||||||
success "Build completed"
|
success "Build completed"
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_latest_release_json() {
|
|
||||||
curl -fsSL "$GITHUB_API"
|
|
||||||
}
|
|
||||||
|
|
||||||
download_binary() {
|
|
||||||
log "Fetching latest release..."
|
|
||||||
|
|
||||||
local release_json download_url tag
|
|
||||||
release_json="$(fetch_latest_release_json)"
|
|
||||||
|
|
||||||
tag="$(printf '%s\n' "$release_json" | sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p' | head -n1)"
|
|
||||||
if [[ -z "$tag" ]]; then
|
|
||||||
error "Failed to determine release version"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
download_url="$(printf '%s\n' "$release_json" | sed -n "s#.*\"browser_download_url\": \"\([^\"]*${ASSET_NAME}\)\".*#\1#p" | head -n1)"
|
|
||||||
if [[ -z "$download_url" ]]; then
|
|
||||||
error "Asset ${ASSET_NAME} not found in release ${tag}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p "$INSTALL_PATH"
|
|
||||||
curl -fL "$download_url" -o "$INSTALL_PATH/dcr"
|
|
||||||
chmod +x "$INSTALL_PATH/dcr"
|
|
||||||
success "Binary ${ASSET_NAME} downloaded (${tag})"
|
|
||||||
}
|
|
||||||
|
|
||||||
install_built_binary() {
|
install_built_binary() {
|
||||||
mkdir -p "$INSTALL_PATH"
|
mkdir -p "$INSTALL_PATH"
|
||||||
cp "$TMPDIR/target/release/dcr" "$INSTALL_PATH/dcr"
|
cp "$TMPDIR/target/release/dcr" "$INSTALL_PATH/dcr"
|
||||||
@@ -122,25 +188,13 @@ cleanup() {
|
|||||||
rm -rf "$TMPDIR" 2>/dev/null || true
|
rm -rf "$TMPDIR" 2>/dev/null || true
|
||||||
}
|
}
|
||||||
|
|
||||||
select_install_mode() {
|
|
||||||
echo "Choose installation mode:"
|
|
||||||
echo " 1) Download prebuilt binary from GitHub Release (recommended)"
|
|
||||||
echo " 2) Build from git"
|
|
||||||
read -r -p "Enter 1 or 2 [1]: " choice
|
|
||||||
|
|
||||||
case "${choice:-1}" in
|
|
||||||
1) INSTALL_MODE="release" ;;
|
|
||||||
2) INSTALL_MODE="build" ;;
|
|
||||||
*) error "Unknown option"; exit 1 ;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
log "Starting DCR installation"
|
log "Starting DCR installation"
|
||||||
|
|
||||||
check_os
|
check_os
|
||||||
detect_target
|
detect_target
|
||||||
check_common_dependencies
|
check_common_dependencies
|
||||||
|
select_channel
|
||||||
select_install_mode
|
select_install_mode
|
||||||
cleanup
|
cleanup
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user