From d8625b9f39bfc4f1108423902877c53dc8619058 Mon Sep 17 00:00:00 2001 From: Edouard Vanbelle Date: Mon, 11 May 2026 11:24:11 +0200 Subject: [PATCH] ci: merge end-to-end workflow into ci, permits to reduce amount of built --- .github/workflows/ci.yml | 389 +++++++++++++++---------- .github/workflows/end-to-end-tests.yml | 110 ------- tests/api/run.sh | 14 +- tests/e2e/playwright.config.ts | 4 +- 4 files changed, 250 insertions(+), 267 deletions(-) delete mode 100644 .github/workflows/end-to-end-tests.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29f9ee39..f9da694e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,153 +1,236 @@ -name: CI - -# IMPORTANT: using Swatinem/rust-cache@v2 : reuse same cache as playwright.yml (minimize non necessary new compilation) - -on: - push: - branches: - - main - - dev - - "feat/**" - - "fix/**" - pull_request: - branches: [ "main", "dev" ] - -env: - CARGO_TERM_COLOR: always - RUSTFLAGS: "-Dwarnings" - DATABASE_URL: "postgres://postgres:postgres@localhost/oxicloud_test" - -jobs: - - # Detect which parts of the codebase changed - changes: - runs-on: ubuntu-latest - outputs: - frontend: ${{ steps.filter.outputs.frontend }} - backend: ${{ steps.filter.outputs.backend }} - steps: - - uses: actions/checkout@v4 - - uses: dorny/paths-filter@v3 - id: filter - with: - filters: | - frontend: - - 'static/**' - - 'biome.json' - - '.grit' - - '.stylelintrc.json' - - 'jsconfig.json' - backend: - - 'src/**' - - 'Cargo.toml' - - 'Cargo.lock' - - frontend-linter: - name: Frontend — CSS and JS checks (format, lint, rules, etc) - needs: changes - if: needs.changes.outputs.frontend == 'true' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Install Biome - uses: biomejs/setup-biome@v2 - - - name: Run Biome check - run: biome ci static/ - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: 25 - - # because we are not using package.json - - name: Install Stylelint and plugins - run: | - npm install --global \ - stylelint@17 \ - postcss@8 \ - stylelint-value-no-unknown-custom-properties@6 - - - name: Run Stylelint - run: npx stylelint "static/css/**/*.{css,scss}" - - rust-fmt: - name: Rustfmt - needs: changes - if: needs.changes.outputs.backend == 'true' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt - - run: cargo fmt --all --check - - rust-clippy: - name: Clippy - needs: changes - if: needs.changes.outputs.backend == 'true' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - uses: dtolnay/rust-toolchain@stable - with: - components: clippy - - uses: Swatinem/rust-cache@v2 - - run: cargo clippy --all-targets --all-features -- -D warnings - - rust-test: - name: Tests - needs: changes - if: needs.changes.outputs.backend == 'true' - runs-on: ubuntu-latest - services: - postgres: - image: postgres:16-alpine - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: oxicloud_test - ports: - - 5432:5432 - options: >- - --health-cmd "pg_isready -U postgres" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - steps: - - uses: actions/checkout@v6 - - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - - - name: Initialize test database - run: psql -h localhost -U postgres -d oxicloud_test -f migrations/20260307000000_initial_schema.sql - env: - PGPASSWORD: postgres - - - name: Run tests - run: cargo test --all-features --workspace - env: - DATABASE_URL: "postgres://postgres:postgres@localhost/oxicloud_test" - - rust-audit: - name: Security Audit - needs: changes - if: needs.changes.outputs.backend == 'true' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - uses: rustsec/audit-check@v2.0.0 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - build: - name: Build Check - runs-on: ubuntu-latest - needs: [frontend-linter, rust-fmt, rust-clippy, rust-test] - steps: - - uses: actions/checkout@v6 - - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - - run: cargo build --release +name: CI + +on: + push: + branches: + - main + - dev + - "feat/**" + - "fix/**" + pull_request: + branches: [ "main", "dev" ] + +env: + CARGO_TERM_COLOR: always + RUSTFLAGS: "-Dwarnings" + DATABASE_URL: "postgres://postgres:postgres@localhost/oxicloud_test" + +jobs: + + # Detect which parts of the codebase changed + changes: + runs-on: ubuntu-latest + outputs: + frontend: ${{ steps.filter.outputs.frontend }} + backend: ${{ steps.filter.outputs.backend }} + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + frontend: + - 'static/**' + - 'biome.json' + - '.grit' + - '.stylelintrc.json' + - 'jsconfig.json' + backend: + - 'src/**' + - 'Cargo.toml' + - 'Cargo.lock' + + frontend-check: + name: Frontend — CSS and JS checks (format, lint, rules) + needs: changes + if: needs.changes.outputs.frontend == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Biome + uses: biomejs/setup-biome@v2 + + - name: Run Biome check + run: biome ci static/ + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 25 + + # because we are not using package.json + - name: Install Stylelint and plugins + run: | + npm install --global \ + stylelint@17 \ + postcss@8 \ + stylelint-value-no-unknown-custom-properties@6 + + - name: Run Stylelint + run: npx stylelint "static/css/**/*.{css,scss}" + + rust-fmt: + name: Rustfmt + needs: changes + if: needs.changes.outputs.backend == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - run: cargo fmt --all --check + + rust-clippy: + name: Clippy + needs: changes + if: needs.changes.outputs.backend == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy + - uses: Swatinem/rust-cache@v2 + - run: cargo clippy --all-targets --all-features -- -D warnings + + rust-test: + name: Server Unit and Functionnal Tests + needs: changes + if: needs.changes.outputs.backend == 'true' + runs-on: ubuntu-latest + services: + postgres: + image: postgres:16-alpine + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: oxicloud_test + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v6 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + + - name: Initialize test database + run: psql -h localhost -U postgres -d oxicloud_test -f migrations/20260307000000_initial_schema.sql + env: + PGPASSWORD: postgres + + - name: Run tests + run: cargo test --all-features --workspace + env: + DATABASE_URL: "postgres://postgres:postgres@localhost/oxicloud_test" + + rust-audit: + name: Security Audit + needs: changes + if: needs.changes.outputs.backend == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: rustsec/audit-check@v2.0.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + build: + name: Build + runs-on: ubuntu-latest + needs: [rust-fmt, rust-clippy, rust-test] + steps: + - uses: actions/checkout@v6 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - run: cargo build --release + - uses: actions/upload-artifact@v4 + with: + name: oxicloud-release + path: target/release/oxicloud + retention-days: 1 + + api-test: + name: API tests (via Hurl) + needs: build + # if: github.event_name == 'pull_request' + timeout-minutes: 30 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: oxicloud-release + path: target/release/ + + - run: chmod +x target/release/oxicloud + + - name: Install Hurl + env: + HURL_MAJOR: "8" + run: | + HURL_VERSION=$(curl -fsSL -H "Authorization: Bearer ${{ github.token }}" \ + https://api.github.com/repos/Orange-OpenSource/hurl/releases \ + | jq -r "map(select(.tag_name | startswith(\"${HURL_MAJOR}.\"))) | first | .tag_name") + curl -fLO "https://github.com/Orange-OpenSource/hurl/releases/download/${HURL_VERSION}/hurl_${HURL_VERSION}_amd64.deb" + sudo apt-get install -y "./hurl_${HURL_VERSION}_amd64.deb" + + - name: Run Hurl API tests + run: bash tests/api/run.sh + env: + BUILD_TARGET: release + + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: hurl-report + path: tests/api/storage/ + retention-days: 7 + + front-test: + name: Frontend end-to-end tests (via Playwright) + # ensure that api tests are ok before + needs: api-test + # if: github.event_name == 'pull_request' + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: oxicloud-release + path: target/release/ + + - run: chmod +x target/release/oxicloud + + - uses: actions/setup-node@v4 + with: + node-version: lts/* + + - name: Install Node dependencies + working-directory: tests/e2e + run: npm ci + + - name: Install Playwright browsers + working-directory: tests/e2e + run: npx playwright install --with-deps + + - name: Run Playwright tests (spawns DB via pretest hook) + working-directory: tests/e2e + run: npm test + env: + BUILD_TARGET: release + + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: playwright-report + path: tests/e2e/playwright-report/ + retention-days: 30 diff --git a/.github/workflows/end-to-end-tests.yml b/.github/workflows/end-to-end-tests.yml deleted file mode 100644 index 7b9aa86f..00000000 --- a/.github/workflows/end-to-end-tests.yml +++ /dev/null @@ -1,110 +0,0 @@ -name: Playwright Test (end-to-end) - -# IMPORTANT: using Swatinem/rust-cache@v2 : reuse same cache as ci.yml (minimize non necessary new compilation) - -on: - push: - branches: [ main, dev ] - pull_request: - branches: [ main, dev ] - -#concurrency: -# group: rust-build-${{ github.ref }} -# cancel-in-progress: false - -jobs: - api-test: - name: Hurl API tests - timeout-minutes: 30 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable - - - name: Cache compiled binary - id: binary-cache - uses: actions/cache@v4 - with: - path: ${{ github.workspace }}/target/debug/oxicloud - key: ${{ runner.os }}-oxicloud-binary-${{ hashFiles('src/**', 'Cargo.toml', 'Cargo.lock') }} - - - name: Cache Rust dependencies - if: steps.binary-cache.outputs.cache-hit != 'true' - uses: Swatinem/rust-cache@v2 - - - name: Build server - if: steps.binary-cache.outputs.cache-hit != 'true' - run: cargo build - - - name: Install Hurl - env: - HURL_MAJOR: "8" - run: | - HURL_VERSION=$(curl -fsSL -H "Authorization: Bearer ${{ github.token }}" \ - https://api.github.com/repos/Orange-OpenSource/hurl/releases \ - | jq -r "map(select(.tag_name | startswith(\"${HURL_MAJOR}.\"))) | first | .tag_name") - curl -fLO "https://github.com/Orange-OpenSource/hurl/releases/download/${HURL_VERSION}/hurl_${HURL_VERSION}_amd64.deb" - sudo apt-get install -y "./hurl_${HURL_VERSION}_amd64.deb" - - - name: Run Hurl API tests - run: bash tests/api/run.sh - - - uses: actions/upload-artifact@v4 - if: ${{ !cancelled() }} - with: - name: hurl-report - path: tests/api/storage/ - retention-days: 7 - - front-test: - # starts api-test first - needs: api-test - timeout-minutes: 60 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable - - - name: Cache compiled binary - id: binary-cache - uses: actions/cache@v4 - with: - path: ${{ github.workspace }}/target/debug/oxicloud - key: ${{ runner.os }}-oxicloud-binary-${{ hashFiles('src/**', 'Cargo.toml', 'Cargo.lock') }} - - - name: Cache Rust dependencies - if: steps.binary-cache.outputs.cache-hit != 'true' - uses: Swatinem/rust-cache@v2 - - - name: Build server - if: steps.binary-cache.outputs.cache-hit != 'true' - run: cargo build - - - uses: actions/setup-node@v4 - with: - node-version: lts/* - - - name: Install Node dependencies - working-directory: tests/e2e - run: npm ci - - - name: Install Playwright browsers - working-directory: tests/e2e - run: npx playwright install --with-deps - - - name: Run Playwright tests (spawns DB via pretest hook) - working-directory: tests/e2e - run: npm test - - - uses: actions/upload-artifact@v4 - if: ${{ !cancelled() }} - with: - name: playwright-report - path: tests/e2e/playwright-report/ - retention-days: 30 - - diff --git a/tests/api/run.sh b/tests/api/run.sh index 779c44dd..4a888146 100755 --- a/tests/api/run.sh +++ b/tests/api/run.sh @@ -66,9 +66,17 @@ mkdir -p "$OXICLOUD_STORAGE_PATH" # ── 3. Start OxiCloud server ────────────────────────────────────────────────── -log "Building and starting OxiCloud server on port $SERVER_PORT..." -cd "$REPO_ROOT" -cargo run & +BUILD_TARGET="${BUILD_TARGET:-debug}" +OXICLOUD_BIN="$REPO_ROOT/target/$BUILD_TARGET/oxicloud" + +if [[ -x "$OXICLOUD_BIN" ]]; then + log "Starting pre-built OxiCloud server ($BUILD_TARGET) on port $SERVER_PORT..." + "$OXICLOUD_BIN" & +else + log "Building and starting OxiCloud server on port $SERVER_PORT..." + cd "$REPO_ROOT" + cargo run & +fi SERVER_PID=$! log "Waiting for server at $base_url..." wait_for_http "$base_url/ready" 120 diff --git a/tests/e2e/playwright.config.ts b/tests/e2e/playwright.config.ts index de972f02..5016a6a7 100644 --- a/tests/e2e/playwright.config.ts +++ b/tests/e2e/playwright.config.ts @@ -48,7 +48,9 @@ export default defineConfig({ ], webServer: { - command: process.env.CI ? `${process.env.GITHUB_WORKSPACE}/target/debug/oxicloud` : 'cargo run', + command: process.env.BUILD_TARGET + ? `${process.env.GITHUB_WORKSPACE}/target/${process.env.BUILD_TARGET}/oxicloud` + : 'cargo run', url: 'http://localhost:8087', timeout: 600_000, reuseExistingServer: false,