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
This commit is contained in:
Twenty Panda 2024-03-15 14:34:55 +07:00 committed by p
parent dd35a9f1a8
commit 9ff495254a
8 changed files with 64 additions and 153 deletions

View file

@ -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

View file

@ -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

View file

@ -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`

View file

@ -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

30
packages/alpine-app.ini Normal file
View file

@ -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

View file

@ -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
}

11
packages/packages.sh Normal file
View file

@ -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
}

View file

@ -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 "$@"