From 9ff495254af1cd2ad6c0f938f781cb349dd82676 Mon Sep 17 00:00:00 2001 From: Twenty Panda Date: Fri, 15 Mar 2024 14:34:55 +0700 Subject: [PATCH] packages: simplify the setup to use the same as upgrades the packages tests control which Forgejo version they run against so they can test a feature on version X+1 and not on version X --- .forgejo/workflows/packages.yml | 43 ----------------- .forgejo/workflows/upgrade.yml | 3 ++ README.md | 29 +++--------- forgejo/upgrades/test-upgrade.sh | 3 ++ packages/alpine-app.ini | 30 ++++++++++++ packages/alpine.sh | 18 +++---- packages/packages.sh | 11 +++++ packages/run.sh | 80 -------------------------------- 8 files changed, 64 insertions(+), 153 deletions(-) delete mode 100644 .forgejo/workflows/packages.yml create mode 100644 packages/alpine-app.ini create mode 100644 packages/packages.sh delete mode 100755 packages/run.sh diff --git a/.forgejo/workflows/packages.yml b/.forgejo/workflows/packages.yml deleted file mode 100644 index fc59c92..0000000 --- a/.forgejo/workflows/packages.yml +++ /dev/null @@ -1,43 +0,0 @@ -on: - pull_request: - push: - branches: - - 'main' - -jobs: - packages: - runs-on: self-hosted - strategy: - matrix: - info: - - version: v7.0 - branch: next - forgejo: https://codeberg.org - repo: forgejo-experimental/forgejo - tests: ${{ vars.V7_0_TESTS }} - - version: v1.21 - forgejo: https://codeberg.org - repo: forgejo/forgejo - tests: ${{ vars.V1_21_TESTS }} - steps: - - uses: actions/checkout@v4 - - - uses: https://code.forgejo.org/actions/setup-forgejo@v2 - with: - install-only: true - - - name: run - if: matrix.info.tests != 'none' - shell: bash - run: | - set -x - forgejo-binary.sh ensure_user forgejo - full_version=$(curl -sS ${{ matrix.info.forgejo }}/api/v1/repos/${{ matrix.info.repo }}/releases | jq -r '.[] | .tag_name | select(startswith("${{ matrix.info.version }}"))' | sort -r | head -1) - binary=${{ matrix.info.forgejo }}/${{ matrix.info.repo }}/releases/download/${full_version}/forgejo-${full_version#v}-linux-amd64 - - export DIR=$(mktemp -d) - chown forgejo $DIR /srv - - export VERBOSE="${{ vars.VERBOSE || false }}" - - su -c "packages/run.sh $binary $full_version ${{ matrix.info.version }} ${{ matrix.info.tests }}" forgejo diff --git a/.forgejo/workflows/upgrade.yml b/.forgejo/workflows/upgrade.yml index 06a8843..eb285f7 100644 --- a/.forgejo/workflows/upgrade.yml +++ b/.forgejo/workflows/upgrade.yml @@ -31,8 +31,11 @@ jobs: with: go-version: "1.21" - run: | + apt-get update -qq + apt-get -q install -qq -y docker.io git config --add safe.directory '*' adduser --quiet --comment forgejo --disabled-password forgejo + adduser forgejo docker chown -R forgejo:forgejo . - run: | script=$(pwd)/forgejo/upgrades/test-upgrade.sh diff --git a/README.md b/README.md index 3cdb044..6ca1311 100644 --- a/README.md +++ b/README.md @@ -95,34 +95,19 @@ it does not exist, all tests are run. * `V1_21_TESTS` * `V1_20_TESTS` -## Running packages locally +## Running other tests locally -To run and debug package tests, from the root of the source directory. +To run and debug tests, from the root of the source directory. -Run one test +Run one test. When the test fails the instance can be inspected at http://0.0.0.0:3000 ```sh -packages/run.sh https://codeberg.org/forgejo-experimental/forgejo/releases/download/v7.0-test/forgejo-7.0-test-linux-amd64 v7.0.0-test v7_0 alpine # runs packages/alpine.sh +VERBOSE=true ./forgejo/upgrades/test-upgrade.sh test_packages_alpine +VERBOSE=true ./forgejo/upgrades/test-upgrade.sh test_storage_stable_s3 minio ``` -Cleanup. It will teardown Forgejo and not run them because there is nothing to test. +Cleanup. It will teardown the Forgejo instance. ```sh -packages/run.sh https://codeberg.org/forgejo-experimental/forgejo/releases/download/v7.0-test/forgejo-7.0-test-linux-amd64 v7.0.0-test v7_0 none +./forgejo/upgrades/test-upgrade.sh stop ``` -Run all examples for v7_0 - -```sh -packages/run.sh https://codeberg.org/forgejo-experimental/forgejo/releases/download/v7.0-test/forgejo-7.0-test-linux-amd64 v7.0.0-test v7_0 -``` - -Remote testing - -To reduce the runtime the following variables can be set to control -the number of cases run by the -[packages test](.forgejo/workflows/packages.yml) tests. If set to -**none** they are not run at all for that version of Forgejo. If -it does not exist, all tests are run. - -* `v7_0_PACKAGES_TESTS` -* `V1_21_PACKAGES_TESTS` diff --git a/forgejo/upgrades/test-upgrade.sh b/forgejo/upgrades/test-upgrade.sh index 25eea18..b2a0c10 100755 --- a/forgejo/upgrades/test-upgrade.sh +++ b/forgejo/upgrades/test-upgrade.sh @@ -87,12 +87,15 @@ function test_forgejo_database_version() { source $SELF_DIR/test-upgrade-1.20-storage.sh source $SELF_DIR/test-upgrade-forgejo-database-v3.sh +source $SELF_DIR/../../packages/packages.sh function test_upgrades() { run stop run dependencies run build_all + test_packages + run test_successful_upgrades run test_storage_stable_s3 minio run test_storage_stable_s3 garage diff --git a/packages/alpine-app.ini b/packages/alpine-app.ini new file mode 100644 index 0000000..a51290a --- /dev/null +++ b/packages/alpine-app.ini @@ -0,0 +1,30 @@ +RUN_MODE = prod +WORK_PATH = ${WORK_PATH} + +[server] +APP_DATA_PATH = ${WORK_PATH}/data +HTTP_PORT = 3000 +SSH_LISTEN_PORT = 2222 +LFS_START_SERVER = true + +[database] +DB_TYPE = sqlite3 +PATH = ${WORK_PATH}/forgejo.db + +[log] +MODE = file +LEVEL = trace +ROUTER = file + +[log.file] +FILE_NAME = forgejo.log + +[security] +INSTALL_LOCK = true + +[repository] +ENABLE_PUSH_CREATE_USER = true +DEFAULT_PUSH_CREATE_PRIVATE = false + +[actions] +ENABLED = true diff --git a/packages/alpine.sh b/packages/alpine.sh index 96c619b..11cb56a 100644 --- a/packages/alpine.sh +++ b/packages/alpine.sh @@ -2,16 +2,18 @@ # Copyright 2024 The Forgejo Authors # SPDX-License-Identifier: MIT -SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +function test_packages_alpine_v1.21() { + stop_daemon forgejo + reset_forgejo $PACKAGES_DIR/alpine-app.ini + start_forgejo 1.21 -source $SELF_DIR/../lib/lib.sh - -function main() { - local d=$SELF_DIR/alpine - local token=$(cat $DIR/forgejo-token) - local url=$(cat $DIR/forgejo-url) + local d=$PACKAGES_DIR/alpine + local token=$(cat $DIR/forgejo-curl/token) + local url=http://${HOST_PORT} docker run --rm --volume $d:$d:ro --workdir $d docker.io/alpine:3.19 ash -c "./test.sh $url $token" } -"${@:-main}" +function test_packages_alpine() { + test_packages_alpine_v1.21 +} diff --git a/packages/packages.sh b/packages/packages.sh new file mode 100644 index 0000000..002ed79 --- /dev/null +++ b/packages/packages.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# Copyright 2024 The Forgejo Authors +# SPDX-License-Identifier: MIT + +PACKAGES_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source $PACKAGES_DIR/alpine.sh + +function test_packages() { + run test_packages_alpine +} diff --git a/packages/run.sh b/packages/run.sh deleted file mode 100755 index 7a0a62e..0000000 --- a/packages/run.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash -# Copyright 2024 The Forgejo Authors -# SPDX-License-Identifier: MIT - -SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -source $SELF_DIR/../lib/lib.sh - -function run() { - local package=$1 - - bash -ex $SELF_DIR/$package.sh -} - -function packages_v1_21() { - echo 'alpine' -} - -function packages_v7_0() { - packages_v1_21 -} - -function setup() { - local binary=$1 - forgejo-binary.sh setup root admin1234 $binary -} - -function teardown() { - forgejo-curl.sh logout - forgejo-binary.sh teardown -} - -function main() { - local binary="$1" - shift - export full_version="$1" - shift - export version="$1" - shift - - export DOT=$DIR/forgejo-curl - - teardown - - if test "$#" = 0 ; then - packages=$(packages_${version/./_}) - else - packages="$@" - fi - - if test "$packages" = "none" ; then - exit 0 - fi - - setup $binary - - if ! test -f "$DIR/forgejo-auth-url" ; then - echo "DIR=$DIR must be a directory with a forgejo-auth-url file" - fi - - export url=$(cat $DIR/forgejo-auth-url) - export token=$(cat $DIR/forgejo-token) - - for package in $packages ; do - echo "======================== BEGIN package-$package ===================" - if ! time run $package >& /tmp/run.out ; then - sed -e 's/^/[RUN] /' < /tmp/run.out - echo "======================== FAIL package-$package ===================" - sleep 5 # hack for Forgejo v1.21 to workaround a bug by which the last lines of the output are moved to the next step - false - else - if test "$VERBOSE" = true ; then - sed -e 's/^/[RUN] /' < /tmp/run.out - fi - fi - echo "======================== END package-$package ===================" - done -} - -main "$@"