-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Check for integration result | ||
|
||
on: | ||
issue_comment: | ||
types: [created, edited] | ||
pull_request: # for debugging | ||
|
||
jobs: | ||
# note: this workflow always passes, it does not fail when integration tests are failing | ||
check-for-integration-result: | ||
if: github.event.issue.pull_request | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get integration result comment | ||
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 { data: currentLabels } = await github.rest.issues.listLabelsOnIssue(issue); | ||
const existingIntegrationLabels = currentLabels | ||
.map(label => label.name) | ||
.filter(label => label.startsWith('integration-tests:')); | ||
if (existingIntegrationLabels.includes(INTEGRATION_LABEL_NAMES.skipped)) return; | ||
const result = await github.rest.issues.listComments(issue); | ||
const integrationComments = result.data.filter( | ||
comment => | ||
comment.user.login == 'primer-integration[bot]' && | ||
comment.body.includes('<!-- test-result') | ||
); | ||
if (integrationComments.length === 0) { | ||
console.log('Integration comment with test-result not found'); | ||
return; // CI should pass if there's nothing to do | ||
} | ||
const latestComment = integrationComments.pop(); | ||
console.log(latestComment.body); | ||
// based on comment message in github/github: https://github.com/github/github/blob/fe7fe9072fd913ec04255ce7403ae764e6c33d5f/.github/workflows/github-ci.yml#L664-L692 | ||
const pass = latestComment.body.includes('🟢'); | ||
console.log({ pass }); | ||
const newIntegrationLabel = pass ? INTEGRATION_LABEL_NAMES.passing : INTEGRATION_LABEL_NAMES.failing; | ||
console.log({existingIntegrationLabels, newIntegrationLabel}) | ||
Object.values(INTEGRATION_LABEL_NAMES).map(async (name) => { | ||
if (name === newIntegrationLabel) { | ||
if (existingIntegrationLabels.includes(name)); // already added, nothing to do here | ||
else await github.rest.issues.addLabels({...issue, labels: [newIntegrationLabel]}); | ||
} else if (existingIntegrationLabels.includes(name)) { | ||
// remove outdated labels | ||
await github.rest.issues.removeLabel({ ...issue, name }); | ||
} | ||
}); |