Update experimental tag #215
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: Trigger preproc on comment with "/regenerate-cache" | |
on: | |
issue_comment: | |
types: [created] | |
jobs: | |
trigger: | |
if: ${{ github.event.issue.pull_request }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Dispatch preproc | |
if: ${{ github.event.issue.pull_request }} | |
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 != '/regenerate-cache') { | |
console.log("Comment is not trigger phrase") | |
return | |
} | |
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 | |
// 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: 'cookbook_preproc.yaml', | |
ref: ref, | |
inputs: {pr_number: pr_number.toString()}, | |
headers: { | |
'X-GitHub-Api-Version': '2022-11-28' | |
} | |
}, | |
) | |
console.log(dispatch) |