Skip to content

Commit df31f50

Browse files
authored
ci: Run tests only in merge queue or when labeled (#159)
Signed-off-by: Charlie Truong <chtruong@nvidia.com>
1 parent e3af337 commit df31f50

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

.github/workflows/cicd-main.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818
branches:
1919
- "main"
2020
- "r**"
21-
types: [labeled]
21+
types: [labeled, opened, synchronize, reopened]
2222
merge_group:
2323
types: [checks_requested]
2424
workflow_dispatch:
@@ -68,22 +68,28 @@ jobs:
6868
CHANGED_DOCS: ${{ steps.changed-files.outputs.doc_all_changed_files }}
6969
CHANGED_SRC: ${{ steps.changed-files.outputs.src_all_changed_files }}
7070
IS_PULLREQUEST: ${{ github.event_name == 'pull_request' }}
71-
LABEL: ${{ github.event.label.name == 'Run CICD' }}
71+
LABEL: ${{ github.event.label.name }}
7272
MERGE_GROUP: ${{ github.event_name == 'merge_group' }}
7373
run: |
7474
# Some output that's helpful for debugging
7575
echo "Docs changed: $CHANGED_DOCS"
7676
echo "Src changed: $CHANGED_SRC"
7777
echo "LABEL: $LABEL"
7878
echo "IS_PULLREQUEST: $IS_PULLREQUEST"
79+
echo "DOCS_ONLY: $DOCS_ONLY"
7980
81+
# Run CI only (on main or if label is attached) and if it's not only docs
8082
# Determine test level based on conditions
81-
if [[ "$DOCS_ONLY" == "true" ]]; then
83+
if [[ "$DOCS_ONLY" == "true" || "$LABEL" == "CI:docs" ]]; then
8284
# For doc-only changes, run only doc tests
8385
TEST_LEVEL="docs"
84-
elif [[ "$LABEL" == "true" || "$IS_PULLREQUEST" == "false" || "$MERGE_GROUP" == "true" ]]; then
86+
elif [[ "$LABEL" == "CI:L0" || "$IS_PULLREQUEST" == "false" || "$MERGE_GROUP" == "true" ]]; then
8587
# For labeled PRs, pushes to main (IS_PULL_REQUEST=false), or merge group events, run L0 by default
8688
TEST_LEVEL="L0"
89+
elif [[ "$LABEL" == "CI:L1" ]]; then
90+
TEST_LEVEL="L1"
91+
elif [[ "$LABEL" == "CI:L2" ]]; then
92+
TEST_LEVEL="L2"
8793
else
8894
# Skip tests by default for non-labeled PRs
8995
TEST_LEVEL="none"
@@ -101,7 +107,6 @@ jobs:
101107
name: Lint check
102108
needs: [pre-flight]
103109
runs-on: ubuntu-latest
104-
if: ${{ needs.pre-flight.outputs.test_level != 'none' }}
105110
steps:
106111
- name: Checkout repository
107112
uses: actions/checkout@v4
@@ -112,10 +117,10 @@ jobs:
112117
pre-commit run --all-files --show-diff-on-failure --color=always
113118
114119
sphinx-build:
120+
if: ${{ needs.pre-flight.outputs.test_level != 'none' }}
115121
name: Sphinx build
116122
needs: [pre-flight]
117123
runs-on: ubuntu-latest
118-
if: ${{ needs.pre-flight.outputs.test_level != 'none' }}
119124
steps:
120125
- name: Checkout repository
121126
uses: actions/checkout@v4
@@ -182,12 +187,12 @@ jobs:
182187
cd /opt/reinforcer
183188
cat <<EOF | tee -a $GITHUB_STEP_SUMMARY
184189
# Test Summary for level: ${{ needs.pre-flight.outputs.test_level }}
185-
190+
186191
## Unit test results
187192
\`\`\`json
188193
$(if [[ "${{ needs.pre-flight.outputs.test_level }}" =~ ^(L0|L1|L2)$ ]]; then cat tests/unit/unit_results.json || echo "n/a"; else echo "Not run"; fi)
189194
\`\`\`
190-
195+
191196
## Test Level: ${{ needs.pre-flight.outputs.test_level }}
192197
EOF
193198
secrets:
@@ -209,11 +214,15 @@ jobs:
209214
# Job is considered successful if nothing was run, or if all jobs were successful (the tests run even if only docs were run b/c doctests are selected)
210215
ALL_SUCCESS: >-
211216
${{
212-
(needs.pre-flight.outputs.test_level == 'none') ||
213-
(needs.pre-flight.outputs.test_level != 'none' &&
214-
needs.lint-check.result == 'success' &&
215-
needs.sphinx-build.result == 'success' &&
216-
needs.tests.result == 'success')
217+
needs.lint-check.result == 'success' &&
218+
(
219+
needs.pre-flight.outputs.test_level == 'none' ||
220+
(
221+
needs.pre-flight.outputs.test_level != 'none' &&
222+
needs.sphinx-build.result == 'success' &&
223+
needs.tests.result == 'success'
224+
)
225+
)
217226
}}
218227
CI_SKIP: ${{ github.event.label.name == 'Skip CICD' }}
219228
TEST_LEVEL: ${{ needs.pre-flight.outputs.test_level }}

0 commit comments

Comments
 (0)