-
Notifications
You must be signed in to change notification settings - Fork 538
71 lines (63 loc) · 3.21 KB
/
recommend-integration-tests.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
name: Recommend integration tests
on:
pull_request:
jobs:
recommend:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Get source files changes
id: source-files
run: |
DIFF=$(git diff --name-only origin/main | grep 'packages/react' | grep -Ev '.stories.tsx|.docs.json' || true)
if [ -z "$DIFF" ]; then
echo "diff=" >> $GITHUB_OUTPUT
else
echo "diff=true" >> $GITHUB_OUTPUT
fi
- name: Has diff?
run: echo ${{ steps.source-files.outputs.diff != '' }}
- name: Add label and comment
if: ${{ steps.source-files.outputs.diff != '' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const INTEGRATION_LABEL_NAMES = {
// synced with https://github.com/primer/react/labels?q=integration-tests
skipped: 'integration-tests: skipped manually',
recommended: 'integration-tests: recommended',
failing: 'integration-tests: failing',
passing: 'integration-tests: passing'
}
const issue = {
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
}
const labels = await github.paginate(github.rest.issues.listLabelsOnIssue, issue);
const integrationLabels = labels.filter(label => label.name.startsWith('integration-tests'))
const hasPassingLabel = integrationLabels.find(label => label.name === INTEGRATION_LABEL_NAMES.passing)
if (integrationLabels.length === 0) {
// recommend integration tests
await github.rest.issues.addLabels({...issue, labels: [INTEGRATION_LABEL_NAMES.recommended]})
await github.rest.issues.createComment({
...issue,
body: '<!-- recommend-integration-tests.yml -->\n\n :wave: Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the [integration workflow](https://gh.io/testing_primer_at_dotcom). Thanks!'
})
} else if (hasPassingLabel) {
// recommend running integration tests again as there are new commits that might change the status
// note: we don't remove 'integration-tests: passing' label because this is only a suggestion/nudge
await github.rest.issues.addLabels({...issue, labels: [INTEGRATION_LABEL_NAMES.recommended]})
await github.rest.issues.createComment({
...issue,
body: '<!-- recommend-integration-tests.yml -->\n\n :wave: Hi, there are new commits since the last successful integration test. We recommend running the [integration workflow](https://gh.io/testing_primer_at_dotcom) once more, unless you are sure the new changes do not affect github/github. Thanks!'
})
}