Conditionally auto-approve dependabot PRs#1117
Conversation
3f85b18 to
2794a5f
Compare
31a8097 to
52296b9
Compare
52296b9 to
630de98
Compare
5b12e4f to
c6d82d6
Compare
|
8ac6588 to
eb2be71
Compare
d7b8460 to
868463d
Compare
|
I'm going to merge this pull request in an hour (after a meeting). Then either update a relevant Dependabot PR or close/reopen a Dependabot PR (which ever works to test). I'll also check the other Dependabot PRs, especially ones which we don't want merged (like npm or minor bumps). If anything goes wrong I'll revert the merge and we can figure out next steps. |
56b23b8 to
e37cd03
Compare
|
Another thought (sorry)... We should probably add branch protections to all I got the idea from https://boostsecurity.io/blog/weaponizing-dependabot-pwn-request-at-its-finest#:~:text=To%20prevent%20branch%20protection%20bypasses. |
It's a good point. My concern with branch protections is that we'd then have to open a PR to commit changes to dependabot PRs, which is not a great flow for us. |
ec5ae32 to
4d534c8
Compare
5d98805 to
94b46b4
Compare
We want to set up a flow to to auto-approve some dependabot PRs. PRs will only be approved if: - they are not `npm` updates, and - the update is only a version patch
Split the checks into jobs so that it can stop if a condition is not met Heavily based on https://github.com/alphagov/govuk-developer-docs/blob/68146cbddadb6adbf96fe3caaf15a3210ca66a37/.github/workflows/dependabot-auto-merge.yml
* The `auto_approve_and_merge` if-conditional was skipping because there was no value in `outputs.is_allowed_dependency` * Adding an outputs field on the `validate_this_is_an_allowed_dependency` job solved this issue
* This section is almost impossible test on a branch or even a fork, it must be tested by merging into the main branch * Uncommenting the section in order raise a PR and pair with someone on merging it
* Add step with a script which iterates through all the checks for a commit and waits until there are no pending and no failing checks * I tried waiting for a success but this didn't work because it's possible to have successful checks and pending/failing checks simultaneously, it was more reliable to wait for the absence of pending/failing checks then the presence of successful checks * Exclude the `wait_for_checks` check or else it loops until the max retries are reached (I learned this the hard way) * Add `wait_for_checks` to the auto_approve_and_merge step's need attribute so it will only run once the `wait_for_checks` has succeeded
* Add curly braces to the PR_URL variable since this is more conventional and safer bash * Add line separation to the if/else block to make the test command and statements more distinct
* Add linting workflow which runs `actionlint` on all the repo's workflows (see documentation: https://github.com/rhysd/actionlint). * I've introduced a fair amount of bash in the dependabot-auto-approve.yml file and it behooves us to ensure the bash is linted (in addition to the workflow logic)
Only the job that merges the PR needs write access. And we want to only auto-merge the dependencies we agree to automerge
We unintentionally broke this flow by agreeing to actionlint's suggestions
Instead of using actionlint's suggested script for installation (https://github.com/rhysd/actionlint/blob/main/scripts/download-actionlint.bash), dowload directly from releases and execute ourselves
We unintentionally broke this flow by agreeing to actionlint's suggestions. Since it's mostly a stylistic issue, we can ignore it
94b46b4 to
9d1d759
Compare
|
|
🎉 A review copy of this PR has been deployed! It is made of up two components Important Not all of the functionality of forms-runner is present in review apps. You should use the full dev environment to test the functionality which is disabled here. It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready For the sign in details and more information, see the review apps wiki page. |



What problem does this pull request solve?
We want to set up a flow to to auto-approve some dependabot PRs. PRs will only
be approved if:
npmupdates, andTrello card
Things to consider when reviewing
It would be great to sense check the workflow against what we're trying to achieve.
The workflow is configured to approve and merge a PR only if:
Otherwise, those steps will be skipped and the PR goes through the regular review process. You can see this in action in this PR, where all there a bunch of skipped checks relating to the auto-approving and auto-merging.
General things to consider
Local testing
The only way to test if this really works will be to merge it into the main branch unfortunately. Below are the two testing strategies Cat and I took.
Cat
I wanted to try this workflow locally using act but it keep getting an error at the step where we ask it to get the dependabot metadata.
Sarah
I ended up forking the
forms-runnerrepo so I could test changes on a safe main branch (see fork here: https://github.com/sarahseewhy/forms-runner). I created a new filereview_apps_on_pr_change.ymlin the forked repo and copied the contents from this branch.This was a useful approach because it allowed me to close and reopen Dependabot PRs to test the workflow and learn quite a bit.
Here's an example of the Actions at work on the forked repo: https://github.com/sarahseewhy/forms-runner/actions/runs/15110638823/job/42469149737?pr=39
However, forked repos don't have the Github permission to actually auto-merge so I'm returning to this branch and pull request.
You can take a similar approach by:
review_apps_on_pr_change.ymlreview_apps_on_pr_change.ymlfrom this branch into the forked repo@dependabot reopenin the comment section