-
Notifications
You must be signed in to change notification settings - Fork 70
105 lines (103 loc) · 3.6 KB
/
set-tests-statuses.yml
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
name: Set Test Statuses
on:
- pull_request_target
permissions:
pull-requests: write
checks: write
contents: write
statuses: write
jobs:
# Tugboat tests are not automatically set pending, even though they are
# required in branch protection rules (see #10553).
#
# Therefore, a PR can inappropriately appear to be ready to merge if,
# for instance, a composer.lock merge conflict prevents the Tugboat
# preview from successfully building.
#
# Additionally, CI tests are only run for code changes but they are
# required checks, even for documentation only changes. In these cases,
# the tests should be skipped since no functional changes have occured.
#
# To address these two issues, this action sets check statuses directly
# to the appropriate states:
# - For docs only changes, all required checks are set to 'success'
# - For code changes, Tugboat tests are set to 'pending' so that we can
# trust our automated code review processes more.
set-test-statuses:
name: Set Tests Statuses
runs-on: ubuntu-latest
steps:
- name: Check for documentation only changes
id: docs-only
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
script: |
const opts = github.rest.pulls.listFiles.endpoint.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
})
const files = await github.paginate(
opts,
(response) => response.data.map(
(file) => file.filename
)
)
for (const file of files) {
console.log(`Checking PR file: ${file}`)
if (!file.endsWith('.md')) {
console.log(`Code change found in: ${file}`)
return "false"
}
}
console.log(`No code change found.`)
return "true"
result-encoding: string
- name: Set status for documentation changes.
if: ${{ steps.docs-only.outputs.result == 'true' }}
run: |
test_names=(
va/tests/cypress
va/tests/phpunit
va/tests/content-build-gql
va/tests/status-error
'Composer Validate'
'Check Fields'
ESLint
Stylelint
PHPStan
PHPUnit
PHP_CodeSniffer
'PHP Lint'
)
for test_name in "${test_names[@]}"; do
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/${GITHUB_REPOSITORY}/statuses/${SHA}" \
-f state='success' \
-f context="${test_name}";
done;
env:
SHA: ${{ github.event.pull_request.head.sha }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set status for code changes.
if: ${{ steps.docs-only.outputs.result == 'false' }}
run: |
test_names=(
va/tests/cypress
va/tests/phpunit
va/tests/content-build-gql
va/tests/status-error
)
for test_name in "${test_names[@]}"; do
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/${GITHUB_REPOSITORY}/statuses/${SHA}" \
-f state='pending' \
-f context="${test_name}";
done;
env:
SHA: ${{ github.event.pull_request.head.sha }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}