mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-06-28 04:43:44 +00:00
allow running on a ref instead of a PR
When running from a PR, the ref is the head of the PR in the origin repository. The PR is used to: * display comments about the location of the destination PR * asynchronously close / merge the destination PR when something happens in the origin PR When only the ref is available, the destination PR must be closed and the corresponding branch destroyed immediately after it concludes because there is no convenient way to know what or when something else will happen.
This commit is contained in:
parent
0e9a4e846b
commit
0c3c8b591b
12 changed files with 326 additions and 85 deletions
83
README.md
83
README.md
|
@ -4,58 +4,69 @@ Create and synchronize a PR in a dependent repository
|
|||
## Description
|
||||
|
||||
|
||||
If repository A depends on repository B, `cascadinging-pr` can be
|
||||
used by a workflow in repository B to trigger the CI on repository A
|
||||
and verify it passes when it will upgrade with the proposed change
|
||||
from repository B.
|
||||
If repository A depends on repository B, `cascadinging-pr` can be used
|
||||
by a workflow in repository B to trigger the CI on repository A and
|
||||
verify it passes when using a modified version of repository B. This
|
||||
modified version could be a pull request, a branch or a reference.
|
||||
|
||||
In the simplest case `cascading-pr` runs a workflow in `destination-repo`
|
||||
that uses `origin-ref` and blocks until it completes.
|
||||
|
||||
As an example, when a tag is set in Forgejo and builds a new release,
|
||||
it is concluded by a call to `cascading-pr` that runs
|
||||
[end-to-end](https://code.forgejo.org/forgejo/end-to-end/) tests on
|
||||
the newly built release to verify it works as expected.
|
||||
|
||||
When used in a workflow triggered by a PR event in `origin-repo`,
|
||||
`cascading-pr` will create, update and close a matching PR in
|
||||
another repository (`destination-repo`). When the PR is updated,
|
||||
`cascading-pr` subsequently will update the matching PR. The
|
||||
worfklows in `origin-repo` will wait for the workflow in
|
||||
`destination-repo` to complete. If the workflow in
|
||||
`destination-repo` fails, the workflow in `origin-repo` will also
|
||||
fail.
|
||||
`cascading-pr` will create, update and close a matching PR in the
|
||||
`destination-repo`. When the PR is updated, `cascading-pr` will
|
||||
update the matching PR. It waits for the workflow triggered by these
|
||||
updates in `destination-repo` to complete. If fails, `cascading-pr`,
|
||||
also fails.
|
||||
|
||||
As an example, when a PR is created in
|
||||
[`forgejo/runner`](https://code.forgejo.org/forgejo/runner/), a
|
||||
matching PR is created in
|
||||
[`actions/setup-forgejo`](https://code.forgejo.org/actions/setup-forgejo/)
|
||||
with the proposed change. `cascading-pr` will wait until the CI in
|
||||
with the proposed change and `cascading-pr` waits until the CI in
|
||||
`actions/setup-forgejo` is successful.
|
||||
|
||||
The `update` script is expected to be found in the origin repository
|
||||
running the PR. It is given four arguments:
|
||||
The `update` script is expected to be found in `origin-repo` and is
|
||||
given the following arguments:
|
||||
|
||||
* A directory in which the destination repository (or a fork) is checked-out
|
||||
on the base branch
|
||||
* A file with the JSON describing the pull request in the
|
||||
destination repository
|
||||
* A directory in which the origin repository is checked-out
|
||||
on the head branch
|
||||
* A file with the JSON describing the pull request in the
|
||||
origin repository
|
||||
* A directory path in which the `destination-branch` of `destination-repo`
|
||||
(or a fork) is checked-out.
|
||||
* The path to a JSON file describing the pull request in `destination-repo`.
|
||||
* A directory path in which the head of `origin-repo` is checked-out at:
|
||||
* if `origin-pr` is specified, the head branch of `origin-pr`
|
||||
* otherwise `origin-ref`
|
||||
* Information about the `origin-repo`
|
||||
* if `origin-pr` is specified, the path to a JSON file desccribing
|
||||
the pull request in `origin-repo`
|
||||
* otherwise `origin-ref`
|
||||
|
||||
If changes are found in the destination repository directory after the `update` script runs,
|
||||
they will be pushed as a new commit in the PR.
|
||||
If changes are found in the destination repository directory after
|
||||
the `update` script runs, they will be pushed as a new commit in the
|
||||
PR in the `destination-repo`.
|
||||
|
||||
`origin-token` is used when accessing `origin-repo` and needs the
|
||||
`read:user`, `read:repository` and `write:issue` scopes.
|
||||
|
||||
`destination-token` is used to push the branch that contains an
|
||||
update to `destination-repo` and to open a pull request. It needs
|
||||
the `read:user`, `write:repository` and `write:issue` scopes.
|
||||
update to `destination-repo` (or `destination-fork-repo`) and open a
|
||||
pull request. It needs the `read:user`, `write:repository` and
|
||||
`write:issue` scopes.
|
||||
|
||||
It is recommended that a dedicated user is used to create
|
||||
`destination-token` and that `destination-fork-repo` is always used
|
||||
unless the users who are able to create pull requests are trusted.
|
||||
|
||||
When the PR is from a forked repository, the `update` script is run
|
||||
from the default branch of the base repository instead of the head
|
||||
branch of the fork. The pull request author must not be trusted
|
||||
and it is imperative that the `update` script never runs anything
|
||||
found in the head branch of the pull request.
|
||||
When the PR in the `destination-repo` is from a forked repository,
|
||||
the `update` script is run from the default branch of
|
||||
`destination-repo` instead of the head of the PR which is a branch
|
||||
in destination-fork-repo. The PR author must not be trusted and it
|
||||
is imperative that the `update` script never runs anything found in
|
||||
the head branch of the PR.
|
||||
|
||||
If the fork of the destination repository is specified and it does
|
||||
not exist, it is created.
|
||||
|
@ -68,7 +79,8 @@ not exist, it is created.
|
|||
| origin-url | URL of the Forgejo instance where the PR that triggers the action is located (e.g. https://code.forgejo.org) | `true` | |
|
||||
| origin-repo | the repository in which the PR was created | `true` | |
|
||||
| origin-token | a token with write permission on origin-repo | `true` | |
|
||||
| origin-pr | number of the PR in {orign-repo} | `true` | |
|
||||
| origin-pr | number of the PR in {orign-repo}, mutually exclusive with {origin-ref} | `false` | |
|
||||
| origin-ref | reference in {orign-repo}, mutually exclusive with {origin-pr} | `false` | |
|
||||
| destination-url | URL of the Forgejo instance where the cascading PR is created or updated (e.g. https://code.forgejo.org) | `true` | |
|
||||
| destination-repo | the repository in which the cascading PR is created or updated | `true` | |
|
||||
| destination-fork-repo | the fork of {destination-repo} in which the {destination-branch} will be created or updated | `false` | |
|
||||
|
@ -168,12 +180,13 @@ git clone https://code.forgejo.org/actions/setup-forgejo
|
|||
export PATH=$(pwd)/setup-forgejo:$PATH
|
||||
git clone https://code.forgejo.org/actions/cascading-pr
|
||||
cd cascading-pr
|
||||
export DIR=/tmp/forgejo-for-cascading-pr
|
||||
forgejo-curl.sh logout
|
||||
forgejo-runner.sh teardown
|
||||
forgejo.sh teardown
|
||||
forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.21
|
||||
forgejo-binary.sh teardown
|
||||
forgejo-binary.sh setup root admin1234 https://codeberg.org/forgejo/forgejo/releases/download/v1.21.3-0/forgejo-1.21.3-0-linux-amd64
|
||||
FORGEJO_RUNNER_CONFIG=$(pwd)/tests/runner-config.yaml forgejo-runner.sh setup
|
||||
url=http://$(cat forgejo-ip):3000
|
||||
url=$(cat $DIR/forgejo-url)
|
||||
firefox $url
|
||||
```
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue