geth/.github/workflows/release.yml

132 lines
4.2 KiB
YAML

name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
prerelease:
description: "Mark the GitHub release as a prerelease"
required: false
default: "true"
type: choice
options: ["true", "false"]
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: linux-x86_64
binary: geth
- os: macos-latest
target: macos
binary: geth
- os: windows-latest
target: windows-x86_64
binary: geth.exe
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache Cargo
uses: Swatinem/rust-cache@v2
- name: Build release binary
run: cargo build --release -p geth
- name: Package Unix artifact
if: runner.os != 'Windows'
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME:-manual}"
pkg="geth-${version}-${{ matrix.target }}"
mkdir -p "${pkg}" dist
cp "target/release/${{ matrix.binary }}" "${pkg}/"
cp README.md "${pkg}/"
cp LICENSE-* "${pkg}/"
cp -R docs "${pkg}/docs"
tar -czf "dist/${pkg}.tar.gz" "${pkg}"
- name: Smoke-test Unix artifact
if: runner.os != 'Windows'
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME:-manual}"
pkg="geth-${version}-${{ matrix.target }}"
mkdir -p smoke
tar -xzf "dist/${pkg}.tar.gz" -C smoke
"smoke/${pkg}/${{ matrix.binary }}" --version
test -f "smoke/${pkg}/README.md"
test -f "smoke/${pkg}/LICENSE-MIT"
test -f "smoke/${pkg}/LICENSE-APACHE"
test -d "smoke/${pkg}/docs"
- name: Package Windows artifact
if: runner.os == 'Windows'
shell: pwsh
run: |
$version = if ($env:GITHUB_REF_NAME) { $env:GITHUB_REF_NAME } else { "manual" }
$pkg = "geth-$version-${{ matrix.target }}"
New-Item -ItemType Directory -Force -Path $pkg, dist | Out-Null
Copy-Item "target/release/${{ matrix.binary }}" "$pkg/"
Copy-Item README.md "$pkg/"
Copy-Item LICENSE-* "$pkg/"
Copy-Item docs "$pkg/docs" -Recurse
Compress-Archive -Path "$pkg/*" -DestinationPath "dist/$pkg.zip" -Force
- name: Smoke-test Windows artifact
if: runner.os == 'Windows'
shell: pwsh
run: |
$version = if ($env:GITHUB_REF_NAME) { $env:GITHUB_REF_NAME } else { "manual" }
$pkg = "geth-$version-${{ matrix.target }}"
New-Item -ItemType Directory -Force -Path smoke | Out-Null
Expand-Archive -Path "dist/$pkg.zip" -DestinationPath "smoke/$pkg" -Force
& "smoke/$pkg/${{ matrix.binary }}" --version
if (!(Test-Path "smoke/$pkg/README.md")) { throw "README.md missing from archive" }
if (!(Test-Path "smoke/$pkg/LICENSE-MIT")) { throw "LICENSE-MIT missing from archive" }
if (!(Test-Path "smoke/$pkg/LICENSE-APACHE")) { throw "LICENSE-APACHE missing from archive" }
if (!(Test-Path "smoke/$pkg/docs")) { throw "docs missing from archive" }
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: geth-${{ matrix.target }}
path: dist/*
if-no-files-found: error
github-release:
name: publish GitHub release
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Publish release
uses: softprops/action-gh-release@v2
with:
files: dist/*
prerelease: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.prerelease == 'true' }}
generate_release_notes: true