name: Rust
permissions:
contents: read
on:
push:
pull_request:
env:
CARGO_TERM_COLOR: always
CARGO_TERM_VERBOSE: true
jobs:
rustfmt:
if: (github.event_name != 'pull_request' && ! github.event.pull_request.head.repo.fork) || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
submodules: recursive
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 with:
toolchain: nightly
components: rustfmt
- name: Run rustfmt
run: cargo fmt -- --check
clippy:
permissions:
security-events: write
if: (github.event_name != 'pull_request' && ! github.event.pull_request.head.repo.fork) || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork)
runs-on: ubuntu-latest
container:
image: ghcr.io/terrapkg/builder:f44
options: --cap-add=SYS_ADMIN --privileged
env:
DATABASE_URL: postgres://postgres:postgres@postgres:5432/subatomic
ZSTD_SYS_USE_PKG_CONFIG: "1"
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: subatomic
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Install dependencies
run: dnf in -y clang gcc 'pkgconfig(libzstd)' 'pkgconfig(openssl)' appstream
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
submodules: recursive
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 with:
toolchain: nightly
components: clippy
- name: Cache Cargo
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 with:
path: |
~/.cargo/
target
key: ${{ runner.os }}-cargo-nightly-${{ hashFiles('rust-toolchain.toml', 'Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-nightly-
- name: Install required cargo
run: |
cargo install clippy-sarif sarif-fmt --force
cargo install sqlx-cli --version 0.9.0 --locked --no-default-features -F native-tls,postgres --force
- name: Perform database migration
run: cargo sqlx migrate run
- name: Run rust-clippy
run: cargo clippy
--all-features
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
continue-on-error: true
env:
CARGO_TERM_VERBOSE: false
- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066 with:
sarif_file: rust-clippy-results.sarif
wait-for-processing: true
test:
if: (github.event_name != 'pull_request' && ! github.event.pull_request.head.repo.fork) || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork)
runs-on: ubuntu-latest
container:
image: ghcr.io/terrapkg/builder:f44
options: --cap-add=SYS_ADMIN --privileged
env:
DATABASE_URL: postgres://postgres:postgres@postgres:5432/subatomic
ZSTD_SYS_USE_PKG_CONFIG: "1"
SUBATOMIC_S3_TESTS: "1"
AWS_ENDPOINT: http://rustfs:9000
AWS_BUCKET_NAME: kuchiyose-test
AWS_ACCESS_KEY_ID: subatomic-ci
AWS_SECRET_ACCESS_KEY: subatomic-ci-secret
AWS_ALLOW_HTTP: "true"
AWS_REGION: us-east-1
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: subatomic
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
rustfs:
image: rustfs/rustfs:1.0.3
env:
RUSTFS_ACCESS_KEY: subatomic-ci
RUSTFS_SECRET_KEY: subatomic-ci-secret
options: >-
--health-cmd "curl -f http://localhost:9000/health || exit 1"
--health-interval 10s
--health-timeout 5s
--health-retries 10
steps:
- name: Install dependencies
run: dnf in -y clang gcc 'pkgconfig(libzstd)' 'pkgconfig(openssl)' appstream
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
submodules: recursive
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 with:
toolchain: nightly
- name: Cache Cargo
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 with:
path: |
~/.cargo/
target
key: ${{ runner.os }}-cargo-nightly-${{ hashFiles('rust-toolchain.toml', 'Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-nightly-
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@ea647c55f74bb153499600c054578c0d83fa19d5
- name: Fetch
run: cargo fetch --locked
- name: Install required cargo
run: cargo install sqlx-cli --version 0.9.0 --locked --no-default-features --features native-tls,postgres --force
- name: Perform database migration
run: cargo sqlx migrate run
- name: Create test bucket on RustFS
run: |
# dl.min.io no longer serves archived MinIO community dm (HTTP 410), so use the
# first-party RustFS client, pinned, from GitHub releases. The tarball extracts rc.
curl -sSLo /tmp/rc.tar.gz https://github.com/rustfs/cli/releases/download/v0.1.36/rustfs-cli-linux-amd64-v0.1.36.tar.gz
echo "4a8128911ccad4e7b481f26635a4cfd1ec064412210526e57ad2c748d356f3b7 /tmp/rc.tar.gz" | sha256sum -c -
tar -xzf /tmp/rc.tar.gz -C /tmp
/tmp/rc alias set rustfs "$AWS_ENDPOINT" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY"
# Idempotent: if create fails, the bucket must already exist (reruns/stale services).
/tmp/rc bucket create "rustfs/$AWS_BUCKET_NAME" || /tmp/rc bucket list rustfs | grep -qF "/$AWS_BUCKET_NAME"
- name: Run tests
run: cargo llvm-cov --workspace