Skip to content

Commit

Permalink
Workflow: Recommend integration tests again if there are new commits (#…
Browse files Browse the repository at this point in the history
…5264)

* Update recommend-integration-tests.yml

* Update recommend-integration-tests.yml
  • Loading branch information
siddharthkp authored Nov 13, 2024
1 parent 536d7ab commit eade27f
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions .github/workflows/recommend-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,43 @@ jobs:
- name: Has diff?
run: echo ${{ steps.source-files.outputs.diff != '' }}

- name: Get or Create Comment
- name: Add label and comment
if: ${{ steps.source-files.outputs.diff != '' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const result = await github.paginate(github.rest.issues.listComments, {
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 labels = await github.paginate(github.rest.issues.listLabelsOnIssue, issue);
const integrationLabels = labels.filter(label => label.name.startsWith('integration-tests'))
const hasPassingLabel = integrationLabels.find(label => label.name === INTEGRATION_LABEL_NAMES.passing)
const previousComment = result.filter(c => c.user.login == 'github-actions[bot]' && c.body.startsWith('<!-- recommend-integration-tests.yml -->'))
if (!previousComment.length) {
if (integrationLabels.length === 0) {
// recommend integration tests
await github.rest.issues.addLabels({...issue, labels: [INTEGRATION_LABEL_NAMES.recommended]})
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
...issue,
body: '<!-- recommend-integration-tests.yml -->\n\n :wave: Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the [integration workflow](https://gh.io/testing_primer_at_dotcom). Thanks!'
})
}
- name: Add label
if: ${{ steps.source-files.outputs.diff != '' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const result = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
})
const integrationLabels = result.data.filter(label => label.name.startsWith('integration-tests'))
if (!integrationLabels.length) {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['integration-tests: recommended'],
} else if (hasPassingLabel) {
// recommend running integration tests again as there are new commits that might change the status
// note: we don't remove 'integration-tests: passing' label because this is only a suggestion/nudge
await github.rest.issues.addLabels({...issue, labels: [INTEGRATION_LABEL_NAMES.recommended]})
await github.rest.issues.createComment({
...issue,
body: '<!-- recommend-integration-tests.yml -->\n\n :wave: Hi, there are new commits since the last successful integration test. We recommend running the [integration workflow](https://gh.io/testing_primer_at_dotcom) once more, unless you are sure the new changes do not affect github/github. Thanks!'
})
}

0 comments on commit eade27f

Please sign in to comment.