mirror of
https://github.com/imjasonh/krust
synced 2026-07-08 06:45:32 +00:00
- Use docker/setup-buildx-action for consistent Docker setup across all platforms - Fix Windows rust-lld configuration by using full path instead of command name - Make Docker-dependent tests fail explicitly when Docker is not available - Add proper Docker availability check in integration tests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
200 lines
6.6 KiB
YAML
200 lines
6.6 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
RUSTFLAGS: "--cfg ci"
|
|
|
|
jobs:
|
|
test:
|
|
name: Test
|
|
runs-on: ${{ matrix.os }}
|
|
strategy:
|
|
matrix:
|
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
rust: [stable, beta]
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Install Rust
|
|
uses: dtolnay/rust-toolchain@master
|
|
with:
|
|
toolchain: ${{ matrix.rust }}
|
|
targets: x86_64-unknown-linux-musl
|
|
- name: Install cross-compilation tools (Ubuntu)
|
|
if: matrix.os == 'ubuntu-latest'
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y musl-tools
|
|
- name: Install cross-compilation tools (macOS)
|
|
if: matrix.os == 'macos-latest'
|
|
run: |
|
|
# Install musl-cross from the correct tap
|
|
brew install messense/macos-cross-toolchains/x86_64-unknown-linux-musl
|
|
# Set up cargo config for cross-compilation
|
|
mkdir -p ~/.cargo
|
|
echo '[target.x86_64-unknown-linux-musl]' >> ~/.cargo/config.toml
|
|
echo 'linker = "x86_64-unknown-linux-musl-gcc"' >> ~/.cargo/config.toml
|
|
- name: Install cross-compilation tools (Windows)
|
|
if: matrix.os == 'windows-latest'
|
|
shell: pwsh
|
|
run: |
|
|
# On Windows, we'll use rust-lld as the linker for musl targets
|
|
rustup component add llvm-tools-preview
|
|
# Find rust-lld location
|
|
$rustc_sysroot = rustc --print sysroot
|
|
$rust_lld = "$rustc_sysroot\lib\rustlib\x86_64-pc-windows-msvc\bin\rust-lld.exe"
|
|
Write-Host "rust-lld location: $rust_lld"
|
|
# Create cargo config directory
|
|
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.cargo"
|
|
# Create config file with full path to rust-lld
|
|
Add-Content -Path "$env:USERPROFILE\.cargo\config.toml" -Value "[target.x86_64-unknown-linux-musl]"
|
|
Add-Content -Path "$env:USERPROFILE\.cargo\config.toml" -Value "linker = `"$rust_lld`""
|
|
- name: Set up Docker for all platforms
|
|
uses: docker/setup-buildx-action@v3
|
|
with:
|
|
install: true
|
|
- name: Cache cargo registry
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.cargo/registry
|
|
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
|
- name: Cache cargo index
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.cargo/git
|
|
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
|
- name: Cache cargo build
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: target
|
|
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
|
|
- name: Verify cross-compilation setup (Unix)
|
|
if: matrix.os != 'windows-latest'
|
|
run: |
|
|
echo "Installed targets:"
|
|
rustup target list --installed
|
|
echo "Cargo version:"
|
|
cargo --version
|
|
echo "Rustc version:"
|
|
rustc --version
|
|
echo "Available linkers:"
|
|
which x86_64-unknown-linux-musl-gcc || echo "x86_64-unknown-linux-musl-gcc not found"
|
|
which x86_64-linux-musl-gcc || echo "x86_64-linux-musl-gcc not found"
|
|
which musl-gcc || echo "musl-gcc not found"
|
|
which rust-lld || echo "rust-lld not found"
|
|
echo "Cargo config:"
|
|
cat ~/.cargo/config.toml || echo "No cargo config found"
|
|
- name: Verify cross-compilation setup (Windows)
|
|
if: matrix.os == 'windows-latest'
|
|
shell: pwsh
|
|
run: |
|
|
Write-Host "Installed targets:"
|
|
rustup target list --installed
|
|
Write-Host "Cargo version:"
|
|
cargo --version
|
|
Write-Host "Rustc version:"
|
|
rustc --version
|
|
Write-Host "rust-lld location:"
|
|
$rustc_sysroot = rustc --print sysroot
|
|
$rust_lld = "$rustc_sysroot\lib\rustlib\x86_64-pc-windows-msvc\bin\rust-lld.exe"
|
|
if (Test-Path $rust_lld) {
|
|
Write-Host "$rust_lld exists"
|
|
} else {
|
|
Write-Host "$rust_lld not found"
|
|
}
|
|
Write-Host "Cargo config:"
|
|
Get-Content "$env:USERPROFILE\.cargo\config.toml" -ErrorAction SilentlyContinue || Write-Host "No cargo config found"
|
|
- name: Build
|
|
run: cargo build --verbose
|
|
- name: Run unit tests
|
|
run: cargo test --verbose
|
|
- name: Run e2e tests
|
|
run: cargo test --test '*' --verbose
|
|
|
|
fmt:
|
|
name: Rustfmt
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Install Rust
|
|
uses: dtolnay/rust-toolchain@stable
|
|
with:
|
|
components: rustfmt
|
|
- name: Check formatting
|
|
run: cargo fmt -- --check
|
|
|
|
clippy:
|
|
name: Clippy
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Install Rust
|
|
uses: dtolnay/rust-toolchain@stable
|
|
with:
|
|
components: clippy
|
|
- name: Run clippy
|
|
run: cargo clippy -- -D warnings
|
|
|
|
integration:
|
|
name: Integration Test
|
|
runs-on: ubuntu-latest
|
|
needs: [test, fmt, clippy] # Only run after other tests pass
|
|
services:
|
|
registry:
|
|
image: registry:2
|
|
ports:
|
|
- 5000:5000
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Install Rust
|
|
uses: dtolnay/rust-toolchain@stable
|
|
with:
|
|
targets: x86_64-unknown-linux-musl
|
|
- name: Install musl tools
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y musl-tools
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
- name: Build krust
|
|
run: cargo build --release
|
|
- name: Add krust to PATH
|
|
run: echo "${{ github.workspace }}/target/release" >> $GITHUB_PATH
|
|
- name: Test krust version
|
|
run: krust version
|
|
- name: Build and run example with krust
|
|
run: |
|
|
cd example/hello-krust
|
|
# Build and push to ttl.sh (ephemeral registry)
|
|
export KRUST_REPO=ttl.sh/${{ github.run_id }}
|
|
IMAGE_REF=$(krust build ./)
|
|
echo "Built image: $IMAGE_REF"
|
|
# Run the image
|
|
docker run --rm $IMAGE_REF
|
|
- name: Test docker run with command substitution
|
|
run: |
|
|
cd example/hello-krust
|
|
export KRUST_REPO=ttl.sh/${{ github.run_id }}-test2
|
|
docker run --rm $(krust build ./)
|
|
- name: Test build with --no-push
|
|
run: |
|
|
cd example/hello-krust
|
|
krust build --no-push --image local.test/hello:latest ./
|
|
|
|
# Takes too long to run on CI, so it's commented out for now.
|
|
# coverage:
|
|
# name: Code coverage
|
|
# runs-on: ubuntu-latest
|
|
# steps:
|
|
# - uses: actions/checkout@v4
|
|
# - name: Install Rust
|
|
# uses: dtolnay/rust-toolchain@stable
|
|
# - name: Install cargo-tarpaulin
|
|
# run: cargo install cargo-tarpaulin
|
|
# - name: Generate code coverage
|
|
# run: cargo tarpaulin --verbose --workspace
|