|
| 1 | +name: Run Chromatic Tests |
| 2 | +concurrency: |
| 3 | + group: Run-Chromatic-Tests-${{ github.workflow }}-${{ github.head_ref || github.event.workflow_run.head_branch || github.run_id }} |
| 4 | + cancel-in-progress: true |
| 5 | + |
| 6 | +on: push |
| 7 | + |
| 8 | +env: |
| 9 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 10 | + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} |
| 11 | + |
| 12 | +jobs: |
| 13 | + playwright-tests: |
| 14 | + name: Playwright Tests |
| 15 | + |
| 16 | + # See https://runs-on.com/runners/linux/ |
| 17 | + runs-on: [runs-on,runner=8cpu-linux-x64,ram=16,"run-id=${{ github.run_id }}"] |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Set up Python |
| 25 | + uses: actions/setup-python@v5 |
| 26 | + with: |
| 27 | + python-version: '3.11' |
| 28 | + cache: 'pip' |
| 29 | + cache-dependency-path: | |
| 30 | + backend/requirements/default.txt |
| 31 | + backend/requirements/dev.txt |
| 32 | + backend/requirements/model_server.txt |
| 33 | + - run: | |
| 34 | + python -m pip install --upgrade pip |
| 35 | + pip install --retries 5 --timeout 30 -r backend/requirements/default.txt |
| 36 | + pip install --retries 5 --timeout 30 -r backend/requirements/dev.txt |
| 37 | + pip install --retries 5 --timeout 30 -r backend/requirements/model_server.txt |
| 38 | + |
| 39 | + - name: Setup node |
| 40 | + uses: actions/setup-node@v4 |
| 41 | + with: |
| 42 | + node-version: 22 |
| 43 | + |
| 44 | + - name: Install node dependencies |
| 45 | + working-directory: ./web |
| 46 | + run: npm ci |
| 47 | + |
| 48 | + - name: Install playwright browsers |
| 49 | + working-directory: ./web |
| 50 | + run: npx playwright install --with-deps |
| 51 | + |
| 52 | + - name: Set up Docker Buildx |
| 53 | + uses: docker/setup-buildx-action@v3 |
| 54 | + |
| 55 | + - name: Login to Docker Hub |
| 56 | + uses: docker/login-action@v3 |
| 57 | + with: |
| 58 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 59 | + password: ${{ secrets.DOCKER_TOKEN }} |
| 60 | + |
| 61 | + # tag every docker image with "test" so that we can spin up the correct set |
| 62 | + # of images during testing |
| 63 | + |
| 64 | + # we use the runs-on cache for docker builds |
| 65 | + # in conjunction with runs-on runners, it has better speed and unlimited caching |
| 66 | + # https://runs-on.com/caching/s3-cache-for-github-actions/ |
| 67 | + # https://runs-on.com/caching/docker/ |
| 68 | + # https://github.com/moby/buildkit#s3-cache-experimental |
| 69 | + |
| 70 | + # images are built and run locally for testing purposes. Not pushed. |
| 71 | + |
| 72 | + - name: Build Web Docker image |
| 73 | + uses: ./.github/actions/custom-build-and-push |
| 74 | + with: |
| 75 | + context: ./web |
| 76 | + file: ./web/Dockerfile |
| 77 | + platforms: linux/amd64 |
| 78 | + tags: danswer/danswer-web-server:test |
| 79 | + push: false |
| 80 | + load: true |
| 81 | + cache-from: type=s3,prefix=cache/${{ github.repository }}/integration-tests/web-server/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }} |
| 82 | + cache-to: type=s3,prefix=cache/${{ github.repository }}/integration-tests/web-server/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }},mode=max |
| 83 | + |
| 84 | + - name: Build Backend Docker image |
| 85 | + uses: ./.github/actions/custom-build-and-push |
| 86 | + with: |
| 87 | + context: ./backend |
| 88 | + file: ./backend/Dockerfile |
| 89 | + platforms: linux/amd64 |
| 90 | + tags: danswer/danswer-backend:test |
| 91 | + push: false |
| 92 | + load: true |
| 93 | + cache-from: type=s3,prefix=cache/${{ github.repository }}/integration-tests/backend/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }} |
| 94 | + cache-to: type=s3,prefix=cache/${{ github.repository }}/integration-tests/backend/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }},mode=max |
| 95 | + |
| 96 | + - name: Build Model Server Docker image |
| 97 | + uses: ./.github/actions/custom-build-and-push |
| 98 | + with: |
| 99 | + context: ./backend |
| 100 | + file: ./backend/Dockerfile.model_server |
| 101 | + platforms: linux/amd64 |
| 102 | + tags: danswer/danswer-model-server:test |
| 103 | + push: false |
| 104 | + load: true |
| 105 | + cache-from: type=s3,prefix=cache/${{ github.repository }}/integration-tests/model-server/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }} |
| 106 | + cache-to: type=s3,prefix=cache/${{ github.repository }}/integration-tests/model-server/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }},mode=max |
| 107 | + |
| 108 | + - name: Start Docker containers |
| 109 | + run: | |
| 110 | + cd deployment/docker_compose |
| 111 | + ENABLE_PAID_ENTERPRISE_EDITION_FEATURES=true \ |
| 112 | + AUTH_TYPE=basic \ |
| 113 | + REQUIRE_EMAIL_VERIFICATION=false \ |
| 114 | + DISABLE_TELEMETRY=true \ |
| 115 | + IMAGE_TAG=test \ |
| 116 | + docker compose -f docker-compose.dev.yml -p danswer-stack up -d |
| 117 | + id: start_docker |
| 118 | + |
| 119 | + - name: Wait for service to be ready |
| 120 | + run: | |
| 121 | + echo "Starting wait-for-service script..." |
| 122 | + |
| 123 | + docker logs -f danswer-stack-api_server-1 & |
| 124 | +
|
| 125 | + start_time=$(date +%s) |
| 126 | + timeout=300 # 5 minutes in seconds |
| 127 | + |
| 128 | + while true; do |
| 129 | + current_time=$(date +%s) |
| 130 | + elapsed_time=$((current_time - start_time)) |
| 131 | + |
| 132 | + if [ $elapsed_time -ge $timeout ]; then |
| 133 | + echo "Timeout reached. Service did not become ready in 5 minutes." |
| 134 | + exit 1 |
| 135 | + fi |
| 136 | + |
| 137 | + # Use curl with error handling to ignore specific exit code 56 |
| 138 | + response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/health || echo "curl_error") |
| 139 | + |
| 140 | + if [ "$response" = "200" ]; then |
| 141 | + echo "Service is ready!" |
| 142 | + break |
| 143 | + elif [ "$response" = "curl_error" ]; then |
| 144 | + echo "Curl encountered an error, possibly exit code 56. Continuing to retry..." |
| 145 | + else |
| 146 | + echo "Service not ready yet (HTTP status $response). Retrying in 5 seconds..." |
| 147 | + fi |
| 148 | + |
| 149 | + sleep 5 |
| 150 | + done |
| 151 | + echo "Finished waiting for service." |
| 152 | +
|
| 153 | + - name: Run pytest playwright test init |
| 154 | + working-directory: ./backend |
| 155 | + env: |
| 156 | + PYTEST_IGNORE_SKIP: true |
| 157 | + run: pytest -s tests/integration/tests/playwright/test_playwright.py |
| 158 | + |
| 159 | + - name: Run Playwright tests |
| 160 | + working-directory: ./web |
| 161 | + run: npx playwright test |
| 162 | + |
| 163 | + - uses: actions/upload-artifact@v4 |
| 164 | + if: always() |
| 165 | + with: |
| 166 | + # Chromatic automatically defaults to the test-results directory. |
| 167 | + # Replace with the path to your custom directory and adjust the CHROMATIC_ARCHIVE_LOCATION environment variable accordingly. |
| 168 | + name: test-results |
| 169 | + path: ./web/test-results |
| 170 | + retention-days: 30 |
| 171 | + |
| 172 | + # save before stopping the containers so the logs can be captured |
| 173 | + - name: Save Docker logs |
| 174 | + if: success() || failure() |
| 175 | + run: | |
| 176 | + cd deployment/docker_compose |
| 177 | + docker compose -f docker-compose.dev.yml -p danswer-stack logs > docker-compose.log |
| 178 | + mv docker-compose.log ${{ github.workspace }}/docker-compose.log |
| 179 | + |
| 180 | + - name: Upload logs |
| 181 | + if: success() || failure() |
| 182 | + uses: actions/upload-artifact@v4 |
| 183 | + with: |
| 184 | + name: docker-logs |
| 185 | + path: ${{ github.workspace }}/docker-compose.log |
| 186 | + |
| 187 | + - name: Stop Docker containers |
| 188 | + run: | |
| 189 | + cd deployment/docker_compose |
| 190 | + docker compose -f docker-compose.dev.yml -p danswer-stack down -v |
| 191 | +
|
| 192 | + chromatic-tests: |
| 193 | + name: Chromatic Tests |
| 194 | + |
| 195 | + needs: playwright-tests |
| 196 | + runs-on: [runs-on,runner=8cpu-linux-x64,ram=16,"run-id=${{ github.run_id }}"] |
| 197 | + steps: |
| 198 | + - name: Checkout code |
| 199 | + uses: actions/checkout@v4 |
| 200 | + with: |
| 201 | + fetch-depth: 0 |
| 202 | + |
| 203 | + - name: Setup node |
| 204 | + uses: actions/setup-node@v4 |
| 205 | + with: |
| 206 | + node-version: 22 |
| 207 | + |
| 208 | + - name: Install node dependencies |
| 209 | + working-directory: ./web |
| 210 | + run: npm ci |
| 211 | + |
| 212 | + - name: Download Playwright test results |
| 213 | + uses: actions/download-artifact@v4 |
| 214 | + with: |
| 215 | + name: test-results |
| 216 | + path: ./web/test-results |
| 217 | + |
| 218 | + - name: Run Chromatic |
| 219 | + uses: chromaui/action@latest |
| 220 | + with: |
| 221 | + playwright: true |
| 222 | + projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} |
| 223 | + workingDir: ./web |
| 224 | + env: |
| 225 | + CHROMATIC_ARCHIVE_LOCATION: ./test-results |
0 commit comments