Skip to content

Commit

Permalink
Create a common trigger for testing.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 636909210
  • Loading branch information
fineguy authored and The TensorFlow Datasets Authors committed May 24, 2024
1 parent 6bbba45 commit bd5ac20
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 38 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/pytest-trigger.yml
Original file line number Diff line number Diff line change
@@ -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')
42 changes: 4 additions & 38 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -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).
Expand All @@ -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
Expand Down

0 comments on commit bd5ac20

Please sign in to comment.