From 93e3a01dcaf518e9df23c5c8853470609d0cc6f3 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Mon, 30 Sep 2024 12:37:56 -0400 Subject: [PATCH] test --- .github/workflows/test.yaml | 50 ++++------------------- .github/workflows/which-tests-to-run.yaml | 43 +++++++++++++++++++ 2 files changed, 51 insertions(+), 42 deletions(-) create mode 100644 .github/workflows/which-tests-to-run.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e1a2f3c9271..117c167fd7e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,51 +11,17 @@ name: test on: push: workflow_call: - outputs: - should_run_core_integration_tests: - description: 'Whether core integration tests should run' - value: ${{ jobs.check_paths.outputs.should_run_query_tests }} - -env: - QUERY_SERVICE_PATHS: 'weave-js/ weave_query/' jobs: - check_paths: - runs-on: ubuntu-latest - outputs: - should_run_query_tests: ${{ steps.query_service.outputs.should_run_query_tests }} - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - fetch-tags: true - ref: ${{ github.head_ref }} - - run: git fetch origin ${{ github.base_ref }} - - id: query_service - run: | - if [ "${{ github.event_name }}" = "pull_request" ]; then - base_sha=$(git rev-parse origin/${{ github.base_ref }}) - head_sha=$(git rev-parse HEAD) - changed_files=$(git diff --name-only $base_sha $head_sha) - else - changed_files=$(git diff --name-only HEAD^) - fi - - for path in ${{ env.WATCHED_PATHS }}; do - if echo "$changed_files" | grep -q "$path"; then - echo "should_run_query_tests=true" >> $GITHUB_OUTPUT - exit 0 - fi - done - echo "should_run_query_tests=false" >> $GITHUB_OUTPUT - + determine_tests: + uses: ./github/workflows/which-tests-to-run.yaml # ==== Query Service Jobs ==== build-container-query-service: name: Build Legacy (Query Service) test container timeout-minutes: 30 runs-on: [self-hosted, builder] - needs: check_paths - if: ${{ needs.check_paths.outputs.should_run_query_tests == 'true' }} + needs: determine_tests + if: ${{ needs.determine_tests.outputs.should_run_query_tests == 'true' }} # runs-on: ubuntu-latest env: @@ -133,8 +99,8 @@ jobs: test-query-service-matrix-check: # This job does nothing and is only used for the branch protection needs: - test-query-service - - check_paths - if: ${{ needs.check_paths.outputs.should_run_query_tests == 'true' }} + - determine_tests + if: ${{ needs.determine_tests.outputs.should_run_query_tests == 'true' }} runs-on: ubuntu-latest @@ -148,8 +114,8 @@ jobs: weavejs-lint-compile: name: WeaveJS Lint and Compile runs-on: ubuntu-latest - needs: check_paths - if: ${{ needs.check_paths.outputs.should_run_query_tests == 'true' }} + needs: determine_tests + if: ${{ needs.determine_tests.outputs.should_run_query_tests == 'true' }} # runs-on: [self-hosted, gke-runner] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/which-tests-to-run.yaml b/.github/workflows/which-tests-to-run.yaml new file mode 100644 index 00000000000..1ac33afdeaa --- /dev/null +++ b/.github/workflows/which-tests-to-run.yaml @@ -0,0 +1,43 @@ +name: Determine which tests to run + +on: + push: + pull_request: + workflow_call: + outputs: + should_run_query_tests: + description: 'Whether query tests should run' + value: ${{ jobs.check_paths.outputs.should_run_query_tests }} + +env: + QUERY_SERVICE_PATHS: 'weave-js/ weave_query/' + +jobs: + check_paths: + runs-on: ubuntu-latest + outputs: + should_run_query_tests: ${{ steps.query_service.outputs.should_run_query_tests }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + fetch-tags: true + ref: ${{ github.head_ref }} + - run: git fetch origin ${{ github.base_ref }} + - id: query_service + run: | + if [ "${{ github.event_name }}" = "pull_request" ]; then + base_sha=$(git rev-parse origin/${{ github.base_ref }}) + head_sha=$(git rev-parse HEAD) + changed_files=$(git diff --name-only $base_sha $head_sha) + else + changed_files=$(git diff --name-only HEAD^) + fi + + for path in ${{ env.QUERY_SERVICE_PATHS }}; do + if echo "$changed_files" | grep -q "$path"; then + echo "should_run_query_tests=true" >> $GITHUB_OUTPUT + exit 0 + fi + done + echo "should_run_query_tests=false" >> $GITHUB_OUTPUT