mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-06-27 20:33: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
8
tests/destination-fail/.forgejo/workflows/test.yml
Normal file
8
tests/destination-fail/.forgejo/workflows/test.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: MIT
|
||||
name: test
|
||||
on: [pull_request_target]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: docker
|
||||
steps:
|
||||
- run: false
|
20
tests/origin-branch-fail/.forgejo/workflows/test.yml
Normal file
20
tests/origin-branch-fail/.forgejo/workflows/test.yml
Normal file
|
@ -0,0 +1,20 @@
|
|||
# SPDX-License-Identifier: MIT
|
||||
name: test
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: docker
|
||||
steps:
|
||||
- uses: SELF@vTest
|
||||
with:
|
||||
origin-url: ${{ env.GITHUB_SERVER_URL }}
|
||||
origin-repo: user1/origin-branch-fail
|
||||
origin-token: ${{ secrets.ORIGIN_TOKEN }}
|
||||
origin-ref: refs/heads/main
|
||||
destination-url: ${{ env.GITHUB_SERVER_URL }}
|
||||
destination-repo: user2/destination-fail
|
||||
destination-branch: main
|
||||
destination-token: ${{ secrets.DESTINATION_TOKEN }}
|
||||
update: ./upgraded
|
||||
debug: true
|
1
tests/origin-branch-fail/README
Normal file
1
tests/origin-branch-fail/README
Normal file
|
@ -0,0 +1 @@
|
|||
originrepo
|
14
tests/origin-branch-fail/upgraded
Executable file
14
tests/origin-branch-fail/upgraded
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
destination_checkout="$1"
|
||||
destination_pr_json="$2"
|
||||
origin_checkout="$3"
|
||||
origin_ref="$4"
|
||||
|
||||
test -d $destination_checkout
|
||||
test -d $origin_checkout
|
||||
test "$origin_ref"
|
||||
|
||||
date +%s > $destination_checkout/last
|
20
tests/origin-branch/.forgejo/workflows/test.yml
Normal file
20
tests/origin-branch/.forgejo/workflows/test.yml
Normal file
|
@ -0,0 +1,20 @@
|
|||
# SPDX-License-Identifier: MIT
|
||||
name: test
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: docker
|
||||
steps:
|
||||
- uses: SELF@vTest
|
||||
with:
|
||||
origin-url: ${{ env.GITHUB_SERVER_URL }}
|
||||
origin-repo: user1/origin-branch
|
||||
origin-token: ${{ secrets.ORIGIN_TOKEN }}
|
||||
origin-ref: refs/heads/main
|
||||
destination-url: ${{ env.GITHUB_SERVER_URL }}
|
||||
destination-repo: user2/destinationrepo
|
||||
destination-branch: main
|
||||
destination-token: ${{ secrets.DESTINATION_TOKEN }}
|
||||
update: ./upgraded
|
||||
debug: true
|
1
tests/origin-branch/README
Normal file
1
tests/origin-branch/README
Normal file
|
@ -0,0 +1 @@
|
|||
originrepo
|
14
tests/origin-branch/upgraded
Executable file
14
tests/origin-branch/upgraded
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
destination_checkout="$1"
|
||||
destination_pr_json="$2"
|
||||
origin_checkout="$3"
|
||||
origin_ref="$4"
|
||||
|
||||
test -d $destination_checkout
|
||||
test -d $origin_checkout
|
||||
test "$origin_ref"
|
||||
|
||||
date +%s > $destination_checkout/last
|
73
tests/run.sh
73
tests/run.sh
|
@ -79,17 +79,35 @@ function merge_pull_request() {
|
|||
}
|
||||
|
||||
function has_cascade_pull_request() {
|
||||
log_verbose "verify a cascade pull request exists"
|
||||
test "$(cascade_pull_request_count)" -gt 0
|
||||
local repo="${1:-destinationrepo}"
|
||||
|
||||
log_verbose "verify an open cascade pull request exists"
|
||||
test "$(cascade_open_pull_request_count $repo)" -gt 0
|
||||
}
|
||||
|
||||
function has_no_cascade_pull_request() {
|
||||
log_verbose "verify there is no cascade pull request"
|
||||
test "$(cascade_pull_request_count)" = 0
|
||||
local repo="${1:-destinationrepo}"
|
||||
|
||||
log_verbose "verify there is no open cascade pull request"
|
||||
test "$(cascade_open_pull_request_count $repo)" = 0
|
||||
}
|
||||
|
||||
function cascade_open_pull_request_count() {
|
||||
local repo="$1"
|
||||
|
||||
cascade_pull_request $repo | jq '[ .[] | select(.state == "open") ] | length'
|
||||
}
|
||||
|
||||
function cascade_pull_request_count() {
|
||||
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user2/destinationrepo/pulls | jq '[ .[] | select(.state == "open") ] | length'
|
||||
local repo="$1"
|
||||
|
||||
cascade_pull_request $repo | jq '. | length'
|
||||
}
|
||||
|
||||
function cascade_pull_request() {
|
||||
local repo="$1"
|
||||
|
||||
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user2/${repo}/pulls
|
||||
}
|
||||
|
||||
function create_branch1() {
|
||||
|
@ -150,6 +168,13 @@ function create_pull_request_case1() {
|
|||
create_pull_request $baseowner $headowner $repo
|
||||
}
|
||||
|
||||
function unit_finalize_options() {
|
||||
sanity_check_pr_or_ref A B || test $? = 1
|
||||
sanity_check_pr_or_ref '' '' || test $? = 2
|
||||
sanity_check_pr_or_ref A ''
|
||||
sanity_check_pr_or_ref '' B
|
||||
}
|
||||
|
||||
function unit_retry_fail() {
|
||||
local file=$1
|
||||
local value=$(cat $file)
|
||||
|
@ -246,6 +271,34 @@ function no_change_no_cascade_pr() {
|
|||
has_no_cascade_pull_request
|
||||
}
|
||||
|
||||
function branch_and_success() {
|
||||
local origin_repo=origin-branch
|
||||
local destination_repo=destinationrepo
|
||||
|
||||
fixture ${origin_repo} ${destination_repo}
|
||||
user_secret user1 DESTINATION_TOKEN $(user_token user2 DESTINATION_TOKEN)
|
||||
|
||||
test $(cascade_pull_request_count ${destination_repo}) = 0
|
||||
create_branch1 user1 ${origin_repo}
|
||||
wait_success ${options[url]}/api/v1/repos/user1/${origin_repo} $(cat $TMPDIR/user1-${origin_repo}.sha)
|
||||
test $(cascade_pull_request_count ${destination_repo}) = 1
|
||||
has_no_cascade_pull_request ${destination_repo}
|
||||
}
|
||||
|
||||
function branch_and_fail() {
|
||||
local origin_repo=origin-branch-fail
|
||||
local destination_repo=destination-fail
|
||||
|
||||
fixture ${origin_repo} ${destination_repo}
|
||||
user_secret user1 DESTINATION_TOKEN $(user_token user2 DESTINATION_TOKEN)
|
||||
|
||||
test $(cascade_pull_request_count ${destination_repo}) = 0
|
||||
create_branch1 user1 ${origin_repo}
|
||||
wait_failure ${options[url]}/api/v1/repos/user1/${origin_repo} $(cat $TMPDIR/user1-${origin_repo}.sha)
|
||||
test $(cascade_pull_request_count ${destination_repo}) = 1
|
||||
has_no_cascade_pull_request ${destination_repo}
|
||||
}
|
||||
|
||||
function create_and_close() {
|
||||
fixture originrepo destinationrepo
|
||||
user_secret user1 DESTINATION_TOKEN $(user_token user2 DESTINATION_TOKEN)
|
||||
|
@ -367,6 +420,7 @@ function run() {
|
|||
}
|
||||
|
||||
function integration() {
|
||||
run branch_and_success
|
||||
run no_change_no_cascade_pr
|
||||
run create_in_destination_fork_and_close
|
||||
run create_and_close
|
||||
|
@ -379,6 +433,7 @@ function integration() {
|
|||
}
|
||||
|
||||
function unit() {
|
||||
unit_finalize_options
|
||||
unit_retry
|
||||
}
|
||||
|
||||
|
@ -388,12 +443,12 @@ function run_tests() {
|
|||
}
|
||||
|
||||
function finalize_options() {
|
||||
if test -f forgejo-ip; then
|
||||
: ${options[host_port]:=$(cat forgejo-ip):3000}
|
||||
if test -f $DIR/forgejo-ip; then
|
||||
: ${options[host_port]:=$(cat $DIR/forgejo-ip):3000}
|
||||
fi
|
||||
options[url]=http://${options[host_port]}
|
||||
if test -f forgejo-token; then
|
||||
: ${options[token]:=$(cat forgejo-token)}
|
||||
if test -f $DIR/forgejo-token; then
|
||||
: ${options[token]:=$(cat $DIR/forgejo-token)}
|
||||
fi
|
||||
options[password]=admin1234
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue