name: Test on: pull_request: push: branches: - main merge_group: env: TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TEAM: hashintel TURBO_CACHE: remote:rw NEXTEST_PROFILE: ci concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: setup: runs-on: ubuntu-24.04 permissions: contents: read outputs: unit-tests: ${{ steps.packages.outputs.unit-tests }} integration-tests: ${{ steps.packages.outputs.integration-tests }} system-tests: ${{ steps.packages.outputs.system-tests }} publish-rust: ${{ steps.packages.outputs.publish-rust }} steps: - name: Checkout source code uses: actions/checkout@v6.0.2 with: fetch-depth: 2 - name: Install tools uses: $/.github/actions/install-tools with: token: ${{ secrets.GITHUB_TOKEN }} rust: false - name: Determine changed packages id: packages run: | UNIT_TEST_PACKAGES=$(.github/scripts/affected-packages.sh test:unit) INTEGRATION_TEST_PACKAGES=$(.github/scripts/affected-packages.sh test:integration) PUBLISH_PACKAGES=[] while IFS= read -r file; do if [[ -n "$file" ]]; then PACKAGE_NAME=$(yq '.package.name' -p toml -oy "$file") if [[ "$PACKAGE_NAME" == "null" ]]; then continue fi if [[ "$(yq '.package.publish' -p toml -oy "$file")" == "false" ]]; then continue fi if [[ "$(yq '.package.publish.workspace' -p toml -oy "$file")" == "true" ]]; then if [[ "$(yq '.workspace.package.publish' -p toml -oy "Cargo.toml")" == "false" ]]; then continue fi fi OLD_VERSION=$(git show HEAD^:"$file" | yq '.package.version' -p toml) if [[ "$OLD_VERSION" == "null" ]]; then continue fi NEW_VERSION=$(yq '.package.version' -p toml -oy "$file") if [[ "$OLD_VERSION" == "$NEW_VERSION" ]]; then continue fi PUBLISH_PACKAGES=$(echo "$PUBLISH_PACKAGES" | jq -c --arg package "$PACKAGE_NAME" '. += [$package]') fi done <<< "$(find . -name 'Cargo.toml' -type f | sed 's|\./||')" echo "unit-tests=$UNIT_TEST_PACKAGES" | tee -a "$GITHUB_OUTPUT" echo "integration-tests=$INTEGRATION_TEST_PACKAGES" | tee -a "$GITHUB_OUTPUT" echo "publish-rust=$PUBLISH_PACKAGES" | tee -a "$GITHUB_OUTPUT" sccache-credentials: runs-on: ubuntu-24.04 permissions: contents: read id-token: write outputs: encrypted-credentials: ${{ steps.mint.outputs.encrypted_credentials }} steps: - name: Checkout source code uses: actions/checkout@v6.0.2 - name: Mint sccache credentials id: mint uses: $/.github/actions/mint-sccache-credentials with: vault_address: ${{ vars.VAULT_STAGE_ADDR }} cf_access_client_id: ${{ vars.CF_ACCESS_STAGE_CLIENT_ID }} cf_access_client_secret: ${{ secrets.CF_ACCESS_STAGE_CLIENT_SECRET }} encryption_key: ${{ secrets.SCCACHE_ENC_KEY }} unit-tests: name: Unit needs: [setup, sccache-credentials] strategy: matrix: ${{ fromJSON(needs.setup.outputs.unit-tests) }} fail-fast: false if: needs.setup.outputs.unit-tests != '{"name":[],"include":[]}' runs-on: ubuntu-24.04 permissions: contents: read steps: - name: Show selection reason env: MATRIX: ${{ toJSON(matrix) }} run: echo "$MATRIX" - name: Checkout uses: actions/checkout@v6.0.2 - name: Clean up disk uses: $/.github/actions/clean-up-disk - name: Install tools uses: $/.github/actions/install-tools with: token: ${{ secrets.GITHUB_TOKEN }} encrypted_sccache_credentials: ${{ needs.sccache-credentials.outputs.encrypted-credentials }} sccache_encryption_key: ${{ secrets.SCCACHE_ENC_KEY }} - name: Prune repository uses: $/.github/actions/prune-repository with: scope: | ${{ matrix.name }} hash-repo-chores - name: Warm up repository uses: $/.github/actions/warm-up-repo - name: Find test steps to run id: tests run: | HAS_RUST=$([[ -f "${{ matrix.path }}/Cargo.toml" || ${{ matrix.path }} = "apps/hash-graph" ]] && echo 'true' || echo 'false') echo "has-rust=$HAS_RUST" | tee -a "$GITHUB_OUTPUT" if [[ "$HAS_RUST" == "true" ]]; then echo "COVERAGE_KEY=rust" >> "$GITHUB_ENV" else echo "COVERAGE_KEY=javascript" >> "$GITHUB_ENV" fi - name: Show disk usage run: df -h - name: Run tests continue-on-error: ${{ steps.tests.outputs.allow-failure == 'true' }} env: TEST_COVERAGE: ${{ github.event_name != 'merge_group' }} run: | turbo run test:unit --env-mode=loose --filter "${{ matrix.name }}" echo "TRIMMED_PACKAGE_NAME=$(echo "${{ matrix.name }}" | sed 's|@||g' | sed 's|/|.|g')" >> "$GITHUB_ENV" - name: Show disk usage run: df -h - uses: codecov/codecov-action@v5.5.5 name: Upload coverage to https://app.codecov.io/gh/hashintel/hash with: flags: ${{ env.TRIMMED_PACKAGE_NAME }} token: ${{ secrets.CODECOV_TOKEN }} ## not required for public repos, can be removed when https://github.com/codecov/codecov-action/issues/837 is resolved - name: Run miri if: always() && steps.tests.outputs.has-rust == 'true' run: | turbo run test:miri --filter "${{ matrix.name }}" - name: Show sccache logs if: always() && steps.tests.outputs.has-rust == 'true' run: | grep "CannotCache" /tmp/sccache.log | while IFS= read -r line; do # Extract reason - format as "reason1 (reason2)" if comma-separated, otherwise just "reason" if echo "$line" | grep -qE 'CannotCache\([^,]+, [^)]+\):'; then reason=$(echo "$line" | sed -E 's/.*CannotCache\(([^,]+), ([^)]+)\):.*/\1 (\2)/') else reason=$(echo "$line" | sed -E 's/.*CannotCache\(([^)]+)\):.*/\1/') fi # Extract crate name if present if echo "$line" | grep -q '"--crate-name"'; then crate=$(echo "$line" | sed -E 's/.*"--crate-name", "([^"]+)".*/\1/') else crate="" fi # Extract args args=$(echo "$line" | sed -E 's/.*CannotCache\([^)]+\): (\[.+\])$/\1/') echo "" echo "reason: $reason" echo "crate: $crate" echo "args: $args" done integration-tests: name: Integration needs: [setup, sccache-credentials] strategy: matrix: ${{ fromJSON(needs.setup.outputs.integration-tests) }} fail-fast: false # Only the top of a stack runs integration tests: it contains every layer below it. if: >- needs.setup.outputs.integration-tests != '{"name":[],"include":[]}' && (github.event.pull_request.stack == null || github.event.pull_request.stack.position == github.event.pull_request.stack.size) runs-on: ubuntu-24.04 permissions: contents: read steps: - name: Show selection reason env: MATRIX: ${{ toJSON(matrix) }} run: echo "$MATRIX" - name: Checkout uses: actions/checkout@v6.0.2 - name: Clean up disk uses: $/.github/actions/clean-up-disk - name: Install tools uses: $/.github/actions/install-tools with: token: ${{ secrets.GITHUB_TOKEN }} encrypted_sccache_credentials: ${{ needs.sccache-credentials.outputs.encrypted-credentials }} sccache_encryption_key: ${{ secrets.SCCACHE_ENC_KEY }} - name: Prune repository uses: $/.github/actions/prune-repository with: scope: | ${{ matrix.name }} - name: Warm up repository uses: $/.github/actions/warm-up-repo - name: Find test steps to run id: tests run: | HAS_BACKGROUND_TASKS=$(turbo run start:test --dry-run json | jq -c '[.tasks[] | select(.command != "") | .name] != []' || echo 'false') echo "has-background-tasks=$HAS_BACKGROUND_TASKS" | tee -a "$GITHUB_OUTPUT" HAS_RUST=$([[ -f "${{ matrix.path }}/Cargo.toml" || ${{ matrix.path }} = "apps/hash-graph" ]] && echo 'true' || echo 'false') echo "has-rust=$HAS_RUST" | tee -a "$GITHUB_OUTPUT" - name: Create temp files and folders run: mkdir -p var/logs - name: Install playwright if: matrix.name == '@tests/hash-playwright' uses: nick-fields/retry@v3.0.2 with: max_attempts: 3 timeout_minutes: 2 shell: bash command: npx playwright install chromium - name: Show disk usage run: df -h - name: Launch external services # Retried because BuildKit occasionally fails with transient rpc errors on # individual runners (e.g. "failed to receive status: rpc error: code = # Unavailable desc = error reading from server: EOF"), failing the job # before any test runs. See https://linear.app/hash/issue/SRE-803 uses: nick-fields/retry@v3.0.2 with: max_attempts: 3 timeout_minutes: 15 retry_wait_seconds: 15 shell: bash command: cd infra/compose && docker compose --profile dev up -d - name: Start background tasks id: background-tasks if: steps.tests.outputs.has-background-tasks == 'true' env: # Set terminal logging to WARN level and enable verbose file logging for CI HASH_GRAPH_LOG_CONSOLE_LEVEL: warn HASH_GRAPH_LOG_FILE_ENABLED: true HASH_GRAPH_LOG_FILE_LEVEL: info HASH_GRAPH_LOG_FOLDER: ${{ github.workspace }}/var/logs run: | # Optimistically compile background tasks. Ideally, we also `build` them but this includes # `@apps/plugin-browser` which needs `build:test` instead. We cannot filter it out because # except when running PlayWright tests, the plugin-browser is already pruned out so the # command would fail. turbo run compile --env-mode=loose mkdir -p logs turbo run start:test --env-mode=loose --log-order stream >var/logs/background-task.log 2>&1 & PID=$! echo "pid=$PID" | tee -a "$GITHUB_OUTPUT" # Not strictly needed to run the healthchecks here as they are also run in the integration # tests but it this way we can fail the job early if the background tasks are not healthy. # Also, the recorded time for the different steps is more accurate. turbo run start:test:healthcheck --env-mode=loose - name: Show disk usage run: df -h - name: Run tests continue-on-error: ${{ steps.tests.outputs.allow-failure == 'true' }} run: | turbo run test:integration --env-mode=loose --filter "${{ matrix.name }}" echo "TRIMMED_PACKAGE_NAME=$(echo "${{ matrix.name }}" | sed 's|@||g' | sed 's|/|.|g')" >> "$GITHUB_ENV" - name: Show disk usage run: df -h - uses: codecov/codecov-action@v5.5.5 name: Upload coverage to https://app.codecov.io/gh/hashintel/hash with: flags: ${{ env.TRIMMED_PACKAGE_NAME }} token: ${{ secrets.CODECOV_TOKEN }} ## not required for public repos, can be removed when https://github.com/codecov/codecov-action/issues/837 is resolved - name: Show container logs if: ${{ success() || failure() }} working-directory: infra/compose run: docker compose --profile dev logs --timestamps - name: Show background tasks logs if: always() && steps.tests.outputs.has-background-tasks == 'true' run: | kill -15 ${{ steps.background-tasks.outputs.pid }} || true cat var/logs/background-task.log - name: Upload artifact playwright-report if: matrix.name == '@tests/hash-playwright' && (success() || failure()) uses: actions/upload-artifact@v4.6.2 with: name: ${{ env.TRIMMED_PACKAGE_NAME }}_report path: tests/hash-playwright/playwright-report - name: Upload logs uses: actions/upload-artifact@v4.6.2 if: success() || failure() with: name: ${{ env.TRIMMED_PACKAGE_NAME }}_logs path: | var/api var/logs publish-rust: name: Publish dry run (Rust) needs: [setup] if: needs.setup.outputs.publish-rust != '[]' && (github.event_name == 'pull_request' || github.event_name == 'merge_group') runs-on: ubuntu-24.04 steps: - name: Checkout source code uses: actions/checkout@v6.0.2 - name: Clean up disk uses: $/.github/actions/clean-up-disk - name: Build package flags id: flags env: PUBLISH_PACKAGES: ${{ needs.setup.outputs.publish-rust }} run: | PACKAGES=$(echo "$PUBLISH_PACKAGES" | jq -r '.[]' | while read -r pkg; do echo -n "-p $pkg "; done) echo "packages=$PACKAGES" | tee -a "$GITHUB_OUTPUT" - name: Publish (dry run) run: cargo publish --all-features --dry-run --no-verify ${{ steps.flags.outputs.packages }} passed: name: Tests passed needs: [setup, sccache-credentials, unit-tests, integration-tests, publish-rust] if: always() runs-on: ubuntu-24.04 steps: - name: Check setup script run: | [[ ${{ needs.setup.result }} = success ]] - name: Check sccache credentials run: | [[ ${{ needs.sccache-credentials.result }} = success ]] - name: Check unit tests run: | [[ ${{ needs.unit-tests.result }} =~ success|skipped ]] - name: Check integration tests run: | [[ ${{ needs.integration-tests.result }} =~ success|skipped ]] - name: Check publish results run: | [[ ${{ needs.publish-rust.result }} =~ success|skipped ]] - name: Notify Slack on failure uses: rtCamp/action-slack-notify@v2.4.0 if: ${{ failure() && github.event_name == 'merge_group' }} env: SLACK_LINK_NAMES: true SLACK_MESSAGE: "At least one test job failed for a Pull Request in the Merge Queue failed " # Notifies @devops SLACK_TITLE: Tests failed SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} SLACK_USERNAME: GitHub VAULT_ADDR: "" VAULT_TOKEN: ""