diff --git a/.config/starte2e.sh b/.config/starte2e.sh index 7a9dae2..00edf38 100755 --- a/.config/starte2e.sh +++ b/.config/starte2e.sh @@ -5,20 +5,41 @@ set -eu # CI does not add /usr/bin to $PATH for some reason, which means we # lack docker export PATH="${PATH}:/usr/bin" +# Assume the default profile on older nextest versions +NEXTEST_PROFILE="${NEXTEST_PROFILE:-default}" + +# If we're running in CI, we are in a docker container, so containers +# launched by us do not bind-mount into local directories. Instead, we +# copy the test environment to the host, so that we can bind-mount +# from there. + +TEST_ENV="$(realpath "$(dirname "$0")/../tests/environment")" +export ENV_PATH="$TEST_ENV" + +if [ "$NEXTEST_PROFILE" = "ci" ]; then + cp -r tests/environment "$RUNNER_TEMP/test-env" + TEST_ENV="$RUNNER_TEMP/test-env" + ENV_PATH="/home/runner/work/_temp/test-env" + export ENV_PATH +fi # Make sure the containers can write some files that need to be shared -touch tests/environment/zitadel/service-user.json -chmod a+rw tests/environment/zitadel/service-user.json +touch "$TEST_ENV/zitadel/service-user.json" +chmod a+rw "$TEST_ENV/zitadel/service-user.json" -# We only take down ldap if the cert are too old and need regeneration +# We only take down ldap if the certs are too old and need regeneration ldap_down="" -file_creation=$(date -r ./tests/environment/certs/ca.crt +%s || echo 0) -if [ $(( $(date +%s) - $file_creation )) -gt 2160000 ]; # 25 days old? -then -ldap_down="-v ldap" +file_creation=$(date -r "$TEST_ENV/certs/ca.crt" +%s || echo 0) +if [ $(($(date +%s) - file_creation)) -gt $((25 * 24 * 60 * 60)) ]; then + ldap_down="-v ldap" fi # Shut down any still running test-setup first -docker compose --project-directory ./tests/environment down -v test-setup $ldap_down || true -docker compose --project-directory ./tests/environment up --wait \ - || (docker compose --project-directory ./tests/environment logs test-setup; exit 1) +docker compose --project-directory "$TEST_ENV" down -v test-setup "$ldap_down" || true +docker compose --project-directory "$TEST_ENV" up --wait || ( + docker compose --project-directory "$TEST_ENV" logs test-setup + exit 1 +) + +echo "TEST_ENV=$TEST_ENV" >> "$NEXTEST_ENV" +cat "$NEXTEST_ENV" diff --git a/.github/workflows/rust-workflow.yml b/.github/workflows/rust-workflow.yml index 4594c28..a9a5a69 100644 --- a/.github/workflows/rust-workflow.yml +++ b/.github/workflows/rust-workflow.yml @@ -8,9 +8,6 @@ on: pull_request: branches: [ "*" ] -env: - CARGO_TERM_COLOR: always - # Make sure there is no pipeline running uselessly. concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -18,91 +15,6 @@ concurrency: # Defined CI jobs. jobs: - simple-checks: - container: docker-oss.nexus.famedly.de/rust-container:nightly - runs-on: ubuntu-latest - steps: - - name: Checkout current repository - uses: actions/checkout@v4 - - - uses: famedly/backend-build-workflows/.github/actions/rust-prepare@main - with: - gitlab_ssh: ${{ secrets.CI_SSH_PRIVATE_KEY}} - gitlab_user: ${{ secrets.GITLAB_USER }} - gitlab_pass: ${{ secrets.GITLAB_PASS }} - - - name: Caching - uses: Swatinem/rust-cache@68b3cb7503c78e67dae8373749990a220eb65352 - with: - cache-on-failure: true - cache-all-crates: true - - - name: Rustfmt - shell: bash - run: cargo +${NIGHTLY_VERSION} fmt -- --check - - - name: Clippy - shell: bash - run: cargo +${NIGHTLY_VERSION} clippy --workspace --all-targets -- -D warnings - - - name: Doc-test - shell: bash - run: cargo +${NIGHTLY_VERSION} test --doc --workspace --verbose - - - name: Udeps - shell: bash - run: cargo +${NIGHTLY_VERSION} udeps - - - name: Typos - shell: bash - run: typos --exclude '*.key' --exclude '*.crt' --exclude '*.csr' --exclude '*.srl' - tests: - runs-on: ubuntu-latest - steps: - - name: Checkout current repository - uses: actions/checkout@v4 - - - uses: famedly/backend-build-workflows/.github/actions/rust-prepare@main - with: - gitlab_ssh: ${{ secrets.CI_SSH_PRIVATE_KEY}} - gitlab_user: ${{ secrets.GITLAB_USER }} - gitlab_pass: ${{ secrets.GITLAB_PASS }} - - - name: Add llvm-tools rust component - run: rustup component add llvm-tools-preview --toolchain stable-x86_64-unknown-linux-gnu - - - name: Caching - uses: Swatinem/rust-cache@68b3cb7503c78e67dae8373749990a220eb65352 - with: - cache-on-failure: true - cache-all-crates: true - - - name: Install additional cargo tooling - shell: bash - run: cargo install cargo-nextest cargo-llvm-cov --locked - - - name: Test - timeout-minutes: 20 - shell: bash - run: | - docker compose --project-directory ./tests/environment down -v - cargo llvm-cov nextest --profile ci --workspace --lcov --output-path lcov.info - - - name: Get docker logs on failure - shell: bash - if: failure() - run: | - docker compose --project-directory ./tests/environment logs - - - name: Codecov - Upload coverage - uses: codecov/codecov-action@v4 - with: - token: ${{secrets.CODECOV_TOKEN}} - files: lcov.info - - - name: Codecov - Upload test results - uses: codecov/test-results-action@v1 - with: - token: ${{secrets.CODECOV_TOKEN}} - + uses: famedly/backend-build-workflows/.github/workflows/rust-workflow.yml@ccb800fdb716ff3b8459f19bb9ceb56544d0798e + secrets: inherit diff --git a/tests/e2e.rs b/tests/e2e.rs index ee648de..060e813 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -2,7 +2,7 @@ #![cfg(test)] /// E2E integration tests -use std::{collections::HashSet, path::Path, pin::pin, time::Duration}; +use std::{collections::HashSet, path::PathBuf, pin::pin, time::Duration}; use base64::{engine::general_purpose, Engine as _}; use famedly_sync::{ @@ -2060,13 +2060,15 @@ async fn cleanup_test_users(config: &Config) { /// Get the module's test environment config async fn ldap_config() -> &'static Config { + let config_dir = std::env::var("TEST_ENV").map(PathBuf::from).expect("Cannot find config dir"); + CONFIG_WITH_LDAP .get_or_init(|| async { - let mut config = Config::new(Path::new("tests/environment/config.yaml")) + let mut config = Config::new(&config_dir.join("config.yaml")) .expect("failed to parse test env file"); config.sources.ldap = serde_yaml::from_slice( - &std::fs::read(Path::new("tests/environment/ldap-config.template.yaml")) + &std::fs::read(config_dir.join("ldap-config.template.yaml")) .expect("failed to read ldap config file"), ) .expect("failed to parse ldap config"); @@ -2078,13 +2080,15 @@ async fn ldap_config() -> &'static Config { /// Get the module's test environment config async fn ukt_config() -> &'static Config { + let config_dir = std::env::var("TEST_ENV").map(PathBuf::from).expect("Cannot find config dir"); + CONFIG_WITH_UKT .get_or_init(|| async { - let mut config = Config::new(Path::new("tests/environment/config.yaml")) + let mut config = Config::new(&config_dir.join("config.yaml")) .expect("failed to parse test env file"); config.sources.ukt = serde_yaml::from_slice( - &std::fs::read(Path::new("tests/environment/ukt-config.template.yaml")) + &std::fs::read(config_dir.join("ukt-config.template.yaml")) .expect("failed to read ukt config file"), ) .expect("failed to parse ukt config"); @@ -2096,13 +2100,15 @@ async fn ukt_config() -> &'static Config { /// Get the module's test environment config async fn csv_config() -> &'static Config { + let config_dir = std::env::var("TEST_ENV").map(PathBuf::from).expect("Cannot find config dir"); + CONFIG_WITH_CSV .get_or_init(|| async { - let mut config = Config::new(Path::new("tests/environment/config.yaml")) + let mut config = Config::new(&config_dir.join("config.yaml")) .expect("failed to parse test env file"); config.sources.csv = serde_yaml::from_slice( - &std::fs::read(Path::new("tests/environment/csv-config.template.yaml")) + &std::fs::read(config_dir.join("csv-config.template.yaml")) .expect("failed to read csv config file"), ) .expect("failed to parse csv config"); diff --git a/tests/environment/docker-compose.yaml b/tests/environment/docker-compose.yaml index 179d42a..2da8107 100644 --- a/tests/environment/docker-compose.yaml +++ b/tests/environment/docker-compose.yaml @@ -3,7 +3,7 @@ services: image: alpine/openssl:3.3.2 volumes: - type: bind - source: ./certs + source: ${ENV_PATH}/certs target: /certs entrypoint: /certs/generate-certs.sh @@ -20,7 +20,7 @@ services: - LDAP_TLS_VERIFY_CLIENTS=try volumes: - type: bind - source: ./certs + source: ${ENV_PATH}/certs target: /certs read_only: true depends_on: @@ -34,10 +34,10 @@ services: entrypoint: /environment/test-setup.sh volumes: - type: bind - source: ./ + source: ${ENV_PATH}/ target: /environment - type: bind - source: ./config.template.yaml + source: ${ENV_PATH}/config.template.yaml target: /config.template.yaml read_only: true healthcheck: @@ -59,7 +59,7 @@ services: - 8080:8080 volumes: - type: bind - source: ./zitadel/ + source: ${ENV_PATH}/zitadel/ target: /zitadel-config/ depends_on: db: