workflow: Check for integration result comment #16
Workflow file for this run
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
name: Check for integration result | |
on: | |
issue_comment: | |
types: [created, edited] | |
pull_request: # for debugging | |
jobs: | |
# fetch comments, if integration-test comment is present, use that to label pass or fail. remove in-progress. | |
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 issue = { | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
} | |
const result = await github.rest.issues.listComments(issue); | |
const integrationComments = result.data.filter(c => c.user.login == 'primer-integration[bot]' && c.body.includes('<!-- test-result')) | |
if (integrationComments.length === 0) { | |
console.log('Integration comment with test-result not found') | |
return // nothing to do here | |
} | |
const latestComment = integrationComments.pop() | |
console.log(latestComment.body) | |
const pass = latestComment.body.includes('🟢') | |
console.log({pass}) | |
const existingLabels = await github.rest.issues.listLabelsOnIssue({...issue}) | |
console.log(existingLabels) | |
const integrationLabels = existingLabels.filter(label => label.name.startsWith('integration-tests:')) | |
console.log(integrationLabels) | |
// reset integration-tests labels before applying the latest label again | |
// todo: only try to remove these when they are present | |
try { | |
await github.rest.issues.removeLabel({...issue, name: 'integration-tests: recommended'}) | |
} catch (error) { | |
console.log(error.response.status, error.response.url) | |
} | |
try { | |
await github.rest.issues.removeLabel({...issue, name: 'integration-tests: passing'}) | |
} catch (error) { | |
console.log(error.response.status, error.response.url) | |
} | |
try { | |
await github.rest.issues.removeLabel({...issue, name: 'integration-tests: failing'}) | |
} catch (error) { | |
console.log(error.response.status, error.response.url) | |
} | |
await github.rest.issues.addLabels({ | |
...issue, | |
labels: [pass ? 'integration-tests: passing' : 'integration-tests: failing'], | |
}) | |