Skip to content

Commit e1993f1

Browse files
authored
workflow: Check for integration result comment (#5233)
* Create check-for-integration-result.yml * [skip ci] Add workflow_dispatch trigger for debugging * Update check-for-integration-result.yml * debug github.event * syntax fix * debug entire object * Update check-for-integration-result.yml * Update check-for-integration-result.yml * Refactor integration comments filter condition * Update check-for-integration-result.yml * Update check-for-integration-result.yml * Update check-for-integration-result.yml * silly typo * Update check-for-integration-result.yml * Update check-for-integration-result.yml * Update check-for-integration-result.yml * Update check-for-integration-result.yml * Update check-for-integration-result.yml * Update check-for-integration-result.yml * Update check-for-integration-result.yml * Update check-for-integration-result.yml * add more logs * add check for pull_request * rename workflow * remove debugger * run format
1 parent e021a8f commit e1993f1

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Check for integration result comment
2+
3+
on:
4+
issue_comment:
5+
types: [created, edited]
6+
7+
jobs:
8+
# note: this workflow always passes, it does not fail when integration tests are failing
9+
check-for-integration-result-comment:
10+
if: github.event.issue.pull_request
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Get integration result comment
14+
uses: actions/github-script@v7
15+
with:
16+
github-token: ${{ secrets.GITHUB_TOKEN }}
17+
script: |
18+
const INTEGRATION_LABEL_NAMES = {
19+
// synced with https://github.com/primer/react/labels?q=integration-tests
20+
skipped: 'integration-tests: skipped manually',
21+
recommended: 'integration-tests: recommended',
22+
failing: 'integration-tests: failing',
23+
passing: 'integration-tests: passing'
24+
};
25+
26+
const issue = {
27+
issue_number: context.issue.number,
28+
owner: context.repo.owner,
29+
repo: context.repo.repo
30+
};
31+
32+
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue(issue);
33+
const existingIntegrationLabels = currentLabels
34+
.map(label => label.name)
35+
.filter(label => label.startsWith('integration-tests:'));
36+
37+
if (existingIntegrationLabels.includes(INTEGRATION_LABEL_NAMES.skipped)) return;
38+
39+
const result = await github.rest.issues.listComments(issue);
40+
const integrationComments = result.data.filter(
41+
comment =>
42+
comment.user.login == 'primer-integration[bot]' &&
43+
comment.body.includes('<!-- test-result')
44+
);
45+
if (integrationComments.length === 0) {
46+
console.log('Integration comment with test-result not found');
47+
return; // CI should pass if there's nothing to do
48+
}
49+
50+
const latestComment = integrationComments.pop();
51+
console.log(latestComment.body);
52+
53+
// based on comment message in github/github: https://github.com/github/github/blob/fe7fe9072fd913ec04255ce7403ae764e6c33d5f/.github/workflows/github-ci.yml#L664-L692
54+
const pass = latestComment.body.includes('🟢');
55+
console.log({ pass });
56+
57+
const newIntegrationLabel = pass ? INTEGRATION_LABEL_NAMES.passing : INTEGRATION_LABEL_NAMES.failing;
58+
console.log({existingIntegrationLabels, newIntegrationLabel})
59+
60+
Object.values(INTEGRATION_LABEL_NAMES).map(async (name) => {
61+
if (name === newIntegrationLabel) {
62+
if (existingIntegrationLabels.includes(name)); // already added, nothing to do here
63+
else await github.rest.issues.addLabels({...issue, labels: [newIntegrationLabel]});
64+
} else if (existingIntegrationLabels.includes(name)) {
65+
// remove outdated labels
66+
await github.rest.issues.removeLabel({ ...issue, name });
67+
}
68+
});

0 commit comments

Comments
 (0)