ci: 调整 GitHub Actions 构建与发布流程

This commit is contained in:
mofeng-git
2026-05-19 10:06:37 +08:00
parent a3ebcded34
commit cb0c66af96
5 changed files with 116 additions and 17 deletions

View File

@@ -1,11 +1,18 @@
name: Build name: Build
on: on:
push:
branches:
- main
pull_request: pull_request:
workflow_dispatch: workflow_dispatch:
inputs:
publish_release:
description: Publish GitHub Release
required: false
default: false
type: boolean
release_tag:
description: Release tag name when publishing
required: false
default: ""
permissions: permissions:
contents: read contents: read
@@ -26,7 +33,7 @@ jobs:
- uses: actions/setup-node@v4 - uses: actions/setup-node@v4
with: with:
node-version: 20 node-version: 24
cache: npm cache: npm
cache-dependency-path: web/package-lock.json cache-dependency-path: web/package-lock.json
@@ -63,10 +70,10 @@ jobs:
run: cargo install cross --locked run: cargo install cross --locked
- name: Build linux binary - name: Build linux binary
run: bash build/build-images.sh x86_64 run: bash build/build-images.sh
- name: Package deb - name: Package deb
run: bash build/package-deb.sh amd64 run: bash build/package-deb.sh
- name: Upload deb - name: Upload deb
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
@@ -99,14 +106,14 @@ jobs:
run: | run: |
$env:VCPKG_ROOT = "C:\vcpkg" $env:VCPKG_ROOT = "C:\vcpkg"
$env:VCPKG_DEFAULT_TRIPLET = "x64-windows-static" $env:VCPKG_DEFAULT_TRIPLET = "x64-windows-static"
$env:VCPKG_INSTALLED_DIR = Join-Path $env:VCPKG_ROOT "installed" $env:VCPKG_INSTALLED_DIR = Join-Path $pwd "vcpkg_installed"
if (-not (Test-Path $env:VCPKG_ROOT)) { if (-not (Test-Path $env:VCPKG_ROOT)) {
git clone https://github.com/microsoft/vcpkg $env:VCPKG_ROOT git clone https://github.com/microsoft/vcpkg $env:VCPKG_ROOT
} }
& "$env:VCPKG_ROOT\bootstrap-vcpkg.bat" -disableMetrics & "$env:VCPKG_ROOT\bootstrap-vcpkg.bat" -disableMetrics
& "$env:VCPKG_ROOT\vcpkg.exe" install --triplet $env:VCPKG_DEFAULT_TRIPLET & "$env:VCPKG_ROOT\vcpkg.exe" install --triplet $env:VCPKG_DEFAULT_TRIPLET --x-install-root="$env:VCPKG_INSTALLED_DIR"
$tripletRoot = Join-Path $env:VCPKG_INSTALLED_DIR $env:VCPKG_DEFAULT_TRIPLET $tripletRoot = Join-Path $env:VCPKG_INSTALLED_DIR $env:VCPKG_DEFAULT_TRIPLET
$env:TURBOJPEG_SOURCE = "explicit" $env:TURBOJPEG_SOURCE = "explicit"
@@ -131,3 +138,39 @@ jobs:
path: target/x86_64-pc-windows-msvc/release/one-kvm.exe path: target/x86_64-pc-windows-msvc/release/one-kvm.exe
if-no-files-found: error if-no-files-found: error
retention-days: 7 retention-days: 7
release:
runs-on: ubuntu-22.04
needs: [deb, windows]
if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish_release }}
timeout-minutes: 30
permissions:
contents: write
steps:
- name: Validate release tag
run: |
if [ -z "${{ inputs.release_tag }}" ]; then
echo "release_tag is required when publish_release is true"
exit 1
fi
- name: Download deb artifact
uses: actions/download-artifact@v4
with:
name: one-kvm-deb
path: release-artifacts/deb
- name: Download exe artifact
uses: actions/download-artifact@v4
with:
name: one-kvm-windows-exe
path: release-artifacts/windows
- name: Publish GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.release_tag }}
generate_release_notes: true
files: |
release-artifacts/deb/*.deb
release-artifacts/windows/one-kvm.exe

View File

@@ -3,6 +3,7 @@ param(
[string]$Target = "x86_64-pc-windows-msvc", [string]$Target = "x86_64-pc-windows-msvc",
[string]$Triplet = "x64-windows-static", [string]$Triplet = "x64-windows-static",
[string]$VcpkgRoot = $env:VCPKG_ROOT, [string]$VcpkgRoot = $env:VCPKG_ROOT,
[string]$VcpkgInstalledRoot = $env:VCPKG_INSTALLED_DIR,
[switch]$NoDefaultFeatures, [switch]$NoDefaultFeatures,
[string[]]$Features = @(), [string[]]$Features = @(),
[Parameter(ValueFromRemainingArguments = $true)] [Parameter(ValueFromRemainingArguments = $true)]
@@ -19,8 +20,12 @@ if ([string]::IsNullOrWhiteSpace($VcpkgRoot)) {
} }
$VcpkgRoot = [System.IO.Path]::GetFullPath($VcpkgRoot) $VcpkgRoot = [System.IO.Path]::GetFullPath($VcpkgRoot)
$vcpkgInstalledRoot = Join-Path $VcpkgRoot "installed" if ([string]::IsNullOrWhiteSpace($VcpkgInstalledRoot)) {
$vcpkgTripletRoot = Join-Path $vcpkgInstalledRoot $Triplet $VcpkgInstalledRoot = Join-Path $VcpkgRoot "installed"
}
$VcpkgInstalledRoot = [System.IO.Path]::GetFullPath($VcpkgInstalledRoot)
$vcpkgTripletRoot = Join-Path $VcpkgInstalledRoot $Triplet
$turbojpegLibDir = Join-Path $vcpkgTripletRoot "lib" $turbojpegLibDir = Join-Path $vcpkgTripletRoot "lib"
$turbojpegIncludeDir = Join-Path $vcpkgTripletRoot "include" $turbojpegIncludeDir = Join-Path $vcpkgTripletRoot "include"
@@ -34,6 +39,7 @@ if (-not (Test-Path $turbojpegLibDir) -or -not (Test-Path $turbojpegIncludeDir))
$env:VCPKG_ROOT = $VcpkgRoot $env:VCPKG_ROOT = $VcpkgRoot
$env:VCPKG_DEFAULT_TRIPLET = $Triplet $env:VCPKG_DEFAULT_TRIPLET = $Triplet
$env:VCPKG_INSTALLED_DIR = $VcpkgInstalledRoot
$env:TURBOJPEG_SOURCE = "explicit" $env:TURBOJPEG_SOURCE = "explicit"
$env:TURBOJPEG_LIB_DIR = $turbojpegLibDir $env:TURBOJPEG_LIB_DIR = $turbojpegLibDir
$env:TURBOJPEG_INCLUDE_DIR = $turbojpegIncludeDir $env:TURBOJPEG_INCLUDE_DIR = $turbojpegIncludeDir

View File

@@ -91,8 +91,8 @@ mod ffmpeg {
ffmpeg_ffi(); ffmpeg_ffi();
// Try VCPKG first, fallback to system FFmpeg via pkg-config // Try VCPKG first, fallback to system FFmpeg via pkg-config
if let Ok(vcpkg_root) = std::env::var("VCPKG_ROOT") { if let Some(vcpkg_installed) = vcpkg_installed_root() {
link_vcpkg(builder, vcpkg_root.into()); link_vcpkg(builder, vcpkg_installed);
} else { } else {
// Use system FFmpeg via pkg-config // Use system FFmpeg via pkg-config
link_system_ffmpeg(builder); link_system_ffmpeg(builder);
@@ -104,6 +104,22 @@ mod ffmpeg {
build_ffmpeg_capture(builder); build_ffmpeg_capture(builder);
} }
fn vcpkg_installed_root() -> Option<PathBuf> {
println!("cargo:rerun-if-env-changed=VCPKG_INSTALLED_DIR");
println!("cargo:rerun-if-env-changed=VCPKG_ROOT");
if let Ok(path) = std::env::var("VCPKG_INSTALLED_DIR") {
if !path.trim().is_empty() {
return Some(PathBuf::from(path));
}
}
std::env::var("VCPKG_ROOT")
.ok()
.filter(|path| !path.trim().is_empty())
.map(|path| PathBuf::from(path).join("installed"))
}
/// Link system FFmpeg using pkg-config or custom path /// Link system FFmpeg using pkg-config or custom path
/// Supports both static and dynamic linking based on FFMPEG_STATIC env var /// Supports both static and dynamic linking based on FFMPEG_STATIC env var
fn link_system_ffmpeg(builder: &mut Build) { fn link_system_ffmpeg(builder: &mut Build) {
@@ -274,7 +290,6 @@ mod ffmpeg {
target = target.replace("x64", "x86"); target = target.replace("x64", "x86");
} }
println!("cargo:info={}", target); println!("cargo:info={}", target);
path.push("installed");
path.push(target); path.push(target);
println!( println!(
@@ -297,12 +312,14 @@ mod ffmpeg {
"vpx", "vpx",
"libx264", "libx264",
"x265-static", "x265-static",
"libmfx",
]); ]);
} }
for lib in static_libs { for lib in static_libs {
println!("cargo:rustc-link-lib=static={}", lib); println!("cargo:rustc-link-lib=static={}", lib);
} }
if target_os == "windows" {
link_windows_qsv_lib(&path.join("lib"));
}
} }
let include = path.join("include"); let include = path.join("include");
@@ -311,6 +328,16 @@ mod ffmpeg {
include include
} }
fn link_windows_qsv_lib(lib_dir: &Path) {
if lib_dir.join("libmfx.lib").exists() {
println!("cargo:rustc-link-lib=static=libmfx");
println!("cargo:info=Using Windows QSV support library libmfx.lib");
return;
}
println!("cargo:warning=Windows QSV support library not found in {}", lib_dir.display());
}
fn link_os() { fn link_os() {
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap(); let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();

View File

@@ -82,8 +82,8 @@ fn generate_bindings(cpp_dir: &Path) {
fn link_libyuv() { fn link_libyuv() {
// Try vcpkg first // Try vcpkg first
if let Ok(vcpkg_root) = env::var("VCPKG_ROOT") { if let Some(vcpkg_installed) = vcpkg_installed_root() {
if link_vcpkg(vcpkg_root.into()) { if link_vcpkg(vcpkg_installed) {
return; return;
} }
} }
@@ -109,6 +109,22 @@ fn link_libyuv() {
); );
} }
fn vcpkg_installed_root() -> Option<PathBuf> {
println!("cargo:rerun-if-env-changed=VCPKG_INSTALLED_DIR");
println!("cargo:rerun-if-env-changed=VCPKG_ROOT");
if let Ok(path) = env::var("VCPKG_INSTALLED_DIR") {
if !path.trim().is_empty() {
return Some(PathBuf::from(path));
}
}
env::var("VCPKG_ROOT")
.ok()
.filter(|path| !path.trim().is_empty())
.map(|path| PathBuf::from(path).join("installed"))
}
fn link_vcpkg(mut path: PathBuf) -> bool { fn link_vcpkg(mut path: PathBuf) -> bool {
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
@@ -130,7 +146,6 @@ fn link_vcpkg(mut path: PathBuf) -> bool {
} }
}; };
path.push("installed");
path.push(triplet); path.push(triplet);
let include_path = path.join("include"); let include_path = path.join("include");

8
vcpkg-configuration.json Normal file
View File

@@ -0,0 +1,8 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg-configuration.schema.json",
"default-registry": {
"kind": "git",
"repository": "https://github.com/microsoft/vcpkg",
"baseline": "1e199d32ad53aab1defda61ce41c380302e3f95c"
}
}