Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto approve any pull request with the pull-request-number input #186

Merged
merged 16 commits into from Jun 17, 2021

Conversation

roryabraham
Copy link
Contributor

Fixed issue

Fixes #21

Details

This PR makes it so that this action can be utilized from a workflow triggered by the workflow_dispatch event by adding an optional pull_request_number input. If provided, we will auto-approve that pull request, rather than relying on the pull_request from the GitHub context.

Happy to provide more details or changes as you see fit! Thanks!

Context

I am trying to make a workflow that can be triggered by other workflows/actions that:

  1. Creates a new app version
  2. Creates a pull request to update the version on the main branch
  3. Auto-approves and auto-merges that pull request.

This way, my other workflows can perform the above steps and wait for the workflow to complete and the version update to be present on the main branch. This will go a long way in simplifying my CI/CD code and in preventing race conditions.

Copy link
Owner

@hmarr hmarr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this!

I've added a few relatively minor comments.

Additionally, I noticed that the package-lock.json has changed quite a lot, and the lockfile format switched from v2 to v1. Would you mind reverting that change? I assume it's because you're using an older version of npm.

src/approve.ts Outdated Show resolved Hide resolved
src/approve.ts Outdated Show resolved Hide resolved
src/main.ts Outdated Show resolved Hide resolved
src/approve.test.ts Outdated Show resolved Hide resolved
README.md Outdated
- uses: hmarr/auto-approve-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: 1234
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid the hard-coded example number, perhaps this snippet could use workflow_dispatch inputs so we could change this to a dynamic value.

Alternatively, if you're looking to run this workflow after another Actions workflow that generates a pull request, workflow_run might be the trigger you're looking for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Alternatively, if you're looking to run this workflow after another Actions workflow that generates a pull request, workflow_run might be the trigger you're looking for?

Thanks for the suggestion! Actually, I currently have my automerge workflow happening in response to the pull_request event, and it is successfully triggered after the workflow that generates a pull request. In case you're wondering why I submitted this PR, I am effectively trying to make a "subroutine" that:

  1. Generates a new version
  2. Creates a PR to update the main branch with that version
  3. Merges the PR so that the main branch is updated.

And I want that to happen all in one workflow, so that I can use https://github.com/softprops/turnstyle to prevent race conditions and merge conflicts. I'll use that subroutine in concert with https://github.com/convictional/trigger-workflow-and-wait to synchronously create a new version from any workflow that needs to do that. I'm hopeful that this will DRY up my workflows and simplify the handling of race conditions 😁

@roryabraham
Copy link
Contributor Author

roryabraham commented Apr 9, 2021

I'm unable to reproduce this test failure locally 🤔

image

@roryabraham
Copy link
Contributor Author

roryabraham commented Apr 9, 2021

Hmmm even after merging with the upstream, and using the local Github Actions runner, I'm still unable to reproduce this failure... 😞

Local Github Actions Run Output
in auto-approve-action on  Rory-AutoApproveAnyPullRequest is 📦 v2.1.0 roryabraham⬢ v14.16.0 
  sudo act pull_request
Password:
[CI/Lint and test] 🚀  Start image=nektos/act-environments-ubuntu:18.04
[CI/Lint and test]   🐳  docker run image=nektos/act-environments-ubuntu:18.04 entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[CI/Lint and test]   🐳  docker cp src=/Users/roryabraham/auto-approve-action/. dst=/github/workspace
[CI/Lint and test] ⭐  Run Check out code
[CI/Lint and test]   ✅  Success - Check out code
[CI/Lint and test] ⭐  Run Setup nodejs
[CI/Lint and test]   ☁  git clone 'https://github.com/actions/setup-node' # ref=v2
[CI/Lint and test]   🐳  docker cp src=/Users/roryabraham/.cache/act/actions-setup-node@v2 dst=/actions/
[CI/Lint and test]   💬  ::debug::isExplicit: 
[CI/Lint and test]   💬  ::debug::explicit? false
[CI/Lint and test]   💬  ::debug::evaluating 0 versions
[CI/Lint and test]   💬  ::debug::match not found
| Attempting to download 14...
[CI/Lint and test]   💬  ::debug::check 14.16.1 satisfies 14
[CI/Lint and test]   💬  ::debug::x64===x64 && darwin===linux
[CI/Lint and test]   💬  ::debug::x64===x64 && linux===linux
[CI/Lint and test]   💬  ::debug::matched 14.16.1
| Acquiring 14.16.1 - x64 from https://github.com/actions/node-versions/releases/download/14.16.1-725059535/node-14.16.1-linux-x64.tar.gz
[CI/Lint and test]   💬  ::debug::Downloading https://github.com/actions/node-versions/releases/download/14.16.1-725059535/node-14.16.1-linux-x64.tar.gz
[CI/Lint and test]   💬  ::debug::Destination /tmp/d7e45ab4-4701-4d30-8a43-1523e3696dd1
[CI/Lint and test]   💬  ::debug::download complete
| Extracting ...
[CI/Lint and test]   💬  ::debug::Checking tar --version
[CI/Lint and test]   💬  ::debug::tar (GNU tar) 1.29%0ACopyright (C) 2015 Free Software Foundation, Inc.%0ALicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.%0AThis is free software: you are free to change and redistribute it.%0AThere is NO WARRANTY, to the extent permitted by law.%0A%0AWritten by John Gilmore and Jay Fenlason.
| [command]/bin/tar xz --strip 1 --warning=no-unknown-keyword -C /tmp/ac083928-d8ba-4a31-b42a-94614d52a4eb -f /tmp/d7e45ab4-4701-4d30-8a43-1523e3696dd1
| Adding to the cache ...
[CI/Lint and test]   💬  ::debug::Caching tool node 14.16.1 x64
[CI/Lint and test]   💬  ::debug::source dir: /tmp/ac083928-d8ba-4a31-b42a-94614d52a4eb
[CI/Lint and test]   💬  ::debug::destination /opt/hostedtoolcache/node/14.16.1/x64
[CI/Lint and test]   💬  ::debug::finished caching tool
| Done
[CI/Lint and test]   ⚙  ::add-path:: /opt/hostedtoolcache/node/14.16.1/x64/bin
[CI/Lint and test]   ❓  ##[add-matcher]/actions/actions-setup-node@v2/.github/tsc.json
[CI/Lint and test]   ❓  ##[add-matcher]/actions/actions-setup-node@v2/.github/eslint-stylish.json
[CI/Lint and test]   ❓  ##[add-matcher]/actions/actions-setup-node@v2/.github/eslint-compact.json
[CI/Lint and test]   ✅  Success - Setup nodejs
[CI/Lint and test] ⭐  Run Install dependencies
| added 571 packages in 6.753s
[CI/Lint and test]   ✅  Success - Install dependencies
[CI/Lint and test] ⭐  Run Check style with prettier
| 
| > auto-approve-action@2.1.0 format-check /github/workspace
| > prettier --check **/*.ts
| 
| Checking formatting...
| All matched files use Prettier code style!
[CI/Lint and test]   ✅  Success - Check style with prettier
[CI/Lint and test] ⭐  Run Run tests
| 
| > auto-approve-action@2.1.0 test /github/workspace
| > jest
| 
|  PASS  src/approve.test.ts
|   ✓ when a review is successfully created (42 ms)
|   ✓ when a review is successfully created using pull-request-number (12 ms)
|   ✓ without a pull request (1 ms)
|   ✓ when the token is invalid (13 ms)
|   ✓ when the token doesn't have write permissions (12 ms)
|   ✓ when a user tries to approve their own pull request (11 ms)
|   ✓ when the token doesn't have access to the repository (9 ms)
| 
Test Suites: 1 passed, 1 total
| Tests:       7 passed, 7 total
| Snapshots:   0 total
| Time:        3.277 s
| Ran all test suites.
[CI/Lint and test]   ✅  Success - Run tests
[CI/Lint and test] ⭐  Run Check build artefact has been checked in
| 
| > auto-approve-action@2.1.0 build /github/workspace
| > ncc build src/main.ts
| 
| ncc: Version 0.27.0
| ncc: Compiling file index.js
| ncc: Using typescript@4.2.3 (local user-provided)
| 208kB  dist/index.js
| 208kB  [4041ms] - ncc 0.27.0
[CI/Lint and test]   ✅  Success - Check build artefact has been checked in

@roryabraham
Copy link
Contributor Author

roryabraham commented May 11, 2021

@hmarr Sorry, I'm at a bit of a loss for ideas here. Am I holding something wrong? Any ideas how I might try to reproduce this error?

@roryabraham
Copy link
Contributor Author

FWIW, I've been using this in production for a while and it seems to work just fine 🤷

@hmarr
Copy link
Owner

hmarr commented Jun 17, 2021

Strange – I tried pushing these commits to a new branch and found the build passed successfully. I'll merge, and if the build is still broken I'll try to figure out what's going on.

@hmarr hmarr merged commit 6a9ec75 into hmarr:v2 Jun 17, 2021
@hmarr
Copy link
Owner

hmarr commented Jun 17, 2021

The tests passed after merging. 🤷 😆

estahn pushed a commit to estahn/k8s-image-swapper that referenced this pull request Dec 1, 2022
## [1.3.3](v1.3.2...v1.3.3) (2022-12-01)

### ⬆️ Dependencies

* **deps:** Bump alpine from 3.16.2 to 3.16.3 ([#388](#388)) ([ffae497](ffae497))
* **deps:** Bump alpine from 3.16.3 to 3.17.0 ([#395](#395)) ([d32255d](d32255d))
* **deps:** Bump github.com/aws/aws-sdk-go from 1.44.126 to 1.44.136 ([#391](#391)) ([61a6ae2](61a6ae2)), closes [#4620](https://github.com/estahn/k8s-image-swapper/issues/4620) [#4619](https://github.com/estahn/k8s-image-swapper/issues/4619) [#4617](https://github.com/estahn/k8s-image-swapper/issues/4617) [#4616](https://github.com/estahn/k8s-image-swapper/issues/4616) [#4615](https://github.com/estahn/k8s-image-swapper/issues/4615) [#4614](https://github.com/estahn/k8s-image-swapper/issues/4614) [#4613](https://github.com/estahn/k8s-image-swapper/issues/4613) [#4611](https://github.com/estahn/k8s-image-swapper/issues/4611) [#4608](https://github.com/estahn/k8s-image-swapper/issues/4608) [#4609](https://github.com/estahn/k8s-image-swapper/issues/4609)
* **deps:** Bump github.com/aws/aws-sdk-go from 1.44.136 to 1.44.146 ([#397](#397)) ([d4a6136](d4a6136)), closes [#4638](https://github.com/estahn/k8s-image-swapper/issues/4638) [#4636](https://github.com/estahn/k8s-image-swapper/issues/4636) [#4633](https://github.com/estahn/k8s-image-swapper/issues/4633) [#4632](https://github.com/estahn/k8s-image-swapper/issues/4632) [#4630](https://github.com/estahn/k8s-image-swapper/issues/4630) [#4628](https://github.com/estahn/k8s-image-swapper/issues/4628) [#4627](https://github.com/estahn/k8s-image-swapper/issues/4627) [#4626](https://github.com/estahn/k8s-image-swapper/issues/4626) [#4625](https://github.com/estahn/k8s-image-swapper/issues/4625) [#4624](https://github.com/estahn/k8s-image-swapper/issues/4624)
* **deps:** Bump github.com/containers/image/v5 from 5.23.0 to 5.23.1 ([#393](#393)) ([84f4d18](84f4d18))
* **deps:** Bump github.com/go-co-op/gocron from 1.17.1 to 1.18.0 ([#390](#390)) ([1750ee9](1750ee9)), closes [go-co-op/gocron#388](go-co-op/gocron#388) [go-co-op/gocron#389](go-co-op/gocron#389) [go-co-op/gocron#392](go-co-op/gocron#392) [go-co-op/gocron#394](go-co-op/gocron#394) [go-co-op/gocron#393](go-co-op/gocron#393) [go-co-op/gocron#392](go-co-op/gocron#392) [go-co-op/gocron#394](go-co-op/gocron#394) [#393](#393) [#394](#394) [#392](#392) [#389](#389)
* **deps:** Bump github.com/gruntwork-io/terratest from 0.40.24 to 0.41.3 ([#398](#398)) ([ab35b1a](ab35b1a)), closes [gruntwork-io/terratest#1203](gruntwork-io/terratest#1203) [gruntwork-io/terratest#1202](gruntwork-io/terratest#1202) [gruntwork-io/terratest#1201](gruntwork-io/terratest#1201) [gruntwork-io/terratest#1199](gruntwork-io/terratest#1199) [gruntwork-io/terratest#1196](gruntwork-io/terratest#1196) [#1202](https://github.com/estahn/k8s-image-swapper/issues/1202) [#1203](https://github.com/estahn/k8s-image-swapper/issues/1203) [#1201](https://github.com/estahn/k8s-image-swapper/issues/1201) [#1199](https://github.com/estahn/k8s-image-swapper/issues/1199) [#1196](https://github.com/estahn/k8s-image-swapper/issues/1196)
* **deps:** Bump github.com/prometheus/client_golang from 1.13.0 to 1.13.1 ([#387](#387)) ([b155a16](b155a16)), closes [#1146](https://github.com/estahn/k8s-image-swapper/issues/1146) [#1148](https://github.com/estahn/k8s-image-swapper/issues/1148) [#1118](https://github.com/estahn/k8s-image-swapper/issues/1118) [#1146](https://github.com/estahn/k8s-image-swapper/issues/1146) [#1148](https://github.com/estahn/k8s-image-swapper/issues/1148) [#1118](https://github.com/estahn/k8s-image-swapper/issues/1118) [#1157](https://github.com/estahn/k8s-image-swapper/issues/1157) [#1146](https://github.com/estahn/k8s-image-swapper/issues/1146) [#1148](https://github.com/estahn/k8s-image-swapper/issues/1148) [#1118](https://github.com/estahn/k8s-image-swapper/issues/1118)
* **deps:** Bump github.com/prometheus/client_golang from 1.13.1 to 1.14.0 ([#392](#392)) ([af00594](af00594)), closes [#1150](https://github.com/estahn/k8s-image-swapper/issues/1150) [#1103](https://github.com/estahn/k8s-image-swapper/issues/1103) [prometheus/client_golang#1118](prometheus/client_golang#1118) [prometheus/client_golang#1103](prometheus/client_golang#1103) [prometheus/client_golang#1125](prometheus/client_golang#1125) [prometheus/client_golang#1130](prometheus/client_golang#1130) [prometheus/client_golang#1148](prometheus/client_golang#1148) [prometheus/client_golang#1146](prometheus/client_golang#1146) [prometheus/client_golang#1152](prometheus/client_golang#1152) [#1150](https://github.com/estahn/k8s-image-swapper/issues/1150) [#1103](https://github.com/estahn/k8s-image-swapper/issues/1103) [#1162](https://github.com/estahn/k8s-image-swapper/issues/1162) [#1161](https://github.com/estahn/k8s-image-swapper/issues/1161) [#1160](https://github.com/estahn/k8s-image-swapper/issues/1160) [#1136](https://github.com/estahn/k8s-image-swapper/issues/1136) [#1133](https://github.com/estahn/k8s-image-swapper/issues/1133) [#1150](https://github.com/estahn/k8s-image-swapper/issues/1150) [#1152](https://github.com/estahn/k8s-image-swapper/issues/1152)
* **deps:** Bump github.com/spf13/viper from 1.13.0 to 1.14.0 ([#385](#385)) ([6f79498](6f79498)), closes [spf13/viper#1457](spf13/viper#1457) [spf13/viper#1458](spf13/viper#1458) [spf13/viper#1460](spf13/viper#1460) [spf13/viper#1428](spf13/viper#1428) [spf13/viper#1406](spf13/viper#1406) [spf13/viper#1437](spf13/viper#1437) [spf13/viper#1453](spf13/viper#1453) [spf13/viper#1449](spf13/viper#1449) [spf13/viper#1461](spf13/viper#1461)
* **deps:** Bump golangci/golangci-lint-action from 3.3.0 to 3.3.1 ([#389](#389)) ([0b50f7b](0b50f7b)), closes [golangci/golangci-lint-action#590](golangci/golangci-lint-action#590) [golangci/golangci-lint-action#591](golangci/golangci-lint-action#591) [golangci/golangci-lint-action#592](golangci/golangci-lint-action#592) [golangci/golangci-lint-action#593](golangci/golangci-lint-action#593) [golangci/golangci-lint-action#594](golangci/golangci-lint-action#594) [golangci/golangci-lint-action#595](golangci/golangci-lint-action#595) [golangci/golangci-lint-action#596](golangci/golangci-lint-action#596) [golangci/golangci-lint-action#597](golangci/golangci-lint-action#597) [golangci/golangci-lint-action#598](golangci/golangci-lint-action#598) [golangci/golangci-lint-action#599](golangci/golangci-lint-action#599) [#599](#599) [#598](#598) [#596](#596) [#595](#595) [#593](#593) [#591](#591) [#590](#590)
* **deps:** Bump hmarr/auto-approve-action from 2 to 3 ([#396](#396)) ([0b982a2](0b982a2)), closes [hmarr/auto-approve-action#205](hmarr/auto-approve-action#205) [hmarr/auto-approve-action#202](hmarr/auto-approve-action#202) [hmarr/auto-approve-action#202](hmarr/auto-approve-action#202) [hmarr/auto-approve-action#200](hmarr/auto-approve-action#200) [hmarr/auto-approve-action#200](hmarr/auto-approve-action#200) [hmarr/auto-approve-action#186](hmarr/auto-approve-action#186) [hmarr/auto-approve-action#191](hmarr/auto-approve-action#191) [#210](#210) [#205](#205)
* **deps:** Bump k8s.io/api from 0.25.3 to 0.25.4 ([#401](#401)) ([0f80b5d](0f80b5d))
* **deps:** Bump k8s.io/apimachinery from 0.25.3 to 0.25.4 ([#399](#399)) ([1f0944f](1f0944f)), closes [#112218](https://github.com/estahn/k8s-image-swapper/issues/112218) [haoruan/automated-cherry-pick-of-#111936](https://github.com/haoruan/automated-cherry-pick-of-/issues/111936)
* **deps:** Bump k8s.io/client-go from 0.25.3 to 0.25.4 ([#400](#400)) ([ad036e0](ad036e0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Approval of a PR made by another action
2 participants