name: Integration Test

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

env:
  CARGO_TERM_COLOR: always

jobs:
  integration:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - uses: dtolnay/rust-toolchain@1.88.0
    - run: mkdir .cargo && cp .cargo-config.toml .cargo/config.toml
    - name: Build with default features
      run: cargo build
    - name: Run unit tests with default features
      run: cargo test --lib
    - name: Build with all top level features
      run: cargo build --features=rc,schemars,multipart,resource-builder
    - name: Run unit tests with all top level features
      run: cargo test --features=rc,schemars,multipart,resource-builder
    - name: Run integration tests
      run: |
        export KEYCLOAK_VERSION=`cargo metadata --no-deps --format-version 1 | jq '.packages[0].version | split(".") | map(tonumber) | .[:-1] + [.[2] / 100] | map(floor) | join(".")' | tr -d '"'`
        docker run -p 8080:8080 --name keycloak -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=password -e KC_FEATURES=admin-api quay.io/keycloak/keycloak:${KEYCLOAK_VERSION} start-dev &
        sleep 40
        cargo run --example=adduser
        cargo run --example=resource_adduser --features=resource-builder
        cargo run --example=importconfig --features=multipart
        cargo run --example=adduser --features=rc,schemars,multipart,resource-builder
        cargo run --example=resource_adduser --features=rc,schemars,multipart,resource-builder
