6
6
pull_request : # for debugging
7
7
8
8
jobs :
9
- # fetch comments, if integration-test comment is present, use that to label pass or fail. remove in-progress.
9
+ # note: this workflow always passes, it does not fail when integration tests are failing
10
10
check-for-integration-result :
11
11
# if: ${{ github.event.issue.pull_request }}
12
12
runs-on : ubuntu-latest
@@ -16,51 +16,53 @@ jobs:
16
16
with :
17
17
github-token : ${{ secrets.GITHUB_TOKEN }}
18
18
script : |
19
+ const INTEGRATION_LABEL_NAMES = {
20
+ // synced with https://github.com/primer/react/labels?q=integration-tests
21
+ skipped: 'integration-tests: skipped manually',
22
+ recommended: 'integration-tests: recommended',
23
+ failing: 'integration-tests: failing',
24
+ passing: 'integration-tests: passing'
25
+ };
26
+
19
27
const issue = {
20
28
issue_number: context.issue.number,
21
29
owner: context.repo.owner,
22
30
repo: context.repo.repo
23
- }
24
-
31
+ };
32
+
33
+ const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue(issue);
34
+ const integrationLabels = currentLabels
35
+ .map(label => label.name)
36
+ .filter(label => label.startsWith('integration-tests:'));
37
+
38
+ if (integrationLabels.includes(INTEGRATION_LABEL_NAMES.skipped)) return;
39
+
25
40
const result = await github.rest.issues.listComments(issue);
26
- const integrationComments = result.data.filter(c => c.user.login == 'primer-integration[bot]' && c.body.includes('<!-- test-result'))
41
+ const integrationComments = result.data.filter(
42
+ comment =>
43
+ comment.user.login == 'primer-integration[bot]' &&
44
+ comment.body.includes('<!-- test-result')
45
+ );
27
46
if (integrationComments.length === 0) {
28
- console.log('Integration comment with test-result not found')
29
- return // nothing to do here
30
- }
31
-
32
- const latestComment = integrationComments.pop()
33
- console.log(latestComment.body)
34
- const pass = latestComment.body.includes('🟢')
35
- console.log({pass})
36
-
37
- const existingLabels = await github.rest.issues.listLabelsOnIssue({...issue})
38
- console.log(existingLabels)
39
- const integrationLabels = existingLabels.filter(label => label.name.startsWith('integration-tests:'))
40
- console.log(integrationLabels)
41
-
42
- // reset integration-tests labels before applying the latest label again
43
- // todo: only try to remove these when they are present
44
- try {
45
- await github.rest.issues.removeLabel({...issue, name: 'integration-tests: recommended'})
46
- } catch (error) {
47
- console.log(error.response.status, error.response.url)
48
- }
49
- try {
50
- await github.rest.issues.removeLabel({...issue, name: 'integration-tests: passing'})
51
- } catch (error) {
52
- console.log(error.response.status, error.response.url)
53
- }
54
- try {
55
- await github.rest.issues.removeLabel({...issue, name: 'integration-tests: failing'})
56
- } catch (error) {
57
- console.log(error.response.status, error.response.url)
47
+ console.log('Integration comment with test-result not found');
48
+ return; // CI should pass if there's nothing to do
58
49
}
59
50
60
- await github.rest.issues.addLabels({
61
- ...issue,
62
- labels: [pass ? 'integration-tests: passing' : 'integration-tests: failing'],
63
- })
51
+ const latestComment = integrationComments.pop();
52
+ console.log(latestComment.body);
64
53
54
+ // based on comment message in github/github: https://github.com/github/github/blob/fe7fe9072fd913ec04255ce7403ae764e6c33d5f/.github/workflows/github-ci.yml#L664-L692
55
+ const pass = latestComment.body.includes('🟢');
56
+ console.log({ pass });
65
57
58
+ const newIntegrationLabel = pass ? INTEGRATION_LABEL_NAMES.passing : INTEGRATION_LABEL_NAMES.failing;
66
59
60
+ INTEGRATION_LABEL_NAMES.map(async (name) => {
61
+ if (name === newIntegrationLabel) {
62
+ if (integrationLabels.includes(name)); // already added, nothing to do here
63
+ else await github.rest.issues.addLabels({...issue, labels: [newIntegrationLabel]});
64
+ } else if (integrationLabels.includes(name)) {
65
+ // remove outdated labels
66
+ await github.rest.issues.removeLabel({ ...issue, name });
67
+ }
68
+ });
0 commit comments