Files
medicallib_rust/.gitea/workflows/ci-reusable.yml
T
zack3d 8095743cbf
Quick CI / quick-test (push) Failing after 1m18s
Multi-Platform CI / test-platforms (ubuntu-22.04, x86_64-unknown-linux-gnu) (push) Failing after 1m35s
Multi-Platform CI / test-platforms (windows-latest, x86_64-pc-windows-msvc) (push) Failing after 40s
Multi-Platform CI / test-native (ubuntu-22.04) (push) Failing after 1m14s
Multi-Platform CI / test-native (windows-latest) (push) Failing after 1m14s
Multi-Platform CI / package (ubuntu-22.04, x86_64-unknown-linux-gnu) (push) Has been skipped
Multi-Platform CI / package (windows-latest, x86_64-pc-windows-msvc) (push) Has been skipped
pain
2025-09-21 23:13:49 -07:00

125 lines
4.6 KiB
YAML

name: Reusable CI
on:
workflow_call:
inputs:
os:
required: true
type: string
target:
required: false
type: string
default: ""
upload-artifacts:
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
targets: ${{ inputs.target }}
- name: Install cross-compilation tools (x86_64 on ARM64)
if: runner.os == 'Linux' && runner.arch == 'ARM64' && inputs.target == 'x86_64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-x86-64-linux-gnu
- name: Configure cross-compilation (x86_64 on ARM64)
if: runner.os == 'Linux' && runner.arch == 'ARM64' && inputs.target == 'x86_64-unknown-linux-gnu'
run: |
echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Build
run: |
${{ inputs.target && format('cargo build --all-features --target {0}', inputs.target) || 'cargo build --all-features' }}
- name: Test
if: inputs.target == '' || (runner.os == 'Linux' && inputs.target == 'x86_64-unknown-linux-gnu') || (runner.os == 'Windows' && inputs.target == 'x86_64-pc-windows-msvc')
run: |
${{ inputs.target && format('cargo test --all-features --target {0}', inputs.target) || 'cargo test --all-features' }}
- name: Clippy
run: |
${{ inputs.target && format('cargo clippy --all-targets --all-features --target {0} -D warnings', inputs.target) || 'cargo clippy --all-targets --all-features -D warnings' }}
- name: Fmt check
run: |
cargo fmt --all -- --check
- name: Benchmark (Linux only)
if: runner.os == 'Linux' && inputs.target == ''
run: |
cargo bench --bench heart
- name: Security audit (Linux only)
if: runner.os == 'Linux' && inputs.target == ''
run: |
cargo install cargo-audit
cargo audit
- name: Build FFI library
if: inputs.upload-artifacts
run: |
${{ inputs.target && format('cargo build --release --features ffi --target {0}', inputs.target) || 'cargo build --release --features ffi' }}
- name: Extract version and create package
if: inputs.upload-artifacts
shell: bash
run: |
VERSION=$(sed -n 's/^version\s*=\s*"\([^"]\+\)"/\1/p' Cargo.toml | head -n1)
# Determine target directory and library extension
if [[ -n "${{ inputs.target }}" ]]; then
TARGET_DIR="target/${{ inputs.target }}/release"
PKG_BASENAME="medicallib_rust-v${VERSION}-${{ inputs.target }}"
else
TARGET_DIR="target/release"
case "${{ runner.os }}" in
Linux) PKG_BASENAME="medicallib_rust-v${VERSION}-x86_64-unknown-linux-gnu" ;;
macOS) PKG_BASENAME="medicallib_rust-v${VERSION}-x86_64-apple-darwin" ;;
Windows) PKG_BASENAME="medicallib_rust-v${VERSION}-x86_64-pc-windows-msvc" ;;
*) PKG_BASENAME="medicallib_rust-v${VERSION}-native" ;;
esac
fi
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 }}" == "Windows" ]]; then
cp "${TARGET_DIR}/medicallib_rust.dll" "${PKG_DIR}/lib/" || \
cp "${TARGET_DIR}/libmedicallib_rust.dll" "${PKG_DIR}/lib/"
elif [[ "${{ 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: Upload artifacts
if: inputs.upload-artifacts
uses: actions/upload-artifact@v4
with:
name: medicallib-rust-${{ inputs.target || runner.os }}
path: dist/