diff --git a/actions/actions.sh b/actions/actions.sh index d06027f..f467ba8 100755 --- a/actions/actions.sh +++ b/actions/actions.sh @@ -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 diff --git a/actions/example-automerge/run.sh b/actions/example-automerge/run.sh index 2134dc4..1d48860 100755 --- a/actions/example-automerge/run.sh +++ b/actions/example-automerge/run.sh @@ -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 diff --git a/actions/example-cron/run.sh b/actions/example-cron/run.sh index f95045f..bf19e98 100755 --- a/actions/example-cron/run.sh +++ b/actions/example-cron/run.sh @@ -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)" diff --git a/actions/example-post-7-0-schedule/run.sh b/actions/example-post-7-0-schedule/run.sh index e6e1309..29617c1 100755 --- a/actions/example-post-7-0-schedule/run.sh +++ b/actions/example-post-7-0-schedule/run.sh @@ -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)" \ No newline at end of file +test "schedule" = "$(jq -r .event_name <$c)" +test "schedule" = "$(jq -r .event.action <$c)" diff --git a/actions/example-post-7-0-schedule/setup.sh b/actions/example-post-7-0-schedule/setup.sh index 9e17073..5592dbe 100755 --- a/actions/example-post-7-0-schedule/setup.sh +++ b/actions/example-post-7-0-schedule/setup.sh @@ -1 +1 @@ -mkdir -p /srv/example/post-7-0-schedule-volume \ No newline at end of file +mkdir -p /srv/example/post-7-0-schedule-volume diff --git a/actions/example-pull-request/assert-contexts.sh b/actions/example-pull-request/assert-contexts.sh index 57f0257..83cd660 100755 --- a/actions/example-pull-request/assert-contexts.sh +++ b/actions/example-pull-request/assert-contexts.sh @@ -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)" diff --git a/actions/example-pull-request/run.sh b/actions/example-pull-request/run.sh index a262e6f..de54e37 100755 --- a/actions/example-pull-request/run.sh +++ b/actions/example-pull-request/run.sh @@ -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 } diff --git a/actions/example-pull-request/setup.sh b/actions/example-pull-request/setup.sh index 72c13c0..5f46962 100755 --- a/actions/example-pull-request/setup.sh +++ b/actions/example-pull-request/setup.sh @@ -1,2 +1 @@ mkdir -p /srv/example/pull-request - diff --git a/actions/example-push-cancel/run.sh b/actions/example-push-cancel/run.sh index d6705d8..891798e 100755 --- a/actions/example-push-cancel/run.sh +++ b/actions/example-push-cancel/run.sh @@ -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 # diff --git a/actions/example-service/setup.sh b/actions/example-service/setup.sh index 3a9674e..7bc1672 100755 --- a/actions/example-service/setup.sh +++ b/actions/example-service/setup.sh @@ -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 diff --git a/actions/example-workflow-dispatch/run.sh b/actions/example-workflow-dispatch/run.sh index ed55070..8a49365 100755 --- a/actions/example-workflow-dispatch/run.sh +++ b/actions/example-workflow-dispatch/run.sh @@ -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 diff --git a/end-to-end.sh b/end-to-end.sh index ab9454b..05865ac 100755 --- a/end-to-end.sh +++ b/end-to-end.sh @@ -11,7 +11,7 @@ # Everything happens in /tmp/forgejo-end-to-end # -SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SELF="${BASH_SOURCE[0]}" source $SELF_DIR/lib/lib.sh diff --git a/federation/federation.sh b/federation/federation.sh index 7fbb215..f0acfcf 100755 --- a/federation/federation.sh +++ b/federation/federation.sh @@ -1,46 +1,46 @@ # Copyright 2024 The Forgejo Authors # SPDX-License-Identifier: MIT -FEDERATION_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +FEDERATION_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" export FEDERATION_INSTANCES="ONE TWO" export FEDERATION_CONFIGS function federation_setup_variables() { - if test "$FEDERATION_CONFIGS" ; then - return + if test "$FEDERATION_CONFIGS"; then + return fi - for instance in $FEDERATION_INSTANCES ; do - local config=$FEDERATION_DIR/$instance-app.ini - FEDERATION_CONFIGS="$FEDERATION_CONFIGS $config" - local base=$(work_path_base $config) - local work_path=$DIR/$base - local host_port=$(get_host_port $config) + for instance in $FEDERATION_INSTANCES; do + local config=$FEDERATION_DIR/$instance-app.ini + FEDERATION_CONFIGS="$FEDERATION_CONFIGS $config" + local base=$(work_path_base $config) + local work_path=$DIR/$base + local host_port=$(get_host_port $config) - eval export ${instance}_CONFIG=$config - eval export ${instance}_CURL=$work_path/forgejo-curl.sh - eval export ${instance}_HOST_PORT=$host_port + eval export ${instance}_CONFIG=$config + eval export ${instance}_CURL=$work_path/forgejo-curl.sh + eval export ${instance}_HOST_PORT=$host_port done } function federation_verify_scenario() { - local scenario=$1 + local scenario=$1 - export scenario - export SCENARIO_DIR=$FEDERATION_DIR/scenario-$scenario + export scenario + export SCENARIO_DIR=$FEDERATION_DIR/scenario-$scenario - if test -f $SCENARIO_DIR/setup.sh ; then - echo "============================ SETUP scenario-$scenario ===================" - bash -ex $SCENARIO_DIR/setup.sh || return 1 - fi + if test -f $SCENARIO_DIR/setup.sh; then + echo "============================ SETUP scenario-$scenario ===================" + bash -ex $SCENARIO_DIR/setup.sh || return 1 + fi - echo "============================ RUN scenario-$scenario ===================" - bash -ex $SCENARIO_DIR/run.sh || return 1 + echo "============================ RUN scenario-$scenario ===================" + bash -ex $SCENARIO_DIR/run.sh || return 1 - if test -f $SCENARIO_DIR/teardown.sh ; then - echo "============================ TEARDOWN scenario-$scenario ===================" - bash -ex $SCENARIO_DIR/teardown.sh || return 1 - fi + if test -f $SCENARIO_DIR/teardown.sh; then + echo "============================ TEARDOWN scenario-$scenario ===================" + bash -ex $SCENARIO_DIR/teardown.sh || return 1 + fi } function federation_setup() { @@ -50,9 +50,9 @@ function federation_setup() { federation_teardown local config - for config in $FEDERATION_CONFIGS ; do - reset_forgejo $config - start_forgejo $version $config + for config in $FEDERATION_CONFIGS; do + reset_forgejo $config + start_forgejo $version $config done } @@ -60,8 +60,8 @@ function federation_teardown() { federation_setup_variables local config - for config in $FEDERATION_CONFIGS ; do - stop_forgejo $config + for config in $FEDERATION_CONFIGS; do + stop_forgejo $config done } @@ -71,16 +71,16 @@ function test_federation() { local versions="${1:-$RELEASE_NUMBERS_AND_DEV}" - for version in $versions ; do + for version in $versions; do - if dpkg --compare-versions $version lt 7.1 ; then - continue - fi + if dpkg --compare-versions $version lt 7.1; then + continue + fi - federation_setup $version + federation_setup $version - for scenario in star ; do - run federation_verify_scenario $scenario - done + for scenario in star; do + run federation_verify_scenario $scenario + done done } diff --git a/federation/scenario-star/run.sh b/federation/scenario-star/run.sh index 15db8e2..ad340d2 100644 --- a/federation/scenario-star/run.sh +++ b/federation/scenario-star/run.sh @@ -9,20 +9,20 @@ function star_count() { local host_port=$2 local count=$3 - $curl api_json http://$host_port/api/v1/repos/root/test > $TMPDIR/count.json - if test $count != $(jq -r .stars_count < $TMPDIR/count.json) ; then - jq . < $TMPDIR/count.json - return 1 + $curl api_json http://$host_port/api/v1/repos/root/test >$TMPDIR/count.json + if test $count != $(jq -r .stars_count <$TMPDIR/count.json); then + jq . <$TMPDIR/count.json + return 1 fi } # # create a repo on each instance # -$ONE_CURL api_json --data '{"name":"test","auto_init":true}' $ONE_HOST_PORT/api/v1/user/repos > $TMPDIR/one-repo.json -one_repo_id=$(jq -r .id < $TMPDIR/one-repo.json) -$TWO_CURL api_json --data '{"name":"test","auto_init":true}' $TWO_HOST_PORT/api/v1/user/repos > $TMPDIR/two-repo.json -two_repo_id=$(jq -r .id < $TMPDIR/two-repo.json) +$ONE_CURL api_json --data '{"name":"test","auto_init":true}' $ONE_HOST_PORT/api/v1/user/repos >$TMPDIR/one-repo.json +one_repo_id=$(jq -r .id <$TMPDIR/one-repo.json) +$TWO_CURL api_json --data '{"name":"test","auto_init":true}' $TWO_HOST_PORT/api/v1/user/repos >$TMPDIR/two-repo.json +two_repo_id=$(jq -r .id <$TMPDIR/two-repo.json) # # the repo in instance two is federated with the repo in instance one diff --git a/federation/scenario-star/setup.sh b/federation/scenario-star/setup.sh index e69de29..8b13789 100644 --- a/federation/scenario-star/setup.sh +++ b/federation/scenario-star/setup.sh @@ -0,0 +1 @@ + diff --git a/federation/scenario-star/teardown.sh b/federation/scenario-star/teardown.sh index e69de29..8b13789 100644 --- a/federation/scenario-star/teardown.sh +++ b/federation/scenario-star/teardown.sh @@ -0,0 +1 @@ + diff --git a/forgejo/fixtures.sh b/forgejo/fixtures.sh index 9e7f5ca..b49abf5 100644 --- a/forgejo/fixtures.sh +++ b/forgejo/fixtures.sh @@ -1,6 +1,6 @@ # SPDX-License-Identifier: MIT -FIXTURES_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +FIXTURES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source $FIXTURES_DIR/fixtures/storage.sh source $FIXTURES_DIR/fixtures/doctor.sh diff --git a/forgejo/fixtures/storage.sh b/forgejo/fixtures/storage.sh index 0de79b5..cf893b8 100644 --- a/forgejo/fixtures/storage.sh +++ b/forgejo/fixtures/storage.sh @@ -15,7 +15,7 @@ function fixture_get_paths_s3() { ( mc ls --quiet --recursive testS3/$path | sed -e "s|.* |$path/|" - ) > $DIR/path + ) >$DIR/path } function fixture_content_search_s3() { @@ -23,15 +23,15 @@ function fixture_content_search_s3() { local expected="$2" fixture_get_paths_s3 $path - if test $(wc -l < $DIR/path) -lt 1 ; then - echo expected at least one but got "'$(cat $DIR/path)'" - return 1 + if test $(wc -l <$DIR/path) -lt 1; then + echo expected at least one but got "'$(cat $DIR/path)'" + return 1 fi - for filename in $(cat $DIR/path) ; do - local content=$(mc cat testS3/$filename | base64 -w0) - if test "$content" = "$expected" ; then - return 0 - fi + for filename in $(cat $DIR/path); do + local content=$(mc cat testS3/$filename | base64 -w0) + if test "$content" = "$expected"; then + return 0 + fi done echo nothing in $path found with the expected content "$expected" return 1 @@ -41,7 +41,10 @@ function fixture_get_paths_local() { local path=$1 local work_path=$DIR/forgejo-work-path - ( cd $work_path ; find $path -type f) > $DIR/path + ( + cd $work_path + find $path -type f + ) >$DIR/path } function fixture_get_one_path() { @@ -50,7 +53,7 @@ function fixture_get_one_path() { fixture_get_paths_$storage $path - if test $(wc -l < $DIR/path) != 1 ; then + if test $(wc -l <$DIR/path) != 1; then echo expected one path but got cat $DIR/path return 1 @@ -77,7 +80,7 @@ function fixture_lfs_create() { ( cd $DIR/fixture git lfs track "*.txt" - echo CONTENT > file.txt + echo CONTENT >file.txt git add . git commit -m 'lfs files' git push @@ -87,11 +90,11 @@ function fixture_lfs_create() { function fixture_lfs_assert() { local d=$(mktemp -d) ( - git clone http://${FORGEJO_USER}:${FORGEJO_PASSWORD}@${HOST_PORT}/${FORGEJO_USER}/${FORGEJO_REPO} $d/${FORGEJO_REPO} - cd $d/${FORGEJO_REPO} - rm file.txt + git clone http://${FORGEJO_USER}:${FORGEJO_PASSWORD}@${HOST_PORT}/${FORGEJO_USER}/${FORGEJO_REPO} $d/${FORGEJO_REPO} + cd $d/${FORGEJO_REPO} + rm file.txt git-lfs checkout file.txt - test -f file.txt + test -f file.txt ) rm -fr $d } @@ -110,7 +113,7 @@ function fixture_lfs_assert_local() { } function fixture_packages_create() { - echo PACKAGE_CONTENT > $DIR/fixture/package + echo PACKAGE_CONTENT >$DIR/fixture/package forgejo-curl.sh api_json -X DELETE http://${HOST_PORT}/api/packages/${FORGEJO_USER}/generic/test_package/1.0.0/file.txt || true forgejo-curl.sh api_json --upload-file $DIR/fixture/package http://${HOST_PORT}/api/packages/${FORGEJO_USER}/generic/test_package/1.0.0/file.txt } @@ -128,7 +131,7 @@ function fixture_packages_assert_local() { } function fixture_avatars_create() { - echo -n $ONEPIXEL | base64 --decode > $DIR/avatar.png + echo -n $ONEPIXEL | base64 --decode >$DIR/avatar.png forgejo-curl.sh web --form avatar=@$DIR/avatar.png http://${HOST_PORT}/user/settings/avatar } @@ -145,7 +148,7 @@ function fixture_avatars_assert_local() { } function fixture_repo_avatars_create() { - echo -n $ONEPIXEL | base64 --decode > $DIR/repo-avatar.png + echo -n $ONEPIXEL | base64 --decode >$DIR/repo-avatar.png forgejo-curl.sh web --form avatar=@$DIR/repo-avatar.png http://${HOST_PORT}/${FORGEJO_USER}/${FORGEJO_REPO}/settings/avatar # v1.21 only #forgejo-curl.sh api_json -X POST --data-raw '{"body":"'$avatar'"}' http://${HOST_PORT}/api/v1/repos/${FORGEJO_USER}/${FORGEJO_REPO}/avatar @@ -166,17 +169,17 @@ function fixture_repo_avatars_assert_local() { } function fixture_attachments_create_1_18() { - echo -n $ONEPIXEL | base64 --decode > $DIR/attachment.png + echo -n $ONEPIXEL | base64 --decode >$DIR/attachment.png forgejo-curl.sh web --trace-ascii - --form file=@$DIR/attachment.png http://${HOST_PORT}/${FORGEJO_USER}/${FORGEJO_REPO}/issues/attachments } function fixture_attachments_create() { - if forgejo-curl.sh api_json http://${HOST_PORT}/api/v1/version | grep --quiet --fixed-strings 1.18. ; then + if forgejo-curl.sh api_json http://${HOST_PORT}/api/v1/version | grep --quiet --fixed-strings 1.18.; then fixture_attachments_create_1_18 return fi id=$(forgejo-curl.sh api_json --data-raw '{"title":"TITLE"}' http://${HOST_PORT}/api/v1/repos/${FORGEJO_USER}/${FORGEJO_REPO}/issues | jq .id) - echo -n $ONEPIXEL | base64 --decode > $DIR/attachment.png + echo -n $ONEPIXEL | base64 --decode >$DIR/attachment.png forgejo-curl.sh api --form name=attachment.png --form attachment=@$DIR/attachment.png http://${HOST_PORT}/api/v1/repos/${FORGEJO_USER}/${FORGEJO_REPO}/issues/$id/assets } @@ -206,18 +209,18 @@ function fixture_create() { git remote add origin http://${FORGEJO_USER}:${FORGEJO_PASSWORD}@${HOST_PORT}/${FORGEJO_USER}/${FORGEJO_REPO} git config user.email root@example.com git config user.name username - echo SOMETHING > README + echo SOMETHING >README git add README git commit -m 'initial commit' git push --set-upstream --force origin main ) - for fun in ${STORAGE_FUN} ; do + for fun in ${STORAGE_FUN}; do fixture_${fun}_create done } function fixture_assert() { - for fun in lfs ; do + for fun in lfs; do fixture_${fun}_assert done } diff --git a/lib/api.sh b/lib/api.sh index 03db36c..cc56f50 100644 --- a/lib/api.sh +++ b/lib/api.sh @@ -14,16 +14,16 @@ function api_user_make_admin() { function api_user_create() { local api="$1" username="$2" email="$3" log_info "(re)create user $username" - forgejo-curl.sh api_json -X DELETE $api/admin/users/$username?purge=true >& /dev/null || true + forgejo-curl.sh api_json -X DELETE $api/admin/users/$username?purge=true >&/dev/null || true forgejo-curl.sh api_json --data '{"username":"'$username'","email":"'$email'","password":"admin1234","must_change_password":false}' $api/admin/users } function user_login() { local username=$1 ( - export DOT=$API_TMPDIR/$username - forgejo-curl.sh logout - forgejo-curl.sh --user $username --password "admin1234" login http://${HOST_PORT} + export DOT=$API_TMPDIR/$username + forgejo-curl.sh logout + forgejo-curl.sh --user $username --password "admin1234" login http://${HOST_PORT} ) } diff --git a/lib/build.sh b/lib/build.sh index 11bdf3a..bbef73e 100755 --- a/lib/build.sh +++ b/lib/build.sh @@ -4,16 +4,16 @@ set -ex -SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" version=$1 dir_binaries=$2 v=$(echo $version | sed -E -e 's/^([0-9]+\.[0-9]+).*/\1/') src=$dir_binaries/src-$v -read url ref semver < $SELF_DIR/../forgejo/sources/$v +read url ref semver <$SELF_DIR/../forgejo/sources/$v -if ! test -d $src ; then +if ! test -d $src; then mkdir -p $src cd $src git init @@ -22,15 +22,15 @@ else cd $src fi -if ! [[ "$ref" =~ ^refs/ ]] ; then +if ! [[ "$ref" =~ ^refs/ ]]; then ref=refs/heads/$ref fi -for retry in 1 2 3 ; do - if timeout 15m git fetch --update-head-ok origin +$ref:$ref ; then - break +for retry in 1 2 3; do + if timeout 15m git fetch --update-head-ok origin +$ref:$ref; then + break else - echo "Retry git fetch in 60 seconds" - sleep 60 + echo "Retry git fetch in 60 seconds" + sleep 60 fi done git fetch --update-head-ok origin +$ref:$ref diff --git a/lib/lib.sh b/lib/lib.sh index 7448536..295c0eb 100644 --- a/lib/lib.sh +++ b/lib/lib.sh @@ -2,11 +2,11 @@ # Copyright 2024 The Forgejo Authors # SPDX-License-Identifier: MIT -LIB_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source $LIB_DIR/api.sh -if ${VERBOSE:-false} ; then +if ${VERBOSE:-false}; then set -ex PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: ' else @@ -17,8 +17,8 @@ set -o pipefail export DEBIAN_FRONTEND=noninteractive -if test $(id -u) != 0 ; then - SUDO=sudo +if test $(id -u) != 0; then + SUDO=sudo fi IP=$(hostname -I | cut -f1 -d' ') @@ -35,7 +35,7 @@ export DOT_FORGEJO_CURL=$DIR/forgejo-curl export DOT=$DOT_FORGEJO_CURL # for backward compatibility with forgejo-curl.sh 1.0.0 : ${FORGEJO_USER:=root} : ${FORGEJO_PASSWORD:=admin1234} -: ${RELEASE_NUMBERS_AND_DEV:="$(for r in $RELEASE_NUMBERS ; do echo -n "$r $r-dev " ; done)"} +: ${RELEASE_NUMBERS_AND_DEV:="$(for r in $RELEASE_NUMBERS; do echo -n "$r $r-dev "; done)"} ORGANIZATIONS=$(cat $LIB_DIR/ORGANIZATIONS) function log_info() { @@ -44,50 +44,50 @@ function log_info() { function dependencies() { - if ! test -f /usr/local/bin/forgejo-curl.sh ; then - $SUDO curl --fail -sS https://code.forgejo.org/forgejo/forgejo-curl/raw/branch/main/forgejo-curl.sh -o /usr/local/bin/forgejo-curl.sh - $SUDO chmod +x /usr/local/bin/forgejo-curl.sh + if ! test -f /usr/local/bin/forgejo-curl.sh; then + $SUDO curl --fail -sS https://code.forgejo.org/forgejo/forgejo-curl/raw/branch/main/forgejo-curl.sh -o /usr/local/bin/forgejo-curl.sh + $SUDO chmod +x /usr/local/bin/forgejo-curl.sh fi - if ! which make curl daemon git-lfs jq sqlite3 skopeo > /dev/null ; then + if ! which make curl daemon git-lfs jq sqlite3 skopeo >/dev/null; then $SUDO apt-get update -qq $SUDO apt-get install -y -qq make curl daemon git-lfs jq sqlite3 skopeo fi - if ! test -f /usr/local/bin/mc || ! test -f /usr/local/bin/minio ; then + if ! test -f /usr/local/bin/mc || ! test -f /usr/local/bin/minio; then $SUDO curl --fail -sS https://dl.min.io/client/mc/release/linux-amd64/mc -o /usr/local/bin/mc $SUDO curl --fail -sS https://dl.min.io/server/minio/release/linux-amd64/minio -o /usr/local/bin/minio fi - if ! test -x /usr/local/bin/mc || ! test -x /usr/local/bin/minio ; then + if ! test -x /usr/local/bin/mc || ! test -x /usr/local/bin/minio; then $SUDO chmod +x /usr/local/bin/mc $SUDO chmod +x /usr/local/bin/minio fi - if ! test -f /usr/local/bin/garage > /dev/null ; then + if ! test -f /usr/local/bin/garage >/dev/null; then $SUDO curl --fail -sS https://garagehq.deuxfleurs.fr/_releases/v0.8.2/x86_64-unknown-linux-musl/garage -o /usr/local/bin/garage fi - if ! test -x /usr/local/bin/garage > /dev/null ; then + if ! test -x /usr/local/bin/garage >/dev/null; then $SUDO chmod +x /usr/local/bin/garage fi } function build_all() { - for dev in $RELEASE_NUMBERS ; do - local forgejo=$DIR_BINARIES/forgejo-$dev-dev - if test -f $forgejo ; then - log_info $dev already exists - else - $LIB_DIR/build.sh $dev $DIR_BINARIES - log_info $dev built from sources - fi + for dev in $RELEASE_NUMBERS; do + local forgejo=$DIR_BINARIES/forgejo-$dev-dev + if test -f $forgejo; then + log_info $dev already exists + else + $LIB_DIR/build.sh $dev $DIR_BINARIES + log_info $dev built from sources + fi done } function retry() { rm -f $DIR/wait-for.out success=false - for delay in 1 1 5 5 15 ; do - if "$@" >> $DIR/wait-for.out 2>&1 ; then + for delay in 1 1 5 5 15; do + if "$@" >>$DIR/wait-for.out 2>&1; then success=true break fi @@ -95,7 +95,7 @@ function retry() { echo waiting $delay sleep $delay done - if test $success = false ; then + if test $success = false; then cat $DIR/wait-for.out return 1 fi @@ -105,36 +105,36 @@ function full_version() { local version=$1 local owner=$2 - if [[ $version =~ ^[0-9]+\.[0-9]+$ ]] ; then - full_version=$(curl -sS "https://codeberg.org/api/v1/repos/$owner/forgejo/releases?limit=50" | jq -r '.[] | .tag_name | select(startswith("v'$version'"))' | sort --reverse --version-sort | head -1) - echo ${full_version#v} + if [[ $version =~ ^[0-9]+\.[0-9]+$ ]]; then + full_version=$(curl -sS "https://codeberg.org/api/v1/repos/$owner/forgejo/releases?limit=50" | jq -r '.[] | .tag_name | select(startswith("v'$version'"))' | sort --reverse --version-sort | head -1) + echo ${full_version#v} else - echo $version + echo $version fi } function download_forgejo() { local version=$1 - if ! test -f $DIR_BINARIES/forgejo-$version ; then + if ! test -f $DIR_BINARIES/forgejo-$version; then mkdir -p $DIR_BINARIES - for owner in $ORGANIZATIONS ; do - full_version=$(full_version $version $owner) - if test "$full_version" = "" ; then - continue - fi - if wget -O $DIR_BINARIES/forgejo-$version --quiet https://codeberg.org/$owner/forgejo/releases/download/v$full_version/forgejo-$full_version-linux-amd64 ; then - break - fi - done - if test -s $DIR_BINARIES/forgejo-$version ; then - if test "$version" != "$full_version" ; then - log_info "downloaded Forgejo $full_version for $version" - fi - else - echo unable to download Forgejo $version - return 1 - fi + for owner in $ORGANIZATIONS; do + full_version=$(full_version $version $owner) + if test "$full_version" = ""; then + continue + fi + if wget -O $DIR_BINARIES/forgejo-$version --quiet https://codeberg.org/$owner/forgejo/releases/download/v$full_version/forgejo-$full_version-linux-amd64; then + break + fi + done + if test -s $DIR_BINARIES/forgejo-$version; then + if test "$version" != "$full_version"; then + log_info "downloaded Forgejo $full_version for $version" + fi + else + echo unable to download Forgejo $version + return 1 + fi chmod +x $DIR_BINARIES/forgejo-$version fi } @@ -142,9 +142,9 @@ function download_forgejo() { function download_gitea() { local version=$1 - if ! test -f $DIR_BINARIES/gitea-$version ; then + if ! test -f $DIR_BINARIES/gitea-$version; then mkdir -p $DIR_BINARIES - if [[ $version =~ ^[0-9]+\.[0-9]+$ ]] ; then + if [[ $version =~ ^[0-9]+\.[0-9]+$ ]]; then full_version=$(curl -sS "https://api.github.com/repos/go-gitea/gitea/releases?per_page=100" | jq -r '.[] | .tag_name | select(startswith("v'$version'"))' | grep -v -e '-rc' | sort --reverse --version-sort | head -1) full_version=${full_version#v} else @@ -152,8 +152,8 @@ function download_gitea() { fi wget -O $DIR_BINARIES/gitea-$version --quiet https://dl.gitea.com/gitea/$full_version/gitea-$full_version-linux-amd64 - if test -s $DIR_BINARIES/gitea-$version ; then - if test "$version" != "$full_version" ; then + if test -s $DIR_BINARIES/gitea-$version; then + if test "$version" != "$full_version"; then log_info "downloaded Gitea $full_version for $version" fi else @@ -185,18 +185,18 @@ function clobber() { function start_gitlab_cache_load() { local image=$1 local d=$DIR_BINARIES/gitlab - if test -d $d ; then - log_info "loading $image from $d" - skopeo copy dir:$d docker-daemon:$image + if test -d $d; then + log_info "loading $image from $d" + skopeo copy dir:$d docker-daemon:$image fi } function start_gitlab_cache_save() { local image=$1 local d=$DIR_BINARIES/gitlab - if ! test -d $d ; then - log_info "saving $image to $d" - skopeo copy docker-daemon:$image dir:$d + if ! test -d $d; then + log_info "saving $image to $d" + skopeo copy docker-daemon:$image dir:$d fi } @@ -208,21 +208,21 @@ function start_gitlab() { local GITLAB_OMNIBUS_CONFIG="nginx['listen_https'] = false ; nginx['listen_port'] = 8181 ; external_url 'http://$IP:$GITLAB_PORT'; gitlab_rails['gitlab_shell_ssh_port'] = 2221; $config" docker run --name="test-gitlab" --shm-size=128M -d \ - -e GITLAB_OMNIBUS_CONFIG="$GITLAB_OMNIBUS_CONFIG" \ - -p 2221:22 -p $GITLAB_PORT:8181 \ - $image >& /dev/null < /dev/null + -e GITLAB_OMNIBUS_CONFIG="$GITLAB_OMNIBUS_CONFIG" \ + -p 2221:22 -p $GITLAB_PORT:8181 \ + $image >&/dev/null /dev/null + grep '' $work_path/log/*.log 2>/dev/null return 1 fi - echo "$binary --config $work_path/app.ini --work-path $work_path" '"$@"' > $work_path/forgejocli + echo "$binary --config $work_path/app.ini --work-path $work_path" '"$@"' >$work_path/forgejocli chmod +x $work_path/forgejocli cp -a $work_path/forgejocli $DIR/forgejocli # because setup-forgejo/forgejo-runner.sh expects it here create_user_and_login $version $config @@ -277,18 +277,18 @@ function start_forgejo_daemon() { function start_minio() { mkdir -p $DIR/minio daemon --chdir=$DIR --unsafe \ - --env="PATH=$PATH" \ - --env=MINIO_ROOT_USER=123456 \ - --env=MINIO_ROOT_PASSWORD=12345678 \ - --env=MINIO_VOLUMES=$DIR/minio \ - --pidfile=$DIR/minio-pid --errlog=$DIR/minio-err.log --output=$DIR/minio-out.log -- /usr/local/bin/minio server - retry mc alias set testS3 http://127.0.0.1:9000 123456 12345678 >& /dev/null + --env="PATH=$PATH" \ + --env=MINIO_ROOT_USER=123456 \ + --env=MINIO_ROOT_PASSWORD=12345678 \ + --env=MINIO_VOLUMES=$DIR/minio \ + --pidfile=$DIR/minio-pid --errlog=$DIR/minio-err.log --output=$DIR/minio-out.log -- /usr/local/bin/minio server + retry mc alias set testS3 http://127.0.0.1:9000 123456 12345678 >&/dev/null mc alias set testS3 http://127.0.0.1:9000 123456 12345678 } function start_garage() { mkdir -p $DIR/garage/{data,meta} - cat > $DIR/garage/garage.toml <$DIR/garage/garage.toml < $work_path/app.ini + -e "s|\${WORK_PATH}|$work_path|g" \ + -e "s|^WORK_PATH = .*|WORK_PATH = $work_path|" \ + <$config >$work_path/app.ini } function reset_minio() { @@ -391,19 +391,19 @@ function create_user_and_login() { local work_path=$DIR/$(work_path_base $config) local email="$FORGEJO_USER@example.com" - if ! $work_path/forgejocli admin user list | grep --quiet "$email" ; then - $work_path/forgejocli admin user create --admin --username "$FORGEJO_USER" --password "$FORGEJO_PASSWORD" --email $email + if ! $work_path/forgejocli admin user list | grep --quiet "$email"; then + $work_path/forgejocli admin user create --admin --username "$FORGEJO_USER" --password "$FORGEJO_PASSWORD" --email $email fi forgejo-curl.sh logout local scopes='--scopes ["all"]' - if echo $version | grep --quiet 1.18 ; then + if echo $version | grep --quiet 1.18; then scopes="" fi forgejo-curl.sh --user "$FORGEJO_USER" --password "$FORGEJO_PASSWORD" $scopes login http://$(get_host_port $config) local forgejo_curl=$work_path/forgejo-curl.sh - cat > $forgejo_curl <$forgejo_curl < $DIR/$fun.out + >$DIR/$fun.out tail --follow $DIR/$fun.out |& sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" & local pid=$! - if ! VERBOSE=true $SELF $fun "$@" >& $DIR/$fun.out ; then + if ! VERBOSE=true $SELF $fun "$@" >&$DIR/$fun.out; then kill $pid cat $DIR/$fun.out echo Failure running $fun diff --git a/packages/alpine-1.21/test.sh b/packages/alpine-1.21/test.sh index e210879..93a3aba 100755 --- a/packages/alpine-1.21/test.sh +++ b/packages/alpine-1.21/test.sh @@ -33,20 +33,20 @@ sudo -u user APKBUILD=alpine/APKBUILD abuild -r # upload new package cd packages/srv/x86_64/ for file in $(find . -name '*.apk' -type f | sed -e 's,./,,'); do - # remove old package - curl \ - --fail \ - -H "Authorization: token $forgejo_token" \ - -X DELETE \ - "$forgejo_url/api/packages/root/alpine/3.19/forgejo-2174/$file" \ - || true + # remove old package + curl \ + --fail \ + -H "Authorization: token $forgejo_token" \ + -X DELETE \ + "$forgejo_url/api/packages/root/alpine/3.19/forgejo-2174/$file" || + true - # upload new package - curl \ - --fail \ - -H "Authorization: token $forgejo_token" \ - -T "$file" \ - "$forgejo_url/api/packages/root/alpine/3.19/forgejo-2174" + # upload new package + curl \ + --fail \ + -H "Authorization: token $forgejo_token" \ + -T "$file" \ + "$forgejo_url/api/packages/root/alpine/3.19/forgejo-2174" done # ensure that the install-if condition works as expected @@ -54,5 +54,5 @@ apk add openrc (cd /etc/apk/keys && curl -JO $forgejo_url/api/packages/root/alpine/key) echo "$forgejo_url/api/packages/root/alpine/3.19/forgejo-2174" >>/etc/apk/repositories apk add forgejo-2174 -[ -e /usr/bin/forgejo_2174 ] # from the installed package +[ -e /usr/bin/forgejo_2174 ] # from the installed package [ -e /etc/init.d/forgejo_2174 ] # from the -openrc package installed because of the install-if condition diff --git a/packages/alpine-7.0-test/test.sh b/packages/alpine-7.0-test/test.sh index 45bb60e..82565d0 100755 --- a/packages/alpine-7.0-test/test.sh +++ b/packages/alpine-7.0-test/test.sh @@ -36,20 +36,20 @@ sudo -u user APKBUILD=alpine/forgejo-2173/APKBUILD abuild -r # upload new package cd packages/alpine/x86_64/ for file in $(find . -name '*.apk' -type f | sed -e 's,./,,'); do - # remove old package - curl \ - --fail \ - -H "Authorization: token $forgejo_token" \ - -X DELETE \ - "$forgejo_url/api/packages/root/alpine/3.19/e2e-tests/$file" \ - || true + # remove old package + curl \ + --fail \ + -H "Authorization: token $forgejo_token" \ + -X DELETE \ + "$forgejo_url/api/packages/root/alpine/3.19/e2e-tests/$file" || + true - # upload new package - curl \ - --fail \ - -H "Authorization: token $forgejo_token" \ - -T "$file" \ - "$forgejo_url/api/packages/root/alpine/3.19/e2e-tests" + # upload new package + curl \ + --fail \ + -H "Authorization: token $forgejo_token" \ + -T "$file" \ + "$forgejo_url/api/packages/root/alpine/3.19/e2e-tests" done # ensure that the install-if condition works as expected @@ -57,7 +57,7 @@ apk add openrc (cd /etc/apk/keys && curl -JO $forgejo_url/api/packages/root/alpine/key) echo "$forgejo_url/api/packages/root/alpine/3.19/e2e-tests" >>/etc/apk/repositories apk add forgejo-2174 forgejo-2173 -[ -e /usr/bin/forgejo_2174 ] # from the installed package -[ -e /usr/bin/forgejo_2173 ] # from the installed package +[ -e /usr/bin/forgejo_2174 ] # from the installed package +[ -e /usr/bin/forgejo_2173 ] # from the installed package [ -e /etc/init.d/forgejo_2174 ] # from the -openrc package installed because of the install-if condition [ -e /etc/init.d/forgejo_2173 ] # from the -openrc package installed because of the install-if condition diff --git a/packages/alpine.sh b/packages/alpine.sh index ae82913..79595ae 100644 --- a/packages/alpine.sh +++ b/packages/alpine.sh @@ -16,9 +16,9 @@ function test_packages_alpine_version() { } function test_packages_alpine() { - for alpine_version in 3.18 3.19 ; do - for forgejo_version in 1.21 7.0-test 7.0-dev ; do - test_packages_alpine_version $alpine_version $forgejo_version - done + for alpine_version in 3.18 3.19; do + for forgejo_version in 1.21 7.0-test 7.0-dev; do + test_packages_alpine_version $alpine_version $forgejo_version + done done } diff --git a/storage/storage.sh b/storage/storage.sh index a531e50..e96a0d3 100755 --- a/storage/storage.sh +++ b/storage/storage.sh @@ -1,6 +1,6 @@ # SPDX-License-Identifier: MIT -STORAGE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +STORAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" STORAGE_PATHS="attachments avatars lfs packages repo-archive repo-avatars" @@ -14,7 +14,7 @@ function storage_reset() { function verify_storage() { local work_path=$DIR/forgejo-work-path - for path in ${STORAGE_PATHS} ; do + for path in ${STORAGE_PATHS}; do test -d $work_path/data/$path done } @@ -22,7 +22,7 @@ function verify_storage() { function cleanup_storage() { local work_path=$DIR/forgejo-work-path - for path in ${STORAGE_PATHS} ; do + for path in ${STORAGE_PATHS}; do rm -fr $work_path/data/$path done } @@ -33,13 +33,13 @@ function test_storage_stable_s3() { log_info "See also https://codeberg.org/forgejo/forgejo/issues/1338" - for version in 1.21 $RELEASE_NUMBERS_AND_DEV ; do + for version in 1.21 $RELEASE_NUMBERS_AND_DEV; do log_info "Forgejo $version & $s3_backend" stop storage_reset stable-s3 start $version $s3_backend fixture_create - for fun in ${STORAGE_FUN} ; do + for fun in ${STORAGE_FUN}; do fixture_${fun}_assert_s3 done done diff --git a/upgrade/test-pprof-upload.sh b/upgrade/test-pprof-upload.sh index e5ab46d..48dada4 100644 --- a/upgrade/test-pprof-upload.sh +++ b/upgrade/test-pprof-upload.sh @@ -1,43 +1,43 @@ # SPDX-License-Identifier: MIT function test_upload_profiles() { - FORGEJO_URL="http://localhost:6060" - PROFILECLI_URL="http://0.0.0.0:4040" + FORGEJO_URL="http://localhost:6060" + PROFILECLI_URL="http://0.0.0.0:4040" - endpoints=("/debug/pprof/allocs" "/debug/pprof/block" "/debug/pprof/goroutine" "/debug/pprof/mutex" "/debug/pprof/profile?seconds=5") - curl -fL https://github.com/grafana/pyroscope/releases/download/v1.1.5/profilecli_1.1.5_linux_amd64.tar.gz -o profilecli.tar.gz - tar xzf profilecli.tar.gz + endpoints=("/debug/pprof/allocs" "/debug/pprof/block" "/debug/pprof/goroutine" "/debug/pprof/mutex" "/debug/pprof/profile?seconds=5") + curl -fL https://github.com/grafana/pyroscope/releases/download/v1.1.5/profilecli_1.1.5_linux_amd64.tar.gz -o profilecli.tar.gz + tar xzf profilecli.tar.gz - for endpoint in "${endpoints[@]}"; do - output=$(basename "$endpoint") - if [[ $endpoint == *"/profile"* ]]; then - output="profile" - fi - output="${output}.pprof" - # Download the content and save it to a file - curl -s "${FORGEJO_URL}${endpoint}" -o "${output}" - ./profilecli upload ${output} --url=${PROFILECLI_URL} + for endpoint in "${endpoints[@]}"; do + output=$(basename "$endpoint") + if [[ $endpoint == *"/profile"* ]]; then + output="profile" + fi + output="${output}.pprof" + # Download the content and save it to a file + curl -s "${FORGEJO_URL}${endpoint}" -o "${output}" + ./profilecli upload ${output} --url=${PROFILECLI_URL} - rm ${output} - done + rm ${output} + done } function test_forgejo_pprof() { - stop - docker rm -f test_pyroscope - docker run --name test_pyroscope --rm -d -p 4040:4040 docker.io/grafana/pyroscope + stop + docker rm -f test_pyroscope + docker run --name test_pyroscope --rm -d -p 4040:4040 docker.io/grafana/pyroscope - reset_forgejo $UPGRADE_DIR/default-app.ini - log_info "run 7.0-test" - start 7.0-test - test_upload_profiles - stop + reset_forgejo $UPGRADE_DIR/default-app.ini + log_info "run 7.0-test" + start 7.0-test + test_upload_profiles + stop - log_info "run 8.0-test" - start 8.0-test - test_upload_profiles - stop - - docker stop test_pyroscope + log_info "run 8.0-test" + start 8.0-test + test_upload_profiles + stop + + docker stop test_pyroscope } diff --git a/upgrade/upgrade.sh b/upgrade/upgrade.sh index 5b66d8c..640cf04 100755 --- a/upgrade/upgrade.sh +++ b/upgrade/upgrade.sh @@ -1,6 +1,6 @@ # SPDX-License-Identifier: MIT -UPGRADE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +UPGRADE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" function upgrade_reset() { local config=$1 @@ -11,7 +11,7 @@ function upgrade_reset() { function verify_storage() { local work_path=$DIR/forgejo-work-path - for path in ${STORAGE_PATHS} ; do + for path in ${STORAGE_PATHS}; do test -d $work_path/data/$path done } @@ -19,14 +19,14 @@ function verify_storage() { function cleanup_storage() { local work_path=$DIR/forgejo-work-path - for path in ${STORAGE_PATHS} ; do + for path in ${STORAGE_PATHS}; do rm -fr $work_path/data/$path done } function test_successful_upgrades() { stop - for config in $UPGRADE_DIR/default-app.ini ; do + for config in $UPGRADE_DIR/default-app.ini; do log_info "using $config" upgrade_reset $config @@ -38,7 +38,7 @@ function test_successful_upgrades() { fixture_assert doctor_run $config - for version in $RELEASE_NUMBERS_AND_DEV ; do + for version in $RELEASE_NUMBERS_AND_DEV; do stop log_info "run $version" start $version @@ -55,7 +55,7 @@ function test_gitea_upgrades() { echo gitea 1.21 forgejo 7.0-test echo gitea 1.21 forgejo 8.0-test echo gitea 1.22 forgejo 8.0-test - ) | while read gitea gitea_version forgejo forgejo_version ; do + ) | while read gitea gitea_version forgejo forgejo_version; do log_info "upgrading from Gitea $gitea_version to Forgejo $forgejo_version" stop upgrade_reset $config