-
Notifications
You must be signed in to change notification settings - Fork 108
121 lines (113 loc) · 4.15 KB
/
Copy pathlong-test-status-manager.yml
File metadata and controls
121 lines (113 loc) · 4.15 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Manages long test status for PRs based on labels and file changes.
#
# 1. Label-based bypass:
# - When 'no-long-tests' label is added: sets long-tests status to success
# - When 'no-long-tests' label is removed: sets status to pending
#
# 2. Automatic bypass for trivial changes:
# - When PR only modifies non-code files (docs, README, etc.), automatically
# sets long-tests status to success without running expensive tests
name: Long Test Status Manager
on:
pull_request:
types: [labeled, unlabeled, opened, synchronize, reopened]
permissions:
statuses: write
pull-requests: read
contents: read
jobs:
# Filter to detect if PR contains non-trivial changes requiring long tests
filter:
runs-on: ubuntu-latest
if: |
github.event.action == 'opened' ||
github.event.action == 'synchronize' ||
github.event.action == 'reopened'
outputs:
needs_long: ${{ steps.filter.outputs.test }}
steps:
- uses: actions/checkout@v6
- uses: dorny/paths-filter@v4
id: filter
with:
filters: |
test:
- 'palace/**'
- 'cmake/**'
- 'extern/**'
- 'examples/**'
- 'test/examples/**'
- 'test/unit/**'
- 'spack_repo/**'
- '.github/actions/**'
- '.github/workflows/long-test*.yml'
# Automatically bypass long tests for trivial changes
handle-trivial-changes:
needs: filter
if: |
needs.filter.outputs.needs_long == 'false' &&
!contains(github.event.pull_request.labels.*.name, 'trigger-long-tests') &&
!contains(github.event.pull_request.labels.*.name, 'no-long-tests')
runs-on: ubuntu-latest
steps:
- name: Set bypass status for trivial changes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
gh api "repos/$REPO/statuses/$HEAD_SHA" \
--method POST \
--field state=success \
--field context=long-tests \
--field description="Long tests bypassed (trivial changes)"
# Require long tests when non-trivial changes are detected
handle-non-trivial-changes:
needs: filter
if: |
needs.filter.outputs.needs_long == 'true' &&
!contains(github.event.pull_request.labels.*.name, 'no-long-tests')
runs-on: ubuntu-latest
steps:
- name: Set pending status for non-trivial changes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
gh api "repos/$REPO/statuses/$HEAD_SHA" \
--method POST \
--field state=pending \
--field context=long-tests \
--field description="Waiting for long tests (add 'trigger-long-tests' label to run)"
# Handle adding/removing 'no-long-tests' label
handle-no-long-tests:
if: github.event.label.name == 'no-long-tests'
runs-on: ubuntu-latest
steps:
# When label is added: bypass long test requirement
- name: Set bypass status
if: github.event.action == 'labeled'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
gh api "repos/$REPO/statuses/$HEAD_SHA" \
--method POST \
--field state=success \
--field context=long-tests \
--field description="Long tests bypassed"
# When label is removed: require long tests again
- name: Remove bypass status
if: github.event.action == 'unlabeled'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
gh api "repos/$REPO/statuses/$HEAD_SHA" \
--method POST \
--field state=pending \
--field context=long-tests \
--field description="Waiting for long tests (add 'trigger-long-tests' label to run)"