pg_exporter 0.6.2

PostgreSQL metric exporter for Prometheus
Documentation
---
name: Test

'on':
  workflow_call:
  pull_request:
    branches:
      - '*'

jobs:
  format:
    name: Format
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - name: Cache Rust toolchain
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
          key: ${{ runner.os }}-cargo-fmt-${{ hashFiles('rust-toolchain.toml') }}
          restore-keys: |
            ${{ runner.os }}-cargo-fmt-

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt

      - name: Format
        run: cargo fmt --all -- --check

  lint:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - name: Cache Rust dependencies
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-clippy-
            ${{ runner.os }}-cargo-

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy

      - name: Clippy
        run: cargo clippy --all-targets --all-features -- -D warnings

  check:
    name: Check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - name: Cache Rust dependencies
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-check-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-check-
            ${{ runner.os }}-cargo-

      - uses: dtolnay/rust-toolchain@stable

      - name: Check
        run: cargo check

  test:
    name: Test (PostgreSQL ${{ matrix.postgres }})
    runs-on: ubuntu-latest
    needs:
      - format
      - lint
      - check

    strategy:
      fail-fast: false
      matrix:
        postgres:
          - 16
          - 17
          - 18

    services:
      postgres:
        image: postgres:${{ matrix.postgres }}
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: postgres
          POSTGRES_HOST_AUTH_METHOD: trust
        options: >-
          --health-cmd "pg_isready -U postgres"
          --health-interval 5s
          --health-timeout 5s
          --health-retries 10
          --health-start-period 10s
        ports:
          - 5432:5432

    steps:
      - uses: actions/checkout@v5

      - name: Cache Rust dependencies
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-test-pg${{ matrix.postgres }}-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-test-pg${{ matrix.postgres }}-
            ${{ runner.os }}-cargo-test-
            ${{ runner.os }}-cargo-

      - uses: dtolnay/rust-toolchain@stable

      - name: Wait for PostgreSQL
        run: |
          timeout 30 bash -c 'until pg_isready -h localhost -p 5432 -U postgres; do sleep 1; done'
          echo "PostgreSQL ${{ matrix.postgres }} is ready!"

      - name: Show PostgreSQL version
        run: |
          psql -h localhost -U postgres -d postgres -c "SELECT version();"

      - name: Run tests
        env:
          PG_EXPORTER_DSN: postgresql://postgres:postgres@localhost:5432/postgres
        run: cargo test