kingfisher/.github/workflows/release.yml
2026-02-12 16:51:55 -08:00

392 lines
12 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: build-and-release
on:
push:
branches:
- main
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: "Tag to publish (leave blank to use Cargo.toml version)"
required: false
type: string
env:
VCPKG_ROOT: C:\vcpkg
VCPKG_DOWNLOADS: C:\vcpkg\downloads
VCPKG_FEATURE_FLAGS: binarycaching
VCPKG_BINARY_SOURCES: clear;x-gha,readwrite
RUST_TOOLCHAIN: "1.92"
jobs:
# ──────────────── Linux (via Makefile) ────────────────
linux-x64:
name: Linux x64
runs-on: ubuntu-24.04
env:
CARGO_HOME: ${{ github.workspace }}/.cargo-home
steps:
- uses: actions/checkout@v4
# Free up disk space on Ubuntu runners
- name: Free Disk Space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
df -h
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
profile: minimal
override: true
- uses: swatinem/rust-cache@v2
with:
workspaces: |
. -> target
cache-directories: |
.cargo-home
cache-all-crates: true
shared-key: kingfisher-${{ runner.os }}-${{ runner.arch }}
- name: Install packaging tools
run: cargo install cargo-deb cargo-generate-rpm
- name: Build and Run Tests (Makefile linux-x64)
run: make linux-x64
- name: Fix permissions
run: sudo chown -R $(id -u):$(id -g) target .cargo-home || true
- name: Build Debian package
run: |
cargo deb --no-build --target x86_64-unknown-linux-musl \
--output target/release/kingfisher-linux-x64.deb
- name: Build RPM package
run: |
cargo generate-rpm --target x86_64-unknown-linux-musl \
--output target/release/kingfisher-linux-x64.rpm
- name: Move artifact to dist
shell: bash
run: |
mkdir -p dist
cp target/release/kingfisher-linux-x64.tgz dist/
cp target/release/kingfisher-linux-x64.deb dist/
cp target/release/kingfisher-linux-x64.rpm dist/
- uses: actions/upload-artifact@v4
with:
name: kingfisher-linux-x64.tgz
path: dist/kingfisher-linux-x64.tgz
- uses: actions/upload-artifact@v4
with:
name: kingfisher-linux-x64.deb
path: dist/kingfisher-linux-x64.deb
- uses: actions/upload-artifact@v4
with:
name: kingfisher-linux-x64.rpm
path: dist/kingfisher-linux-x64.rpm
linux-arm64:
name: Linux arm64
runs-on: ubuntu-24.04-arm
env:
CARGO_HOME: ${{ github.workspace }}/.cargo-home
steps:
- uses: actions/checkout@v4
# Free up disk space on Ubuntu runners
- name: Free Disk Space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
df -h
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
profile: minimal
override: true
- uses: swatinem/rust-cache@v2
with:
workspaces: |
. -> target
cache-directories: |
.cargo-home
cache-all-crates: true
shared-key: kingfisher-${{ runner.os }}-${{ runner.arch }}
- name: Install packaging tools
run: cargo install cargo-deb cargo-generate-rpm
- name: Build and Run Tests (Makefile linux-arm64)
run: make linux-arm64
- name: Fix permissions
run: sudo chown -R $(id -u):$(id -g) target .cargo-home || true
- name: Build Debian package
run: |
cargo deb --no-build --target aarch64-unknown-linux-musl \
--output target/release/kingfisher-linux-arm64.deb
- name: Build RPM package
run: |
cargo generate-rpm --target aarch64-unknown-linux-musl \
--output target/release/kingfisher-linux-arm64.rpm
- name: Move artifact to dist
shell: bash
run: |
mkdir -p dist
cp target/release/kingfisher-linux-arm64.tgz dist/
cp target/release/kingfisher-linux-arm64.deb dist/
cp target/release/kingfisher-linux-arm64.rpm dist/
- uses: actions/upload-artifact@v4
with:
name: kingfisher-linux-arm64.tgz
path: dist/kingfisher-linux-arm64.tgz
- uses: actions/upload-artifact@v4
with:
name: kingfisher-linux-arm64.deb
path: dist/kingfisher-linux-arm64.deb
- uses: actions/upload-artifact@v4
with:
name: kingfisher-linux-arm64.rpm
path: dist/kingfisher-linux-arm64.rpm
macos-x64:
name: macOS x64
runs-on: macos-15-intel
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
profile: minimal
override: true
- uses: swatinem/rust-cache@v2
with:
workspaces: |
. -> target
cache-all-crates: true
shared-key: kingfisher-${{ runner.os }}-${{ runner.arch }}
- name: Build Darwin x64
run: make darwin-x64
- name: Move artifacts to dist
shell: bash
run: |
mkdir -p dist
cp target/release/kingfisher-darwin-x64.tgz dist/
- uses: actions/upload-artifact@v4
with:
name: kingfisher-darwin-x64.tgz
path: dist/kingfisher-darwin-x64.tgz
macos-arm64:
name: macOS arm64
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
profile: minimal
override: true
- uses: swatinem/rust-cache@v2
with:
workspaces: |
. -> target
cache-all-crates: true
shared-key: kingfisher-${{ runner.os }}-${{ runner.arch }}
- name: Build Darwin arm64
run: make darwin-arm64
- name: Run tests
run: make tests
- name: Move artifacts to dist
shell: bash
run: |
mkdir -p dist
cp target/release/kingfisher-darwin-arm64.tgz dist/
- uses: actions/upload-artifact@v4
with:
name: kingfisher-darwin-arm64.tgz
path: dist/kingfisher-darwin-arm64.tgz
# ──────────────── Windows ────────────────
windows:
name: Windows x64
runs-on: windows-latest
# Windows-only env to keep vcpkg consistent and enable caching
env:
VCPKG_ROOT: C:\vcpkg
VCPKG_DOWNLOADS: C:\vcpkg\downloads
VCPKG_FEATURE_FLAGS: binarycaching
VCPKG_BINARY_SOURCES: clear;x-gha,readwrite
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
profile: minimal
override: true
# Cache vcpkg artifacts & downloads (so we only fetch PCRE once)
- name: Cache vcpkg artifacts
uses: actions/cache@v4
with:
path: |
C:\vcpkg\buildtrees
C:\vcpkg\packages
C:\vcpkg\installed
C:\vcpkg\downloads
C:\vcpkg\archives
C:\Users\runneradmin\AppData\Local\vcpkg\archives
key: vcpkg-${{ runner.os }}-hs-542
restore-keys: |
vcpkg-${{ runner.os }}-
vcpkg-
# Ensure downloads dir exists and seed PCRE 8.45 zip from a working mirror
- name: Pre-seed PCRE 8.45 for vcpkg
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path "$env:VCPKG_DOWNLOADS" | Out-Null
$dst = Join-Path $env:VCPKG_DOWNLOADS "pcre-8.45.zip"
if (-not (Test-Path $dst)) {
$sf = "https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.zip/download"
# Resolve to the final mirror URL (follow redirects without downloading the whole file)
$handler = New-Object System.Net.Http.HttpClientHandler
$handler.AllowAutoRedirect = $true
$client = New-Object System.Net.Http.HttpClient($handler)
try {
$req = New-Object System.Net.Http.HttpRequestMessage([System.Net.Http.HttpMethod]::Head, $sf)
$resp = $client.SendAsync($req).GetAwaiter().GetResult()
# Some mirrors dont like HEAD; fall back to GET headers only.
if (-not $resp.IsSuccessStatusCode) {
$req.Dispose()
$req = New-Object System.Net.Http.HttpRequestMessage([System.Net.Http.HttpMethod]::Get, $sf)
$resp = $client.SendAsync($req, [System.Net.Http.HttpCompletionOption]::ResponseHeadersRead).GetAwaiter().GetResult()
}
$finalUrl = $resp.RequestMessage.RequestUri.AbsoluteUri
Write-Host "Resolved SourceForge URL to: $finalUrl"
# Download the actual file
Invoke-WebRequest -Uri $finalUrl -OutFile $dst
}
finally {
$client.Dispose()
$handler.Dispose()
}
}
Get-ChildItem $env:VCPKG_DOWNLOADS
- uses: swatinem/rust-cache@v2
with:
workspaces: |
. -> target
cache-all-crates: true
shared-key: kingfisher-${{ runner.os }}-${{ runner.arch }}
- name: Build
run: .\buildwin.bat
shell: cmd
- name: Run tests
shell: pwsh
run: |
if (-not (Get-Command cargo-nextest -ErrorAction SilentlyContinue)) {
cargo install --locked cargo-nextest
}
Write-Host "▶ cargo nextest run --release --workspace --all-targets"
cargo nextest run --release --workspace --all-targets
- name: Move artifact to dist
shell: bash
run: |
mkdir -p dist
cp target/release/kingfisher-windows-x64.zip dist/
- uses: actions/upload-artifact@v4
with:
name: kingfisher-windows-x64
path: dist/kingfisher-*windows-x64*.*
release:
name: Public GitHub Release
needs: [linux-x64, linux-arm64, windows, macos-x64, macos-arm64]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Determine tag
id: version
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
TAG="${{ github.event.release.tag_name }}"
elif [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" && -n "${{ github.event.inputs.tag }}" ]]; then
TAG="${{ github.event.inputs.tag }}"
else
VERSION=$(grep -m1 '^version\s*=' Cargo.toml | cut -d '"' -f2)
TAG="v${VERSION}"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
- uses: actions/download-artifact@v4
with:
path: target/release/kingfisher-*
merge-multiple: true
- name: Extract latest changelog section
run: |
awk '
BEGIN { grabbing = 0 }
/^## \[/ {
if (grabbing) exit; # already grabbed latest entry
grabbing = 1
}
grabbing { print }
' CHANGELOG.md > .latest_changelog.md
# ── create the release using just that snippet ─────────────────────
- name: Create release & upload assets
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.version.outputs.tag }}
name: "Kingfisher ${{ steps.version.outputs.tag }}"
bodyFile: .latest_changelog.md # ← only the most-recent entry
allowUpdates: true
generateReleaseNotes: false
artifacts: target/release/**