test: test offline runner registration (#1449)

Reviewed-on: https://code.forgejo.org/forgejo/end-to-end/pulls/1449
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: Andreas Ahlenstorf <andreas@ahlenstorf.ch>
Co-committed-by: Andreas Ahlenstorf <andreas@ahlenstorf.ch>
This commit is contained in:
Andreas Ahlenstorf 2026-01-19 01:47:27 +00:00 committed by Mathieu Fenniak
parent 25c472b90b
commit 372409f76b
5 changed files with 92 additions and 1 deletions

View file

@ -143,7 +143,7 @@ function test_actions() {
done
fi
for example in echo matrix needs workflow-call lxc config-options cache cache-pull-request checkout service container expression local-action docker-action if if-fail push tag push-cancel artifacts pull-request context private-workflow-call; do
for example in echo matrix needs workflow-call lxc config-options cache cache-pull-request checkout service container expression local-action docker-action if if-fail push tag push-cancel artifacts pull-request context private-workflow-call create-runner-file; do
run actions_verify_example $example
done

View file

@ -0,0 +1,9 @@
on:
push:
jobs:
test:
runs-on: create-runner-file
steps:
- run: |
echo "OK"

View file

@ -0,0 +1,40 @@
source "lib/lib.sh"
api="$url/api/v1"
function main() {
local repo
repo="root/example-$example"
secret="$(openssl rand -hex 20)"
runner_name="runner-$(openssl rand -hex 5)"
create_offline_registration_token "$runner_name" root "$secret"
# Changing to $DIR is necessary so that `.runner` gets created there. Otherwise, `forgejo-runner` would not pick it up.
pushd "$DIR" || exit 1
./forgejo-runner -c "$EXAMPLE_DIR/runner-config.yaml" create-runner-file --instance "http://$IP:3000" --name "$runner_name" --secret "$secret" --connect
popd || exit 1
FORGEJO_RUNNER_CONFIG="$EXAMPLE_DIR/runner-config.yaml" forgejo-runner.sh reload
label_count=$(jq '.labels | length ' "$DIR/.runner")
if [[ "$label_count" != "1" ]] ; then
echo "Unexpected number of labels in .runner file: $label_count instead of 1" >&2
exit 1
fi
runner_label=$(jq -r '.labels[0]' "$DIR/.runner")
if [[ "$runner_label" != "create-runner-file:docker://code.forgejo.org/oci/node:24-trixie" ]] ; then
echo "Unexpected runner label: '$runner_label' instead of create-runner-file:docker://code.forgejo.org/oci/node:24-trixie" >&2
exit 1
fi
forgejo-test-helper.sh push_workflow "actions/example-$example" "$url" root "example-$example" setup-forgejo "$token"
local sha
sha="$(forgejo-test-helper.sh branch_tip "$url" "$repo" main)"
forgejo-test-helper.sh wait_success "$url" "$repo" "$sha"
}
main

View file

@ -0,0 +1,31 @@
log:
level: debug
runner:
file: .runner
capacity: 1
env_file: .env
timeout: 3h
insecure: false
fetch_timeout: 5s
fetch_interval: 2s
labels:
- "create-runner-file:docker://code.forgejo.org/oci/node:24-trixie"
cache:
enabled: true
dir: "/srv/example/cache"
host: ""
port: 0
container:
network: "bridge"
privileged: false
options:
workdir_parent:
valid_volumes: ["/srv/example"]
docker_host: ""
host:
workdir_parent:

View file

@ -415,6 +415,17 @@ EOF
cp -a $DOT_FORGEJO_CURL $work_path/forgejo-curl
}
function create_offline_registration_token() {
local name="$1"
local scope="$2"
local secret="$3"
local work_path
work_path="$DIR/$(work_path_base "$config")"
"$work_path/forgejocli" forgejo-cli actions register --name "$name" --scope "$scope" --secret "$secret"
}
function stop_daemon() {
local daemon=$1