forked from NVIDIA/Model-Optimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (63 loc) · 2.58 KB
/
_pr_gate.yml
File metadata and controls
65 lines (63 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: PR Gate
on:
workflow_call:
inputs:
files:
description: "Newline-separated list of file patterns to watch for changes"
required: true
type: string
outputs:
any_changed:
description: "Whether any relevant files changed"
value: ${{ jobs.check-file-changes.outputs.any_changed }}
jobs:
check-file-changes:
runs-on: ubuntu-latest
outputs:
any_changed: ${{ steps.changed-tests.outputs.any_changed || steps.non-pr.outputs.any_changed }}
steps:
# For non-PR triggers (schedule, workflow_dispatch), always run tests
- id: non-pr
if: "!startsWith(github.ref, 'refs/heads/pull-request/')"
run: echo "any_changed=true" >> $GITHUB_OUTPUT
- if: startsWith(github.ref, 'refs/heads/pull-request/')
uses: actions/checkout@v6
with:
fetch-depth: 0
- if: startsWith(github.ref, 'refs/heads/pull-request/')
id: get-pr-info
uses: nv-gha-runners/get-pr-info@main
# Extract SHAs from pr-info JSON via shell to avoid fromJSON on potentially-empty outputs
- if: startsWith(github.ref, 'refs/heads/pull-request/')
id: pr-shas
env:
PR_INFO: ${{ steps.get-pr-info.outputs.pr-info }}
run: |
echo "head_sha=$(echo "$PR_INFO" | jq -r '.head.sha')" >> $GITHUB_OUTPUT
echo "base_sha=$(echo "$PR_INFO" | jq -r '.base.sha')" >> $GITHUB_OUTPUT
# Get commit from main branch that is present in the PR to use as base for changed files
- if: startsWith(github.ref, 'refs/heads/pull-request/')
id: calculate-merge-base
run: |
(echo -n "merge-base="; git merge-base "${{ steps.pr-shas.outputs.base_sha }}" "${{ steps.pr-shas.outputs.head_sha }}") | tee --append "${GITHUB_OUTPUT}"
- if: startsWith(github.ref, 'refs/heads/pull-request/')
name: Check for changes in test-relevant directories
id: changed-tests
uses: step-security/changed-files@v46.0.5
with:
base_sha: ${{ steps.calculate-merge-base.outputs.merge-base }}
sha: ${{ steps.pr-shas.outputs.head_sha }}
files: ${{ inputs.files }}
fail_on_initial_diff_error: true
wait-checks:
needs: [check-file-changes]
if: >-
startsWith(github.ref, 'refs/heads/pull-request/') &&
needs.check-file-changes.outputs.any_changed == 'true'
uses: ./.github/workflows/_wait_for_checks.yml
permissions:
checks: read
secrets: inherit
with:
match_pattern: "^linux$" # Wait for Unit tests / linux (DCO is a prerequisite of linux)
delay: 300s