From bd5ac204500eac5165af25ecbbaf380a896710c1 Mon Sep 17 00:00:00 2001 From: Tim Semenov Date: Fri, 24 May 2024 07:18:46 -0700 Subject: [PATCH] Create a common trigger for testing. PiperOrigin-RevId: 636909210 --- .github/workflows/pytest-trigger.yml | 52 ++++++++++++++++++++++++++++ .github/workflows/pytest.yml | 42 +++------------------- 2 files changed, 56 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/pytest-trigger.yml diff --git a/.github/workflows/pytest-trigger.yml b/.github/workflows/pytest-trigger.yml new file mode 100644 index 00000000000..48f6e6552c3 --- /dev/null +++ b/.github/workflows/pytest-trigger.yml @@ -0,0 +1,52 @@ +name: Tests trigger + +on: + workflow_dispatch: + pull_request: + branches: + - master + # Do not trigger tests for documentation or markdown docs. + paths-ignore: + - 'docs/**' + - '*.md' + push: + branches: + - master + # Do not trigger tests for documentation or markdown docs. + paths-ignore: + - 'docs/**' + - '*.md' + schedule: + # Trigger tests every day at 02:00 UTC to refresh cache. + - cron: '0 2 * * *' + +jobs: + activate-tests: + name: Check if tests should be run + runs-on: ubuntu-latest + + steps: + - name: Check + id: check + # For merged PR, activate testing only on the master branch, based on: + # https://github.community/t/trigger-workflow-only-on-pull-request-merge/17359 + run: | + echo "status=${{ github.ref == 'refs/heads/master' || ( + github.event.action != 'closed' + && github.event.pull_request.merged == false + ) }}" >> $GITHUB_OUTPUT + + - name: Trigger tests + if: ${{ steps.check.outputs.status == 'true' }} + uses: actions/github-script@v7 + with: + script: | + core.summary.addHeading(':white_check_mark: trigger tests', '2') + + - name: No tests + if: ${{ steps.check.outputs.status != 'true' }} + uses: actions/github-script@v7 + with: + script: | + core.summary.addHeading(':x: no need to trigger tests', '2') + core.setFailed('Tests do not need to run') diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 4697997990f..da63a2da70a 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -1,24 +1,9 @@ name: Unittests on: - workflow_dispatch: - pull_request: - branches: - - master - # Do not trigger tests for documentation or markdown docs. - paths-ignore: - - 'docs/**' - - '*.md' - push: - branches: - - master - # Do not trigger tests for documentation or markdown docs. - paths-ignore: - - 'docs/**' - - '*.md' - schedule: - # Trigger tests every day at 02:00 UTC to refresh cache. - - cron: '0 2 * * *' + workflow_run: + workflows: ["Tests trigger"] + types: [completed] # Cancel in-progress runs for the current workflow if not on the main branch # (as it mark the unittests as failed). @@ -33,27 +18,8 @@ env: PYTEST_NUM_SHARDS: 4 # Controls tests sharding enabled by `pytest-shard` jobs: - activate-tests: - name: Check if tests should be run - runs-on: ubuntu-latest - - steps: - - name: Check - id: check - # For merged PR, activate testing only on the master branch, based on: - # https://github.community/t/trigger-workflow-only-on-pull-request-merge/17359 - run: | - echo "status=${{ github.ref == 'refs/heads/master' || ( - github.event.action != 'closed' - && github.event.pull_request.merged == false - ) }}" >> $GITHUB_OUTPUT - - outputs: - status: ${{ steps.check.outputs.status }} - shards-job: - needs: activate-tests - if: ${{ needs.activate-tests.outputs.status }} + if: ${{ github.event.workflow_run.conclusion == 'success' }} name: Generate shards runs-on: ubuntu-latest