From cdd9a76852dace159a334de90c2c2424f285d246 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 29 May 2023 15:26:29 +0200 Subject: [PATCH 1/5] example: echo --- .forgejo/workflows/integration.yml | 6 ++++++ testdata/example-echo/.forgejo/workflows/test.yml | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 testdata/example-echo/.forgejo/workflows/test.yml diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index fc0e253..9f877e0 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -18,7 +18,13 @@ jobs: # ./forgejo-runner.sh setup export FORGEJO_RUNNER_LOGS=forgejo-runner.log + for example in echo ; do + echo "============================ example-$example ===================" + ./forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token) + done + echo "============================ demo ===================" ./forgejo-test-helper.sh run_workflow testdata/demo http://root:admin1234@$(cat forgejo-ip):3000 root demo setup-forgejo $(cat forgejo-token) > /tmp/output grep '^sha=' /tmp/output + echo "============================ sanity-check ===================" ./forgejo-test-helper.sh push_self_action http://root:admin1234@$(cat forgejo-ip):3000 root setup-forgejo vTest ./forgejo-test-helper.sh run_workflow testdata/sanity-checks http://root:admin1234@$(cat forgejo-ip):3000 root sanity-check setup-forgejo $(cat forgejo-token) diff --git a/testdata/example-echo/.forgejo/workflows/test.yml b/testdata/example-echo/.forgejo/workflows/test.yml new file mode 100644 index 0000000..6010460 --- /dev/null +++ b/testdata/example-echo/.forgejo/workflows/test.yml @@ -0,0 +1,6 @@ +on: [push] +jobs: + test: + runs-on: ubuntu-latest + steps: + - run: echo All Good From a69ecf9f35e57c814e32b7eb12958ac912bd1e54 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 29 May 2023 16:07:00 +0200 Subject: [PATCH 2/5] example: container --- .forgejo/workflows/integration.yml | 2 +- testdata/example-container/.forgejo/workflows/test.yml | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 testdata/example-container/.forgejo/workflows/test.yml diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index 9f877e0..4281caa 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -18,7 +18,7 @@ jobs: # ./forgejo-runner.sh setup export FORGEJO_RUNNER_LOGS=forgejo-runner.log - for example in echo ; do + for example in echo container ; do echo "============================ example-$example ===================" ./forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token) done diff --git a/testdata/example-container/.forgejo/workflows/test.yml b/testdata/example-container/.forgejo/workflows/test.yml new file mode 100644 index 0000000..f4903a3 --- /dev/null +++ b/testdata/example-container/.forgejo/workflows/test.yml @@ -0,0 +1,8 @@ +on: [push] +jobs: + test: + runs-on: ubuntu-latest + container: + image: alpine:3.18 + steps: + - run: grep Alpine /etc/os-release From 9e59ef5abdfedfe85762835efb0d495e791fc0dc Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 29 May 2023 16:35:13 +0200 Subject: [PATCH 3/5] example: service --- .forgejo/workflows/integration.yml | 2 +- .../.forgejo/workflows/test.yml | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 testdata/example-service/.forgejo/workflows/test.yml diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index 4281caa..5e65f92 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -18,7 +18,7 @@ jobs: # ./forgejo-runner.sh setup export FORGEJO_RUNNER_LOGS=forgejo-runner.log - for example in echo container ; do + for example in echo container service ; do echo "============================ example-$example ===================" ./forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token) done diff --git a/testdata/example-service/.forgejo/workflows/test.yml b/testdata/example-service/.forgejo/workflows/test.yml new file mode 100644 index 0000000..68e6505 --- /dev/null +++ b/testdata/example-service/.forgejo/workflows/test.yml @@ -0,0 +1,19 @@ +on: [push] + +jobs: + test: + runs-on: ubuntu-latest + + services: + pgsql: + image: postgres:15 + env: + POSTGRES_DB: test + POSTGRES_PASSWORD: postgres + ports: + - "5432:5432" + steps: + - run: | + apt-get update -qq + apt-get install -y -qq postgresql-client-11 + PGPASSWORD=postgres psql -h pgsql -U postgres -c '\dt' test From bf7851a1c580a1411c4ae62dafe48ebfbd62d3fa Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 29 May 2023 17:12:23 +0200 Subject: [PATCH 4/5] split integration tests (nested or not) --- .forgejo/workflows/integration.yml | 14 ++------ forgejo-runner.sh | 4 ++- runner-config-no-bridge.yaml | 55 ++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 runner-config-no-bridge.yaml diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index 5e65f92..8e12447 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -6,16 +6,9 @@ jobs: - uses: actions/checkout@v3 - run: | set -x - LXC_IP_PREFIX=10.0.9 ./forgejo-dependencies.sh + LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh ./forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.19 - # - # Uncomment the following for a shortcut to debugging the Forgejo runner. - # It will build the runner from a designated repository and branch instead of - # downloading it from a canonical release. - # - # ./forgejo-test-helper.sh build_runner http://code.forgejo.org/forgejo/runner branch-under-debug - # export PATH=$(pwd)/forgejo-runner:$PATH - # + export FORGEJO_RUNNER_CONFIG=$(pwd)/runner-config-no-bridge.yaml ./forgejo-runner.sh setup export FORGEJO_RUNNER_LOGS=forgejo-runner.log for example in echo container service ; do @@ -25,6 +18,3 @@ jobs: echo "============================ demo ===================" ./forgejo-test-helper.sh run_workflow testdata/demo http://root:admin1234@$(cat forgejo-ip):3000 root demo setup-forgejo $(cat forgejo-token) > /tmp/output grep '^sha=' /tmp/output - echo "============================ sanity-check ===================" - ./forgejo-test-helper.sh push_self_action http://root:admin1234@$(cat forgejo-ip):3000 root setup-forgejo vTest - ./forgejo-test-helper.sh run_workflow testdata/sanity-checks http://root:admin1234@$(cat forgejo-ip):3000 root sanity-check setup-forgejo $(cat forgejo-token) diff --git a/forgejo-runner.sh b/forgejo-runner.sh index 0c2def7..a42254e 100755 --- a/forgejo-runner.sh +++ b/forgejo-runner.sh @@ -3,6 +3,8 @@ set -ex +: ${FORGEJO_RUNNER_CONFIG:=$(pwd)/runner-config.yaml} + function dependencies() { if ! which curl daemon > /dev/null ; then apt-get install -y -qq curl daemon @@ -27,7 +29,7 @@ function register() { function run() { rm -f forgejo-runner.log - daemon --chdir=$(pwd) --unsafe --env="TERM=$TERM" --env="HOME=$HOME" --env="PATH=$PATH" --env="USER=$USER" --env="TERM=dumb" --env="USERNAME=$USERNAME" --env="LANG=$LANG" --pidfile=$(pwd)/forgejo-runner-pid --errlog=$(pwd)/forgejo-runner.log --output=$(pwd)/forgejo-runner.log -- forgejo-runner --config $(pwd)/runner-config.yaml daemon + daemon --chdir=$(pwd) --unsafe --env="TERM=$TERM" --env="HOME=$HOME" --env="PATH=$PATH" --env="USER=$USER" --env="TERM=dumb" --env="USERNAME=$USERNAME" --env="LANG=$LANG" --pidfile=$(pwd)/forgejo-runner-pid --errlog=$(pwd)/forgejo-runner.log --output=$(pwd)/forgejo-runner.log -- forgejo-runner --config $FORGEJO_RUNNER_CONFIG daemon sleep 1 cat forgejo-runner.log } diff --git a/runner-config-no-bridge.yaml b/runner-config-no-bridge.yaml new file mode 100644 index 0000000..1e78425 --- /dev/null +++ b/runner-config-no-bridge.yaml @@ -0,0 +1,55 @@ +# Example configuration file, it's safe to copy this as the default config file without any modification. + +log: + # The level of logging, can be trace, debug, info, warn, error, fatal + level: info + +runner: + # Where to store the registration result. + file: .runner + # Execute how many tasks concurrently at the same time. + capacity: 1 + # Extra environment variables to run jobs. + #envs: + # A_TEST_ENV_NAME_1: a_test_env_value_1 + # A_TEST_ENV_NAME_2: a_test_env_value_2 + # Extra environment variables to run jobs from a file. + # It will be ignored if it's empty or the file doesn't exist. + env_file: .env + # The timeout for a job to be finished. + # Please note that the Gitea instance also has a timeout (3h by default) for the job. + # So the job could be stopped by the Gitea instance if it's timeout is shorter than this. + timeout: 3h + # Whether skip verifying the TLS certificate of the Gitea instance. + insecure: false + # The timeout for fetching the job from the Gitea instance. + fetch_timeout: 5s + # The interval for fetching the job from the Gitea instance. + fetch_interval: 2s + +cache: + # Enable cache server to use actions/cache. + enabled: false + # The directory to store the cache data. + # If it's empty, the cache data will be stored in $HOME/.cache/actcache. + dir: "" + # The host of the cache server. + # It's not for the address to listen, but the address to connect from job containers. + # So 0.0.0.0 is a bad choice, leave it empty to detect automatically. + host: "" + # The port of the cache server. + # 0 means to use a random available port. + port: 0 + +container: + # Specifies the network to which the container will connect. + # Could be host, bridge or the name of a custom network. + # If it's empty, act_runner will create a network automatically. + network: "" + # Whether to use privileged mode or not when launching task containers (privileged mode is required for Docker-in-Docker). + privileged: false + # And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway). + options: + # The parent directory of a job's working directory. + # If it's empty, /workspace will be used. + workdir_parent: From ea6a9c5277c68718612370d2d747a32a8365b95f Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 29 May 2023 17:12:44 +0200 Subject: [PATCH 5/5] nested integration tests --- .forgejo/workflows/integration-nested.yml | 23 ++++++++++ .forgejo/workflows/integration.yml | 3 +- runner-config-no-bridge.yaml | 55 ----------------------- 3 files changed, 24 insertions(+), 57 deletions(-) create mode 100644 .forgejo/workflows/integration-nested.yml delete mode 100644 runner-config-no-bridge.yaml diff --git a/.forgejo/workflows/integration-nested.yml b/.forgejo/workflows/integration-nested.yml new file mode 100644 index 0000000..4710f50 --- /dev/null +++ b/.forgejo/workflows/integration-nested.yml @@ -0,0 +1,23 @@ +on: [ push, pull_request ] +jobs: + integration: + runs-on: self-hosted + steps: + - uses: actions/checkout@v3 + - run: | + set -x + LXC_IP_PREFIX=10.0.9 ./forgejo-dependencies.sh + ./forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.19 + # + # Uncomment the following for a shortcut to debugging the Forgejo runner. + # It will build the runner from a designated repository and branch instead of + # downloading it from a canonical release. + # + # ./forgejo-test-helper.sh build_runner http://code.forgejo.org/forgejo/runner branch-under-debug + # export PATH=$(pwd)/forgejo-runner:$PATH + # + ./forgejo-runner.sh setup + export FORGEJO_RUNNER_LOGS=forgejo-runner.log + echo "============================ sanity-check ===================" + ./forgejo-test-helper.sh push_self_action http://root:admin1234@$(cat forgejo-ip):3000 root setup-forgejo vTest + ./forgejo-test-helper.sh run_workflow testdata/sanity-checks http://root:admin1234@$(cat forgejo-ip):3000 root sanity-check setup-forgejo $(cat forgejo-token) diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index 8e12447..23104e8 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -8,10 +8,9 @@ jobs: set -x LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh ./forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.19 - export FORGEJO_RUNNER_CONFIG=$(pwd)/runner-config-no-bridge.yaml ./forgejo-runner.sh setup export FORGEJO_RUNNER_LOGS=forgejo-runner.log - for example in echo container service ; do + for example in echo container ; do echo "============================ example-$example ===================" ./forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token) done diff --git a/runner-config-no-bridge.yaml b/runner-config-no-bridge.yaml deleted file mode 100644 index 1e78425..0000000 --- a/runner-config-no-bridge.yaml +++ /dev/null @@ -1,55 +0,0 @@ -# Example configuration file, it's safe to copy this as the default config file without any modification. - -log: - # The level of logging, can be trace, debug, info, warn, error, fatal - level: info - -runner: - # Where to store the registration result. - file: .runner - # Execute how many tasks concurrently at the same time. - capacity: 1 - # Extra environment variables to run jobs. - #envs: - # A_TEST_ENV_NAME_1: a_test_env_value_1 - # A_TEST_ENV_NAME_2: a_test_env_value_2 - # Extra environment variables to run jobs from a file. - # It will be ignored if it's empty or the file doesn't exist. - env_file: .env - # The timeout for a job to be finished. - # Please note that the Gitea instance also has a timeout (3h by default) for the job. - # So the job could be stopped by the Gitea instance if it's timeout is shorter than this. - timeout: 3h - # Whether skip verifying the TLS certificate of the Gitea instance. - insecure: false - # The timeout for fetching the job from the Gitea instance. - fetch_timeout: 5s - # The interval for fetching the job from the Gitea instance. - fetch_interval: 2s - -cache: - # Enable cache server to use actions/cache. - enabled: false - # The directory to store the cache data. - # If it's empty, the cache data will be stored in $HOME/.cache/actcache. - dir: "" - # The host of the cache server. - # It's not for the address to listen, but the address to connect from job containers. - # So 0.0.0.0 is a bad choice, leave it empty to detect automatically. - host: "" - # The port of the cache server. - # 0 means to use a random available port. - port: 0 - -container: - # Specifies the network to which the container will connect. - # Could be host, bridge or the name of a custom network. - # If it's empty, act_runner will create a network automatically. - network: "" - # Whether to use privileged mode or not when launching task containers (privileged mode is required for Docker-in-Docker). - privileged: false - # And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway). - options: - # The parent directory of a job's working directory. - # If it's empty, /workspace will be used. - workdir_parent: