From 828bd72b9e42386f08e24362b492f481baa8d6f5 Mon Sep 17 00:00:00 2001 From: Kirill Chernakov Date: Tue, 10 Dec 2024 18:39:31 +0400 Subject: [PATCH] minimal workflow with build and up --- .../workflows/test-pr-e2e-build-and-run.yml | 104 +++++++++++ .github/workflows/test-pr-e2e.yml | 175 ------------------ 2 files changed, 104 insertions(+), 175 deletions(-) create mode 100644 .github/workflows/test-pr-e2e-build-and-run.yml delete mode 100644 .github/workflows/test-pr-e2e.yml diff --git a/.github/workflows/test-pr-e2e-build-and-run.yml b/.github/workflows/test-pr-e2e-build-and-run.yml new file mode 100644 index 000000000..88c78f58b --- /dev/null +++ b/.github/workflows/test-pr-e2e-build-and-run.yml @@ -0,0 +1,104 @@ +name: Tests (E2E) + +on: + workflow_dispatch: + pull_request: + paths: + - 'keep/**' + - 'keep-ui/**' + - 'tests/**' + +env: + PYTHON_VERSION: 3.11 + STORAGE_MANAGER_DIRECTORY: /tmp/storage-manager + # MySQL server environment variables + MYSQL_ROOT_PASSWORD: keep + MYSQL_DATABASE: keep + # Postgres environment variables + POSTGRES_USER: keepuser + POSTGRES_PASSWORD: keeppassword + POSTGRES_DB: keepdb + # To test if imports are working properly + EE_ENABLED: true + +jobs: + tests-e2e: + runs-on: ubuntu-latest + strategy: + matrix: + db_type: [mysql, postgres] + steps: + - name: Checkout + uses: actions/checkout@v3 + + - uses: chartboost/ruff-action@v1 + with: + src: "./keep" + + - name: Expose GitHub Runtime + uses: crazy-max/ghaction-github-runtime@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + driver: docker-container + + - name: Build Docker images + uses: docker/bake-action@v5 + with: + workdir: . + files: | + tests/e2e_tests/docker-compose-e2e-mysql.yml + load: true + set: | + *.cache-from=type=gha + *.cache-to=type=gha,mode=max + + - name: Set up Keep environment + run: | + docker compose \ + --project-directory . \ + -f tests/e2e_tests/docker-compose-e2e-mysql.yml up -d + + - name: Wait for services to be ready + run: | + # Add commands to wait for the database to be ready + until docker exec $(docker ps -qf "name=keep-database") mysqladmin ping -h "localhost" --silent; do + echo "Waiting for MySQL to be ready..." + sleep 2 + done + + # wait to keep backend on port 8080 + echo "Waiting for Keep backend to be ready..." + attempt=0 + max_attempts=10 + + until $(curl --output /dev/null --silent --fail http://localhost:8080/healthcheck); do + if [ "$attempt" -ge "$max_attempts" ]; then + echo "Max attempts reached, exiting... Sometimes Keep can't start because of double-headed migrations, use: 'alembic -c keep/alembic.ini history' to investigate, or check artifacts." + exit 1 + fi + echo "Waiting for Keep backend to be ready... (Attempt: $((attempt+1)))" + attempt=$((attempt+1)) + sleep 2 + done + + echo "Keep backend is ready!" + # wait to the backend + echo "Waiting for Keep frontend to be ready..." + attempt=0 + max_attempts=10 + + until $(curl --output /dev/null --silent --fail http://localhost:3000/); do + if [ "$attempt" -ge "$max_attempts" ]; then + echo "Max attempts reached, exiting..." + exit 1 + fi + echo "Waiting for Keep frontend to be ready... (Attempt: $((attempt+1)))" + attempt=$((attempt+1)) + sleep 2 + done + + # create the state directory + # mkdir -p ./state && chown -R root:root ./state && chmod -R 777 ./state + diff --git a/.github/workflows/test-pr-e2e.yml b/.github/workflows/test-pr-e2e.yml deleted file mode 100644 index 32afc094e..000000000 --- a/.github/workflows/test-pr-e2e.yml +++ /dev/null @@ -1,175 +0,0 @@ -name: Tests (E2E) - -on: - workflow_dispatch: - pull_request: - paths: - - 'keep/**' - - 'keep-ui/**' - - 'tests/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref }} - cancel-in-progress: true - -env: - PYTHON_VERSION: 3.11 - STORAGE_MANAGER_DIRECTORY: /tmp/storage-manager - # MySQL server environment variables - MYSQL_ROOT_PASSWORD: keep - MYSQL_DATABASE: keep - # Postgres environment variables - POSTGRES_USER: keepuser - POSTGRES_PASSWORD: keeppassword - POSTGRES_DB: keepdb - # To test if imports are working properly - EE_ENABLED: true - -jobs: - tests-e2e: - runs-on: ubuntu-latest - strategy: - matrix: - db_type: [mysql, postgres] - steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: chartboost/ruff-action@v1 - with: - src: "./keep" - - - name: Set up Python ${{ env.PYTHON_VERSION }} - uses: actions/setup-python@v4 - with: - python-version: ${{ env.PYTHON_VERSION }} - - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - virtualenvs-create: true - virtualenvs-in-project: true - - - name: Cache dependencies - id: cache-deps - uses: actions/cache@v2 - with: - path: .venv - key: pydeps-${{ hashFiles('**/poetry.lock') }} - - - name: Install dependencies using poetry - run: poetry install --no-interaction --no-root --with dev - - - name: Install Playwright dependencies - run: npx playwright install --with-deps - - - name: Install playwright - run: poetry run playwright install - - - name: Expose GitHub Runtime - uses: crazy-max/ghaction-github-runtime@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - with: - driver: docker-container - - - name: Build Docker images - uses: docker/bake-action@v5 - with: - workdir: . - files: | - tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml - load: true - - - name: Set up Keep environment - run: | - DOCKER_BUILDKIT=1 docker compose \ - --project-directory . \ - -f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml up -d - - - name: Wait for database to be ready - run: | - # Add commands to wait for the database to be ready - if [ "${{ matrix.db_type }}" == "mysql" ]; then - until docker exec $(docker ps -qf "name=keep-database") mysqladmin ping -h "localhost" --silent; do - echo "Waiting for MySQL to be ready..." - sleep 2 - done - elif [ "${{ matrix.db_type }}" == "postgres" ]; then - until docker exec $(docker ps -qf "name=keep-database") pg_isready -h localhost -U keepuser; do - echo "Waiting for Postgres to be ready..." - sleep 2 - done - fi - - # wait to keep backend on port 8080 - echo "Waiting for Keep backend to be ready..." - attempt=0 - max_attempts=10 - - until $(curl --output /dev/null --silent --fail http://localhost:8080/healthcheck); do - if [ "$attempt" -ge "$max_attempts" ]; then - echo "Max attempts reached, exiting... Sometimes Keep can't start because of double-headed migrations, use: 'alembic -c keep/alembic.ini history' to investigate, or check artifacts." - exit 1 - fi - echo "Waiting for Keep backend to be ready... (Attempt: $((attempt+1)))" - attempt=$((attempt+1)) - sleep 2 - done - - echo "Keep backend is ready!" - # wait to the backend - echo "Waiting for Keep frontend to be ready..." - attempt=0 - max_attempts=10 - - until $(curl --output /dev/null --silent --fail http://localhost:3000/); do - if [ "$attempt" -ge "$max_attempts" ]; then - echo "Max attempts reached, exiting..." - exit 1 - fi - echo "Waiting for Keep frontend to be ready... (Attempt: $((attempt+1)))" - attempt=$((attempt+1)) - sleep 2 - done - - # create the state directory - # mkdir -p ./state && chown -R root:root ./state && chmod -R 777 ./state - - - name: Run e2e tests and report coverage - run: | - poetry run coverage run --branch -m pytest -s tests/e2e_tests/ - - - name: Convert coverage results to JSON (for CodeCov support) - run: poetry run coverage json --omit="keep/providers/*" - - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 - with: - fail_ci_if_error: false # don't fail if we didn't manage to upload the coverage report - files: coverage.json - verbose: true - - - name: Dump backend logs - if: always() - run: | - docker compose --project-directory . -f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml logs keep-backend > backend_logs-${{ matrix.db_type }}.txt - docker compose --project-directory . -f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml logs keep-frontend > frontend_logs-${{ matrix.db_type }}.txt - continue-on-error: true - - - name: Upload test artifacts on failure - if: always() - uses: actions/upload-artifact@v3 - with: - name: test-artifacts - path: | - playwright_dump_*.html - playwright_dump_*.png - backend_logs-${{ matrix.db_type }}.txt - frontend_logs-${{ matrix.db_type }}.txt - continue-on-error: true - - - name: Tear down environment - run: | - docker compose --project-directory . -f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml down