subatomic-server 1.1.4

Modern package delivery system for RPMs
# FyraLabs/actions/main/.github/workflows/rust.yml but nightly

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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          submodules: recursive

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 # v1.94.1
        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)'

      - name: Checkout code
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          submodules: recursive

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 # v1.94.1
        with:
          toolchain: nightly
          components: clippy

      - name: Cache Cargo
        uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            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@99df26d4f13ea111d4ec1a7dddef6063f76b97e9 # v4.37.0
        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"
    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)'

      - name: Checkout code
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          submodules: recursive

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 # v1.94.1
        with:
          toolchain: nightly

      - name: Cache Cargo
        uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            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 # cargo-llvm-cov

      - 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: Run tests
        run: cargo llvm-cov