Files
medicallib_rust/.gitea/workflows/ci-reusable.yml
T
zack3d 5f51ebd62f
Multi-Platform CI / test-platforms (ubuntu-22.04) (push) Successful in 22s
Multi-Platform CI / test-platforms (windows-latest) (push) Successful in 18s
Multi-Platform CI / package (ubuntu-22.04) (push) Successful in 37s
Multi-Platform CI / package (windows-latest) (push) Successful in 36s
weh
2025-09-23 20:38:33 -07:00

170 lines
6.4 KiB
YAML

name: Reusable CI
on:
workflow_call:
inputs:
os:
required: true
type: string
upload-artifacts:
required: false
type: boolean
default: false
package-only:
description: "Skip tests/lints; build + package only"
required: false
type: boolean
default: false
jobs:
ci:
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Build
if: ${{ !inputs.package-only }}
run: cargo build --all-features
- name: Test
if: ${{ !inputs.package-only }}
run: cargo test --all-features
- name: Clippy
if: ${{ !inputs.package-only }}
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Fmt check
if: ${{ !inputs.package-only }}
run: |
cargo fmt --all -- --check
- name: Security audit (Linux only)
if: ${{ !inputs.package-only && runner.os == 'Linux' }}
run: |
cargo install cargo-audit
cargo audit
- name: Build FFI library
if: inputs.upload-artifacts
run: cargo build --release --features ffi
- name: Extract version and create package (non-Windows)
if: inputs.upload-artifacts && runner.os != 'Windows'
shell: bash
run: |
VERSION=$(sed -n 's/^version\s*=\s*"\([^"]\+\)"/\1/p' Cargo.toml | head -n1)
# Determine target directory and library extension
TARGET_DIR="target/release"
# Map runner.arch to Rust target arch
case "${{ runner.arch }}" in
ARM64) ARCH_TRIPLE="aarch64" ;;
X64) ARCH_TRIPLE="x86_64" ;;
*) ARCH_TRIPLE="unknown" ;;
esac
# Compose package basename with OS + arch
case "${{ runner.os }}" in
Linux) PKG_BASENAME="medicallib_rust-v${VERSION}-${ARCH_TRIPLE}-unknown-linux-gnu" ;;
macOS) PKG_BASENAME="medicallib_rust-v${VERSION}-${ARCH_TRIPLE}-apple-darwin" ;;
*) PKG_BASENAME="medicallib_rust-v${VERSION}-native" ;;
esac
PKG_DIR="dist/${PKG_BASENAME}"
echo "Creating package ${PKG_BASENAME}..."
mkdir -p "${PKG_DIR}/include" "${PKG_DIR}/lib" "${PKG_DIR}/examples/c"
# Copy header and example
cp ffi/medicallib.h "${PKG_DIR}/include/"
cp examples/c/ffi_example.c "${PKG_DIR}/examples/c/"
cp README.md INSTALL.md MIGRATION.md ARCHITECTURE.md "${PKG_DIR}/" || true
# Copy library with proper extension detection
if [[ "${{ runner.os }}" == "macOS" ]]; then
cp "${TARGET_DIR}/libmedicallib_rust.dylib" "${PKG_DIR}/lib/"
else
cp "${TARGET_DIR}/libmedicallib_rust.so" "${PKG_DIR}/lib/"
fi
# Create archives
tar -C dist -czf "dist/${PKG_BASENAME}.tar.gz" "${PKG_BASENAME}"
if command -v zip >/dev/null 2>&1; then
(cd dist && zip -r9 "${PKG_BASENAME}.zip" "${PKG_BASENAME}")
fi
- name: Extract version and create package (Windows)
if: inputs.upload-artifacts && runner.os == 'Windows'
shell: pwsh
run: |
$versionMatch = (Get-Content Cargo.toml | Select-String -Pattern '^version\s*=\s*"([^"]+)"' -AllMatches | ForEach-Object { $_.Matches } | Select-Object -First 1)
if (-not $versionMatch) { Write-Error "Unable to parse version from Cargo.toml"; exit 1 }
$VERSION = $versionMatch.Groups[1].Value
switch ("${{ runner.arch }}") {
'ARM64' { $ARCH_TRIPLE = 'aarch64' }
'X64' { $ARCH_TRIPLE = 'x86_64' }
default { $ARCH_TRIPLE = 'unknown' }
}
$PKG_BASENAME = "medicallib_rust-v$VERSION-$ARCH_TRIPLE-pc-windows-msvc"
$PKG_DIR = Join-Path 'dist' $PKG_BASENAME
Write-Host "Creating package $PKG_BASENAME..."
New-Item -ItemType Directory -Force -Path (Join-Path $PKG_DIR 'include') | Out-Null
New-Item -ItemType Directory -Force -Path (Join-Path $PKG_DIR 'lib') | Out-Null
New-Item -ItemType Directory -Force -Path (Join-Path $PKG_DIR 'examples' 'c') | Out-Null
Copy-Item -Force -Path 'ffi/medicallib.h' -Destination (Join-Path $PKG_DIR 'include')
Copy-Item -Force -Path 'examples/c/ffi_example.c' -Destination (Join-Path $PKG_DIR 'examples/c')
Copy-Item -Force -Path 'README.md','INSTALL.md','MIGRATION.md','ARCHITECTURE.md' -Destination $PKG_DIR -ErrorAction SilentlyContinue
$TARGET_DIR = 'target\release'
$dllCandidates = @(
(Join-Path $TARGET_DIR 'medicallib_rust.dll'),
(Join-Path $TARGET_DIR 'libmedicallib_rust.dll')
)
$copied = $false
foreach ($file in $dllCandidates) {
if (Test-Path $file) {
Copy-Item -Force -Path $file -Destination (Join-Path $PKG_DIR 'lib')
$copied = $true
break
}
}
if (-not $copied) {
$found = Get-ChildItem -Path $TARGET_DIR -Filter '*medicallib_rust*.dll' -ErrorAction SilentlyContinue | Select-Object -First 1
if ($found) {
Copy-Item -Force $found.FullName -Destination (Join-Path $PKG_DIR 'lib')
$copied = $true
}
}
if (-not $copied) { Write-Error "Could not locate built DLL in $TARGET_DIR"; exit 1 }
$zipPath = Join-Path 'dist' ("{0}.zip" -f $PKG_BASENAME)
Compress-Archive -Path $PKG_DIR -DestinationPath $zipPath -Force
- name: Upload Linux/macOS Artifacts
if: inputs.upload-artifacts && runner.os != 'Windows'
uses: https://github.com/christopherHX/gitea-upload-artifact@v4
with:
name: medicallib-rust-${{ runner.os }}-${{ github.run_number }}
path: |
dist/*.tar.gz
dist/*.zip
if-no-files-found: error
overwrite: false
- name: Upload Windows Artifact
if: inputs.upload-artifacts && runner.os == 'Windows'
uses: https://github.com/christopherHX/gitea-upload-artifact@v4
with:
name: medicallib-rust-${{ runner.os }}-${{ github.run_number }}
path: dist/*.zip # <-- Only look for the .zip file
if-no-files-found: error
overwrite: false