From e97991ef78ea821681b6d826d069aea94627d296 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Tue, 4 Apr 2023 18:24:21 +0200 Subject: [PATCH 1/3] do not try to install the runner if it already available --- forgejo-runner.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/forgejo-runner.sh b/forgejo-runner.sh index 16b8236..b52575b 100755 --- a/forgejo-runner.sh +++ b/forgejo-runner.sh @@ -13,18 +13,21 @@ function download() { local runner_repository="$1" local version="$2" - curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-amd64 > /bin/forgejo-runner - chmod 755 /bin/forgejo-runner + if ! which forgejo-runner > /dev/null; then + curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-amd64 > /bin/forgejo-runner + chmod 755 /bin/forgejo-runner + fi } function register() { local forgejo="$1" docker exec --user 1000 forgejo forgejo actions --registration-token-admin > forgejo-runner-token - timeout --signal=KILL 30 forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat forgejo-runner-token) --labels ubuntu-latest:docker://node:16-buster,self-hosted + timeout --signal=KILL 30 forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat forgejo-runner-token) --labels ubuntu-latest:docker://node:16-buster,self-hosted } function run() { - daemon --chdir=$(pwd) --unsafe --pidfile=$(pwd)/forgejo-runner-pid --errlog=$(pwd)/forgejo-runner.log --output=$(pwd)/forgejo-runner.log /bin/forgejo-runner daemon + rm -f forgejo-runner.log + daemon --chdir=$(pwd) --unsafe --pidfile=$(pwd)/forgejo-runner-pid --errlog=$(pwd)/forgejo-runner.log --output=$(pwd)/forgejo-runner.log forgejo-runner daemon sleep 1 cat forgejo-runner.log } From 05c2b60cc53e998a1e0119c089032d8e696fb59a Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 5 Apr 2023 14:49:04 +0200 Subject: [PATCH 2/3] helper to compile from source --- forgejo-test-helper.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/forgejo-test-helper.sh b/forgejo-test-helper.sh index 386602d..2394e7e 100755 --- a/forgejo-test-helper.sh +++ b/forgejo-test-helper.sh @@ -9,6 +9,36 @@ DIR=$(mktemp -d) trap "rm -fr $DIR" EXIT +function dependency_go() { + if ! which go > /dev/null ; then + apt-get update + apt-get install -y -qq wget tar + wget https://go.dev/dl/go1.20.3.linux-amd64.tar.gz + tar zxf go1.20.3.linux-amd64.tar.gz + export PATH=$PATH:$(pwd)/go/bin + fi +} + +function checkout() { + local git="$1" + if ! test -d forgejo-runner ; then + git clone $git forgejo-runner + fi +} + +function build() { + local git="$1" + local version="$2" + + ( + checkout "$git" + cd forgejo-runner + git checkout "$version" + make build + export PATH=$PATH:$(pwd) + ) +} + function api() { method=$1 shift From 1862690dde52dadc086dcd3562f1b1cb746052b1 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 5 Apr 2023 16:48:22 +0200 Subject: [PATCH 3/3] document how to use build_runner for a short debug loop --- .forgejo/workflows/integration.yml | 8 ++++++++ action.yml | 5 +++++ forgejo-test-helper.sh | 13 +++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index a7594d2..3246eef 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -8,6 +8,14 @@ jobs: 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 ./forgejo-test-helper.sh run_workflow testdata/demo http://root:admin1234@$(cat forgejo-ip):3000 root demo setup-forgejo $(cat forgejo-token) > /tmp/output diff --git a/action.yml b/action.yml index e765be3..eae3f42 100644 --- a/action.yml +++ b/action.yml @@ -21,6 +21,11 @@ description: | Create the repository `$forgejo/root/testrepo` and populate it with the content of the `testrepo` directory. The SHA of the tip of the repository is in the output, starting with `sha=`. + * `forgejo-test-helper.sh build_runner $forgejo/forgejo/runner v1.4.1` + Builds the forgejo runner from source in `./forgejo-runner/forgejo-runner`. + `export PATH=$(pwd)/forgejo-runner:$PATH` will ensure that calling `forgejo-runner.sh` + will use this binary instead of downloading a released version of the runner. + If the version is not specified, build from the main branch. The combination of `push_self_action` and `run_workflow` allows to run Forgejo Actions workflows from `testrepo` that use the action diff --git a/forgejo-test-helper.sh b/forgejo-test-helper.sh index 2394e7e..ebc53c9 100755 --- a/forgejo-test-helper.sh +++ b/forgejo-test-helper.sh @@ -21,22 +21,23 @@ function dependency_go() { function checkout() { local git="$1" - if ! test -d forgejo-runner ; then - git clone $git forgejo-runner - fi + rm -fr forgejo-runner + git clone $git forgejo-runner } -function build() { +function build_runner() { local git="$1" - local version="$2" + local version="${2:-main}" ( checkout "$git" + dependency_go cd forgejo-runner git checkout "$version" make build - export PATH=$PATH:$(pwd) ) + export PATH=$PATH:$(pwd)/forgejo-runner + forgejo-runner --version } function api() {