Reputation: 8311
Is it possible to configure Github actions workflow to merge pull request if it was approved (submitted review with approve
keyword) by one of the users (static fixed list, which can be written in workflow config file)? I tried to find it in documentation: https://help.github.com/en/articles/workflow-syntax-for-github-actions#on
- I suppose I can use on: [pull_request_review]
trigger for action, but documentation didn't mention how to access event payload in action yaml
file, where I need to extract reviewer login from this payload.
Upvotes: 1
Views: 2066
Reputation: 1324437
In addition of rmunn's answer, you might also want to protect your branch:
GitHub Actions: Prevent GitHub Actions from approving pull requests (2022, 14th Jan.)
We have introduced a new policy setting that controls whether GitHub Actions can approve pull requests.
This protects against a user using Actions to satisfy the "Required approvals" branch protection requirement and merging a change that was not reviewed by another user.To prevent breaking existing workflows,
Allow GitHub Actions reviews to count towards required approval
is enabled by default.
However, an organization admin can disable it under the organization's Actions settings.
That way, you are sure approvals were made exclusively by users, not by other actions.
Upvotes: 1
Reputation: 36688
I found this in https://help.github.com/en/articles/virtual-environments-for-github-actions#filesystems-on-github-hosted-machines:
workflow/event.json
: ThePOST
payload of the webhook event that triggered the workflow. GitHub rewrites this each time an action executes to isolate file content between actions. Use theGITHUB_EVENT_PATH
environment variable to access this file.
So the next step will be figuring out how to parse a JSON file and extract some data that a later step can use. For that, looking at GitHub's setup-dotnet
action might prove useful. In line 62 of installer.ts
, they call a function called core.exportVariable
, which as you can see here, causes ##[set-env name=NAME;]value
to be printed in the action's output. I've personally verified that this causes the environment variable called NAME
to automatically be present in later steps of the same workflow job.
Now, I don't yet know if you can simply do echo "##[set-env name=NAME;]$VALUE"
in a run
step of a GitHub workflow and have that work; it's possible that you'll have to write a custom action in Typescript to get access to core.exportVariable
. But once you have parsed the JSON, that would be one way of passing that information on to later steps in your job.
Upvotes: 2