-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run cross-version tests by comment #11765
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,83 @@ | ||
async function main({ context, github }) { | ||
const { comment } = context.payload; | ||
const { owner, repo } = context.repo; | ||
const pull_number = context.issue.number; | ||
|
||
const pr = await github.rest.pulls.get({ owner, repo, pull_number }); | ||
const flavorsMatch = comment.body.match(/\/(?:cross-version-test|crt)\s+([^\n]+)\n?/); | ||
if (!flavorsMatch) { | ||
return; | ||
} | ||
|
||
// Reject non-maintainers | ||
if (!["OWNER", "MEMBER", "COLLABORATOR"].includes(comment.author_association)) { | ||
await github.rest.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number: pull_number, | ||
body: "Only maintainers are allowed to use this command.", | ||
}); | ||
return; | ||
} | ||
|
||
// Run the workflow | ||
const flavors = flavorsMatch[1]; | ||
const uuid = Array.from({ length: 16 }, () => Math.floor(Math.random() * 16).toString(16)).join( | ||
"" | ||
); | ||
const workflow_id = "cross-version-tests.yml"; | ||
await github.rest.actions.createWorkflowDispatch({ | ||
owner, | ||
repo, | ||
workflow_id, | ||
ref: pr.data.base.ref, | ||
inputs: { | ||
repository: `${owner}/${repo}`, | ||
ref: pr.merge_commit_sha, | ||
flavors, | ||
// The response of create-workflow-dispatch request doesn't contain the ID of the triggered | ||
// workflow run. We need to pass a unique identifier to the workflow run and find the run by | ||
// the identifier. See https://github.com/orgs/community/discussions/9752 for more details. | ||
uuid, | ||
}, | ||
}); | ||
|
||
// Find the triggered workflow run | ||
let run; | ||
const maxAttempts = 5; | ||
for (let i = 0; i < maxAttempts; i++) { | ||
await new Promise((resolve) => setTimeout(resolve, 5000)); | ||
|
||
const { data: runs } = await github.rest.actions.listWorkflowRunsForRepo({ | ||
owner, | ||
repo, | ||
workflow_id, | ||
event: "workflow_dispatch", | ||
}); | ||
run = runs.workflow_runs.find((run) => run.name.includes(uuid)); | ||
if (run) { | ||
break; | ||
} | ||
} | ||
|
||
if (!run) { | ||
await github.rest.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number: pull_number, | ||
body: "Failed to find the triggered workflow run.", | ||
}); | ||
return; | ||
} | ||
|
||
await github.rest.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number: pull_number, | ||
body: `Cross-version test run started: ${run.html_url}`, | ||
}); | ||
} | ||
|
||
module.exports = { | ||
main, | ||
}; |
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,30 @@ | ||
name: Cross version test runner | ||
on: | ||
issue_comment: | ||
types: [created] | ||
|
||
permissions: | ||
contents: read | ||
|
||
defaults: | ||
run: | ||
shell: bash --noprofile --norc -exo pipefail {0} | ||
|
||
jobs: | ||
run: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
if: ${{ github.event.issue.pull_request && github.event.comment.body }} | ||
permissions: | ||
pull-requests: write | ||
actions: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/github-script@v7 | ||
id: get-ref | ||
with: | ||
result-encoding: string | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const runner = require('./.github/workflows/cross-version-test-runner.js'); | ||
await runner.main({ context, github }); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be improved by: