We have a check that runs on PRs:
name: check_time
on:
pull_request:
types:
- synchronize
- opened
- reopened
issue_comment:
types:
- created
jobs:
check_time:
runs-on: ubuntu-latest
# run this if this event is not triggered by comment created (i.e. triggered by PR opened)
# or run this if the comment was created on a PR
if: ${{ !github.event.comment || (github.event.issue.pull_request && contains(github.event.comment.body, '/check_time')) }}
steps:
...
We'd like to be able to trigger this check on a schedule. So, every so often, for every open pull request, have this check rerun. Here is the attempted implementation below:
name: trigger_check_time
on:
workflow_dispatch:
inputs:
reason:
description: 'Manual trigger of check-time'
required: false
schedule:
- cron: '5 20 * * *'
jobs:
provide_prs_json:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set_matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- name: List Pull Requests
id: list_prs
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const response = await github.rest.pulls.list({
owner: 'xxxx',
repo: 'yyyy',
});
const prs = response.data.map(pr => pr.number);
console.log(`found ${prs.length} prs: ${JSON.stringify(prs)}`);
return prs;
- name: Set Matrix
id: set_matrix
run: echo ::set-output name=matrix::'${{ steps.list_prs.outputs.result }}'
dispatch_event:
needs: provide_prs_json
runs-on: ubuntu-latest
strategy:
# the real magic happens here - create dynamic matrix from the json
matrix:
pr: ${{ fromJson(needs.provide_prs_json.outputs.matrix) }}
steps:
- name: Comment PR
id: comment_pr
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
try {
github.rest.issues.createComment({
owner: 'xxxx',
repo: 'yyyy',
issue_number: ${{ matrix.pr }},
body: "/check_time",
});
} catch (e) {}
The above all works fine in the sense that it finds all the PRs and comments in their threads but the comment does not trigger the check_time
workflow to run. I assume this is because events github-actions
do not trigger other events? Is there any way to comment as a user instead?
I also looked at using workflow_dispatch
event, but not sure how to have the check_time
workflow run in the context of each PR (i.e. if the check_time
workflow fails, the PRs should no longer be mergeable).