Skip to content

Commit 265b8eb

Browse files
authored
Update check-for-integration-result.yml
1 parent 7f99638 commit 265b8eb

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

.github/workflows/check-for-integration-result.yml

+40-38
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
pull_request: # for debugging
77

88
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
1010
check-for-integration-result:
1111
# if: ${{ github.event.issue.pull_request }}
1212
runs-on: ubuntu-latest
@@ -16,51 +16,53 @@ jobs:
1616
with:
1717
github-token: ${{ secrets.GITHUB_TOKEN }}
1818
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+
1927
const issue = {
2028
issue_number: context.issue.number,
2129
owner: context.repo.owner,
2230
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+
2540
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+
);
2746
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
5849
}
5950
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);
6453
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 });
6557
58+
const newIntegrationLabel = pass ? INTEGRATION_LABEL_NAMES.passing : INTEGRATION_LABEL_NAMES.failing;
6659
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

Comments
 (0)