shfmt -w globally

This commit is contained in:
Earl Warren 2024-08-07 08:31:33 +02:00
parent 4e207414d4
commit d5f66e4c0a
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
27 changed files with 378 additions and 375 deletions

View file

@ -1,57 +1,57 @@
# Copyright 2024 The Forgejo Authors
# SPDX-License-Identifier: MIT
ACTIONS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ACTIONS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
function actions_verify_example() {
local example=$1
local example=$1
export HOST_PORT
export url=http://${FORGEJO_USER}:${FORGEJO_PASSWORD}@${HOST_PORT}
export token=$(cat $DOT_FORGEJO_CURL/token)
export HOST_PORT
export url=http://${FORGEJO_USER}:${FORGEJO_PASSWORD}@${HOST_PORT}
export token=$(cat $DOT_FORGEJO_CURL/token)
actions_cleanup_example_volume
actions_cleanup_example_volume
export example
export EXAMPLE_DIR=$ACTIONS_DIR/example-$example
export example
export EXAMPLE_DIR=$ACTIONS_DIR/example-$example
if test -f $EXAMPLE_DIR/setup.sh ; then
echo "============================ SETUP example-$example ==================="
bash -ex $EXAMPLE_DIR/setup.sh || return 1
fi
if test -f $EXAMPLE_DIR/setup.sh; then
echo "============================ SETUP example-$example ==================="
bash -ex $EXAMPLE_DIR/setup.sh || return 1
fi
if test -f $EXAMPLE_DIR/run.sh ; then
echo "============================ RUN example-$example ==================="
bash -ex $EXAMPLE_DIR/run.sh || return 1
else
forgejo-test-helper.sh run_workflow actions/example-$example $url root example-$example $example $token || return 1
fi
if test -f $EXAMPLE_DIR/run.sh; then
echo "============================ RUN example-$example ==================="
bash -ex $EXAMPLE_DIR/run.sh || return 1
else
forgejo-test-helper.sh run_workflow actions/example-$example $url root example-$example $example $token || return 1
fi
if test -f $EXAMPLE_DIR/teardown.sh ; then
echo "============================ TEARDOWN example-$example ==================="
bash -ex $EXAMPLE_DIR/teardown.sh || return 1
fi
if test -f $EXAMPLE_DIR/teardown.sh; then
echo "============================ TEARDOWN example-$example ==================="
bash -ex $EXAMPLE_DIR/teardown.sh || return 1
fi
actions_save_contexts $example
actions_save_contexts $example
}
function actions_save_contexts() {
local example="$1"
if test -d /srv/example/$example/contexts; then
mkdir -p /srv/contexts
rsync -av /srv/example/$example/contexts/ /srv/contexts/$example/
mkdir -p /srv/contexts
rsync -av /srv/example/$example/contexts/ /srv/contexts/$example/
fi
}
function actions_cleanup_example_volume() {
if test $(id -u) != 0 ; then
$SUDO chown $(id -u) /srv
if test $(id -u) != 0; then
$SUDO chown $(id -u) /srv
fi
if ! test -d /srv/example ; then
mkdir -p /srv/example
return
if ! test -d /srv/example; then
mkdir -p /srv/example
return
fi
$SUDO rm -fr /srv/example/*
@ -79,10 +79,10 @@ function actions_teardown() {
function actions_runner_version() {
local runner_version=$($DIR/forgejo-runner --version | sed -n -e 's/forgejo-runner version v//p')
if test -z "$runner_version" ; then
$DIR/forgejo-runner --version
echo failed to parse version
false
if test -z "$runner_version"; then
$DIR/forgejo-runner --version
echo failed to parse version
false
fi
echo $runner_version
}
@ -90,37 +90,37 @@ function actions_runner_version() {
function test_actions() {
local versions="${1:-1.21 $RELEASE_NUMBERS_AND_DEV}"
for version in $versions ; do
for version in $versions; do
actions_setup $version
local runner_version=$(actions_runner_version)
actions_setup $version
local runner_version=$(actions_runner_version)
log_info "Testing actions with Forgejo $version & Forgejo runner $runner_version"
log_info "Testing actions with Forgejo $version & Forgejo runner $runner_version"
if dpkg --compare-versions $version ge 7.0 && dpkg --compare-versions $runner_version gt 3.3.0 ; then
for example in artifacts-v4 ; do
run actions_verify_example $example
done
fi
for example in echo cache checkout service container expression local-action docker-action if if-fail push tag push-cancel artifacts pull-request context ; do
run actions_verify_example $example
done
if dpkg --compare-versions $version lt 7.1 ; then
for example in cron ; do
run actions_verify_example $example
done
fi
if dpkg --compare-versions $version ge 7.1 ; then
for example in automerge post-7-0-schedule ; do
if dpkg --compare-versions $version ge 7.0 && dpkg --compare-versions $runner_version gt 3.3.0; then
for example in artifacts-v4; do
run actions_verify_example $example
done
fi
if dpkg --compare-versions $version ge 8.0 ; then
for example in workflow-dispatch ; do
for example in echo cache checkout service container expression local-action docker-action if if-fail push tag push-cancel artifacts pull-request context; do
run actions_verify_example $example
done
if dpkg --compare-versions $version lt 7.1; then
for example in cron; do
run actions_verify_example $example
done
fi
if dpkg --compare-versions $version ge 7.1; then
for example in automerge post-7-0-schedule; do
run actions_verify_example $example
done
fi
if dpkg --compare-versions $version ge 8.0; then
for example in workflow-dispatch; do
run actions_verify_example $example
done
fi

View file

@ -22,7 +22,7 @@ function reset_automerge_pr() {
(
cd $d
rm -fr example-automerge
rm -fr example-automerge
git clone $url/$repo
cd example-automerge
git checkout -b other

View file

@ -7,7 +7,7 @@ forgejo-test-helper.sh push_workflow actions/example-$example $url root example-
# See https://codeberg.org/forgejo/forgejo/pulls/1941 for more information
#
function verify_ref() {
local ref=$(sqlite3 $DIR/forgejo-work-path/forgejo.db 'select ref from action_schedule')
local ref=$(sqlite3 $DIR/forgejo-work-path/forgejo.db 'select ref from action_schedule')
test "${ref##*/}" = "main"
}
verify_ref
@ -16,12 +16,12 @@ forgejo-curl.sh api_json --data '{"new_branch_name":"zzzz"}' $api/repos/root/exa
verify_ref
# cron runs once per minute, give it three minutes max before declaring failure
if ! RETRY_DELAYS="30 30 30 30 30 30" forgejo.sh retry test -f /srv/example/cron-volume/DONE ; then
if ! RETRY_DELAYS="30 30 30 30 30 30" forgejo.sh retry test -f /srv/example/cron-volume/DONE; then
cat $FORGEJO_RUNNER_LOGS
false
fi
c=/srv/example/cron/contexts/schedule/github
cat $c
test "schedule" = "$(jq -r .event_name < $c)"
test "schedule" = "$(jq -r .event.action < $c)"
test "schedule" = "$(jq -r .event_name <$c)"
test "schedule" = "$(jq -r .event.action <$c)"

View file

@ -10,7 +10,7 @@ forgejo-curl.sh web --form name=TEST_SCHEDULE_RUNSON --form data=docker http://$
# See https://codeberg.org/forgejo/forgejo/pulls/1941 for more information
#
function verify_ref() {
local ref=$(sqlite3 $DIR/forgejo-work-path/forgejo.db 'select ref from action_schedule')
local ref=$(sqlite3 $DIR/forgejo-work-path/forgejo.db 'select ref from action_schedule')
test "${ref##*/}" = "main"
}
verify_ref
@ -19,12 +19,12 @@ forgejo-curl.sh api_json --data '{"new_branch_name":"zzzz"}' $api/repos/root/exa
verify_ref
# runs once per minute, give it three minutes max before declaring failure
if ! RETRY_DELAYS="30 30 30 30 30 30" forgejo.sh retry test -f /srv/example/post-7-0-schedule-volume/DONE ; then
if ! RETRY_DELAYS="30 30 30 30 30 30" forgejo.sh retry test -f /srv/example/post-7-0-schedule-volume/DONE; then
cat $FORGEJO_RUNNER_LOGS
false
fi
c=/srv/example/post-7-0-schedule/contexts/schedule/github
cat $c
test "schedule" = "$(jq -r .event_name < $c)"
test "schedule" = "$(jq -r .event.action < $c)"
test "schedule" = "$(jq -r .event_name <$c)"
test "schedule" = "$(jq -r .event.action <$c)"

View file

@ -1 +1 @@
mkdir -p /srv/example/post-7-0-schedule-volume
mkdir -p /srv/example/post-7-0-schedule-volume

View file

@ -4,8 +4,8 @@ set -ex
c=$d/contexts
test opened = "$(jq -r .event.action < $c/fork-org/pull_request/github)"
test opened = "$(jq -r .event.action < $c/fork-org/pull_request_target/github)"
test opened = "$(jq -r .event.action <$c/fork-org/pull_request/github)"
test opened = "$(jq -r .event.action <$c/fork-org/pull_request_target/github)"
test opened = "$(jq -r .event.action < $c/root/pull_request/github)"
test opened = "$(jq -r .event.action < $c/root/pull_request_target/github)"
test opened = "$(jq -r .event.action <$c/root/pull_request/github)"
test opened = "$(jq -r .event.action <$c/root/pull_request_target/github)"

View file

@ -12,45 +12,44 @@ function main() {
forgejo-curl.sh api_json --data-raw '{"organization":"fork-org"}' $api/repos/root/example-pull-request/forks
forgejo-curl.sh api_json -X PUT --data-raw '{"data":"AAAA"}' $api/repos/root/example-pull-request/actions/secrets/SECRET
(
cd $d
git clone $url/fork-org/example-pull-request fork
cd fork
git config user.email root@example.com
git config user.name username
echo fork $PROOF >> README
touch file-unique-to-the-pr-branch
git add .
git commit -m 'fork change'
git push
cd $d
git clone $url/fork-org/example-pull-request fork
cd fork
git config user.email root@example.com
git config user.name username
echo fork $PROOF >>README
touch file-unique-to-the-pr-branch
git add .
git commit -m 'fork change'
git push
)
forgejo.sh retry forgejo-curl.sh api_json --data-raw '{"title":"PR from fork","base":"main","head":"fork-org:main"}' $api/repos/root/example-pull-request/pulls
(
cd $d
git clone $url/root/example-pull-request
cd example-pull-request
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
cd $d
git clone $url/root/example-pull-request
cd example-pull-request
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
)
forgejo.sh retry forgejo-curl.sh api_json --data-raw '{"title":"PR same repo","base":"main","head":"other"}' $api/repos/root/example-pull-request/pulls
export RETRY_DELAYS="60 60 60 60 60 60 60"
for assert in $EXAMPLE_DIR/assert-*.sh ; do
if ! forgejo.sh retry $assert ; then
find $d
sed -e 's/^/[RUNNER LOGS]/' < $FORGEJO_RUNNER_LOGS
false
fi
for assert in $EXAMPLE_DIR/assert-*.sh; do
if ! forgejo.sh retry $assert; then
find $d
sed -e 's/^/[RUNNER LOGS]/' <$FORGEJO_RUNNER_LOGS
false
fi
done
}

View file

@ -1,2 +1 @@
mkdir -p /srv/example/pull-request

View file

@ -11,7 +11,7 @@ forgejo-test-helper.sh wait_running $url $repo $sha
#
# push to the same branch
#
forgejo-test-helper.sh push_workflow actions/example-echo $url root example-$example setup-forgejo $token
forgejo-test-helper.sh push_workflow actions/example-echo $url root example-$example setup-forgejo $token
#
# wait for the workflow to be canceled as a result of the previous push
#

View file

@ -1,3 +1,3 @@
> /srv/example-service-volume-valid
> /srv/example-service-volume-invalid
>/srv/example-service-volume-valid
>/srv/example-service-volume-invalid
FORGEJO_RUNNER_CONFIG=$EXAMPLE_DIR/runner-config.yaml forgejo-runner.sh reload

View file

@ -10,7 +10,7 @@ api=$url/api/v1
repo=root/example-$example
function context_wait() {
if ! forgejo.sh retry test -f $context ; then
if ! forgejo.sh retry test -f $context; then
cat "$FORGEJO_RUNNER_LOGS"
false
fi
@ -19,7 +19,7 @@ function context_wait() {
function verify_required() {
local actual=$(forgejo-curl.sh api_json -w '%{http_code}' --data '{"ref":"main","inputs":{}}' $api/repos/$repo/actions/workflows/test.yml/dispatches)
local expected=400
if test "$actual" != $expected ; then
if test "$actual" != $expected; then
log_info "dispatch is expected to fail with status $expected because of string2 is a required value but got status $actual instead"
return 1
fi
@ -28,7 +28,7 @@ function verify_required() {
function verify_inputs() {
local inputs='{"string2":"value2"}'
forgejo-curl.sh api_json --data '{"ref":"main","inputs":'$inputs'}' $api/repos/$repo/actions/workflows/test.yml/dispatches
cat > $TMPDIR/expected <<'EOF'
cat >$TMPDIR/expected <<'EOF'
{
"boolean_default_false": "false",
"boolean_default_true": "true",
@ -46,7 +46,7 @@ function run_tests() {
npm --silent install json-diff
verify_inputs
context_wait
node_modules/.bin/json-diff <(jq .event.inputs < $context) $TMPDIR/expected
node_modules/.bin/json-diff <(jq .event.inputs <$context) $TMPDIR/expected
}
function main() {
@ -56,7 +56,7 @@ function main() {
run_tests
test "workflow_dispatch" = "$(jq -r .event_name < $context)"
test "workflow_dispatch" = "$(jq -r .event_name <$context)"
}
main