Begin setting up torsion automation #56
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
# this is adapted from openff-docs/cookbook_pr_trigger.yaml | |
name: Trigger torsion benchmark run on comment with "/run-torsions" | |
on: | |
pull_request: | |
types: [labeled] | |
jobs: | |
trigger: | |
permissions: write-all | |
if: ${{ github.event.label.name == 'torsion-dev' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Dispatch benchmark | |
if: ${{ github.event.label.name == 'torsion-dev' }} | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const owner = context.repo.owner | |
const repo = context.repo.repo | |
const pr_number = context.issue.number | |
const comment = context.payload.comment | |
// Return early if comment is not the trigger phrase | |
// if (!comment.body.startsWith('/run-torsions')) { | |
// console.log("Comment is not trigger phrase") | |
// return | |
// } | |
// / This will 404 if the user is not a collaborator (and cause an | |
// / exception below), so this check prevents random users from | |
// / triggering the workflow. | |
// / https://docs.github.com/en/rest/collaborators/collaborators | |
// / ?apiVersion=2022-11-28#check-if-a-user-is-a-repository-collaborator | |
// const commenter = await github.request( | |
// 'GET /repos/{owner}/{repo}/collaborators/{username}/permission', | |
// { | |
// owner: owner, | |
// repo: repo, | |
// username: comment.user.login, | |
// headers: { | |
// 'X-GitHub-Api-Version': '2022-11-28' | |
// } | |
// }, | |
// const commenter_can_push = commenter.data.user.permissions.push | |
// // Return early if comment sender doesn't have push rights | |
// if (!commenter_can_push) { | |
// console.log("User does not have push permissions") | |
// return | |
// } | |
const pr = await github.rest.pulls.get({ | |
pull_number: pr_number, | |
owner: owner, | |
repo: repo, | |
}) | |
const ref = pr.data.head.ref | |
// treat everything after the command name as an argument | |
// const args = comment.body.split(" ").slice(1); | |
// const path = args[0]; // path to submission dir | |
// if (!path) { | |
// console.log("No submission path provided"); | |
// return; | |
// } | |
const path = "torsion-dev/tmp.yaml" // "submissions" YAML | |
const env = "devtools/torsions.yaml"; // conda env | |
// We didn't return early, so dispatch the workflow | |
const dispatch = await github.request( | |
'POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches', | |
{ | |
owner: owner, | |
repo: repo, | |
workflow_id: 'torsions.yaml', | |
ref: ref, | |
inputs: { | |
pr_number: pr_number.toString(), | |
env: env, | |
path: path | |
}, | |
headers: { | |
'X-GitHub-Api-Version': '2022-11-28' | |
} | |
}, | |
) | |
console.log(dispatch) |