Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] Skip integration tests on docs-only changes #4165

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,27 @@ on:


jobs:
trigger-tests:
check-integration-test-changes:
if: github.event_name == 'pull_request'
name: Check if changes require integration tests to be triggered
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Check if all changes are in docs/ directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an action to that does the grep for you.

      - uses: dorny/paths-filter@v3
        id: changes
        with:
          filters: |
            integration_tests_required:
              - '**/*'
              - '!docs/**'
needs: [changes]
if: '{{ needs.changes.outputs.integration_tests_required == "true" }}'

id: check-integration-tests-required
run: |
changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
if echo "$changed_files" | grep -qv '^docs/'; then
echo "integration_tests_required=true" >> $GITHUB_ENV
else
echo "integration_tests_required=false" >> $GITHUB_ENV
fi

trigger-tests:
needs: check-integration-test-changes
if: '{{ env.integration_tests_required == "true" }}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an output, not an env.
Define the output and set an id for the job

jobs:
  changes:
    runs-on: ubuntu-latest
    outputs:  <----
      integration_tests_required: ${{ steps.filter.outputs.integration_tests_required }}
    steps:
      - uses: actions/checkout@v4
      
      - uses: dorny/paths-filter@v3
        id: filter <----
        with:
          filters: |
            integration_tests_required:
              - '!**/*.md'

name: Trigger Tests
runs-on: ubuntu-latest
environment: "test-trigger-is"
Expand All @@ -36,24 +55,28 @@ jobs:
-f pull_request_number=${{ github.event.pull_request.number }} \
-f commit_sha=${{ github.event.pull_request.head.sha }}



# Statuses and checks apply to specific commits (by hash).
# Enforcement of required checks is done both at the PR level and the merge queue level.
# In case of multiple commits in a single PR, the hash of the squashed commit
# will not match the one for the latest (approved) commit in the PR.
# We auto approve the check for the merge queue for two reasons:
# * Queue times out due to duration of tests.
# * Avoid running integration tests twice, since it was already run at the tip of the branch before squashing.
# Additionally, integration tests are not run on docs-only changes.
auto-approve:
if: github.event_name == 'merge_group'
if: '{{ github.event_name == "merge_group" || env.integration_tests_required == "false" }}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this won't work in the merge queue. If the "need" job is skipped, this will be skipped too (even with the "if" condition). You can use always() to ensure it runs. Also, use the output
if: always() && (github.event_name == 'merge_group' || needs.check-integration-test-changes.outputs.integration_tests_required == 'true')

runs-on: ubuntu-latest
steps:
- name: Mark Check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
if [ "${{ github.event_name }}" == "merge_group" ]; then
echo "Auto-approving check for merge queue"
else
echo "Auto-approving check for docs-only changes"
fi
gh api -X POST -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/statuses/${{ github.sha }} \
Expand Down
Loading