actions: add automerge example
This commit is contained in:
parent
c6cd39b074
commit
f9e20e7770
7 changed files with 202 additions and 2 deletions
|
@ -114,7 +114,7 @@ function test_actions() {
|
|||
fi
|
||||
|
||||
if dpkg --compare-versions $version ge 7.1 ; then
|
||||
for example in post-7-0-schedule ; do
|
||||
for example in automerge post-7-0-schedule ; do
|
||||
run actions_verify_example $example
|
||||
done
|
||||
fi
|
||||
|
|
13
actions/example-automerge/.forgejo/workflows/test.yml
Normal file
13
actions/example-automerge/.forgejo/workflows/test.yml
Normal file
|
@ -0,0 +1,13 @@
|
|||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: code.forgejo.org/oci/node:20-bookworm
|
||||
options: "--volume /srv/example:/srv/example"
|
||||
|
||||
steps:
|
||||
- run: |
|
||||
${{ vars.SCRIPT }}
|
69
actions/example-automerge/run.sh
Executable file
69
actions/example-automerge/run.sh
Executable file
|
@ -0,0 +1,69 @@
|
|||
TMPDIR=$(mktemp -d)
|
||||
|
||||
trap "rm -fr $TMPDIR" EXIT
|
||||
|
||||
source $EXAMPLE_DIR/../../lib/lib.sh
|
||||
|
||||
api=$url/api/v1
|
||||
export d=/srv/example/automerge
|
||||
|
||||
PROOF='some proof'
|
||||
|
||||
function main() {
|
||||
#
|
||||
# repository with a pull_request event workflow that always succeeds
|
||||
#
|
||||
mkdir -p $d
|
||||
|
||||
forgejo-test-helper.sh push_workflow actions/example-$example $url root example-$example setup-forgejo $token
|
||||
|
||||
local repo=root/example-automerge
|
||||
|
||||
forgejo-curl.sh api_json -X DELETE $api/repos/$repo/actions/variables/SCRIPT >&/dev/null || true
|
||||
forgejo-curl.sh api_json -X POST --data-raw '{"value":"true"}' $api/repos/$repo/actions/variables/SCRIPT
|
||||
|
||||
(
|
||||
cd $d
|
||||
git clone $url/$repo
|
||||
cd example-automerge
|
||||
git checkout -b other
|
||||
git config user.email root@example.com
|
||||
git config user.name username
|
||||
touch file-unique-to-the-pr-branch
|
||||
echo other $PROOF >>README
|
||||
git add .
|
||||
git commit -m 'other change'
|
||||
git push --force -u origin other
|
||||
)
|
||||
|
||||
#
|
||||
# make sure the runner won't race with the sequence that follows
|
||||
#
|
||||
forgejo-runner.sh teardown
|
||||
#
|
||||
# create a PR and schedule it for automerge when the workflow succeeds
|
||||
#
|
||||
api_pr_delete_all $api $repo
|
||||
forgejo-curl.sh api_json --data-raw '{"title":"PR title","base":"main","head":"other"}' $api/repos/$repo/pulls >$TMPDIR/pr.json
|
||||
local pr=$(jq -r .number <$TMPDIR/pr.json)
|
||||
forgejo-curl.sh api_json --data-raw '{"Do":"merge","merge_when_checks_succeed":true}' $api/repos/$repo/pulls/$pr/merge
|
||||
if api_pr_is_merged $api $repo $pr; then
|
||||
echo pull request already merged although it should not be
|
||||
return 1
|
||||
fi
|
||||
#
|
||||
# run the workflow
|
||||
#
|
||||
forgejo-runner.sh run
|
||||
local sha=$(api_branch_tip $api $repo other)
|
||||
api_pr_wait_success $api $repo $sha
|
||||
#
|
||||
# verify the PR was automerged
|
||||
#
|
||||
if ! retry api_pr_is_merged $api $repo $pr; then
|
||||
echo pull request is not automerged as expected
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
main
|
1
actions/example-automerge/setup.sh
Executable file
1
actions/example-automerge/setup.sh
Executable file
|
@ -0,0 +1 @@
|
|||
mkdir -p /srv/example/automerge
|
Loading…
Add table
Reference in a new issue