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

push-to-fork won't push to sibling repos in the same network #2412

Closed
bgilbert opened this issue Sep 28, 2023 · 3 comments · Fixed by #2414 or #2717
Closed

push-to-fork won't push to sibling repos in the same network #2412

bgilbert opened this issue Sep 28, 2023 · 3 comments · Fixed by #2414 or #2717

Comments

@bgilbert
Copy link
Contributor

Subject of the issue

Consider a setup where a repo upstream/repo has a workflow w that creates PRs to upstream/repo, but w should run without write access to upstream/repo. To achieve this, there's an unprivileged bot account bot with a fork of upstream/repo (bot/repo) and upstream/repo has a Personal Access Token for bot in its secrets. w runs with no permissions (permissions: {contents: none}), uses the bot credential to check out upstream/repo, and uses push-to-fork to submit PRs from a bot/repo branch.

Now I'd like to modify w and test my changes. I think these are my options:

  1. Fork upstream/repo to bgilbert/repo, set up my fork with a PAT for bot (or for a separate bot-staging account, to avoid testing with the prod account), and run the workflow. This fails with:

    Error: Repository 'bot/repo' is not a fork of 'bgilbert/repo'. Unable to continue.
    
  2. When testing w, disable push-to-fork and set permissions: {contents: write, pull-requests: write}, so that PRs to bgilbert/repo are created from branches in bgilbert/repo. This is what I've been doing, but as a result I'm testing w with more permissions than it'll have in production. I've definitely pushed broken code to prod as a result of this.

  3. Create my own bgilbert-bot account containing a fork of bgilbert/repo. This lets me test with an environment similar to prod, but requires me to have a second GitHub account for testing, and accounts are pretty heavyweight. If w has multiple developers, they each need their own bot account (or to share an account but constantly delete and recreate its fork), since an account can't have multiple forks of forks of upstream/repo.

Could the "is not a fork of" test be removed? GitHub doesn't require it; any repo in the network of upstream/repo can send PRs to any other repo in the network.

Steps to reproduce

I don't have a minimized reproducer handy, but could create one if needed.

@bgilbert
Copy link
Contributor Author

Proof-of-concept fix in #2414.

@peter-evans
Copy link
Owner

@bgilbert

I've added this change to the v6 release candidate. You can use it like this:

      - uses: peter-evans/create-pull-request@v6-rc

I'll be releasing v6 at some point in the near future.

@peter-evans peter-evans mentioned this issue Jan 31, 2024
Merged
peter-evans added a commit that referenced this issue Jan 31, 2024
* feat: update author and committer input defaults

* Update github-actions[bot]

* Update author to new email format

* feat: optional input for git ops token

* feat: allow push-to-fork to push to sibling repos (#2414)

Fixes #2412.

* build: update dist

* feat: update action runtime to node 20 (#2340)

* feat: add truncate warning to pull request body

* perf: unshallow only when necessary

* fix: remove the remote for the fork on completion

* feat: infer github server and api urls

* test: integration test fixes

* build: bump major version

* docs: update to v6

---------

Co-authored-by: Teko <[email protected]>
Co-authored-by: Benjamin Gilbert <[email protected]>
@peter-evans
Copy link
Owner

I've now released v6. Thanks for your patience.

aleksandrychev pushed a commit to aleksandrychev/create-pull-request that referenced this issue Mar 4, 2024
* feat: update author and committer input defaults

* Update github-actions[bot]

* Update author to new email format

* feat: optional input for git ops token

* feat: allow push-to-fork to push to sibling repos (peter-evans#2414)

Fixes peter-evans#2412.

* build: update dist

* feat: update action runtime to node 20 (peter-evans#2340)

* feat: add truncate warning to pull request body

* perf: unshallow only when necessary

* fix: remove the remote for the fork on completion

* feat: infer github server and api urls

* test: integration test fixes

* build: bump major version

* docs: update to v6

---------

Co-authored-by: Teko <[email protected]>
Co-authored-by: Benjamin Gilbert <[email protected]>
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 a pull request may close this issue.

2 participants