mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-11-24 00:31:02 -05:00
53 lines
1.6 KiB
Bash
Executable file
53 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
set -ex
|
|
|
|
function dependencies() {
|
|
if ! which curl daemon > /dev/null ; then
|
|
apt-get install -y -qq curl daemon
|
|
fi
|
|
}
|
|
|
|
function download() {
|
|
local runner_repository="$1"
|
|
local version="$2"
|
|
|
|
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 generate-runner-token > 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
|
|
}
|
|
|
|
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
|
|
sleep 1
|
|
cat forgejo-runner.log
|
|
}
|
|
|
|
function setup() {
|
|
local runner_repository="${1:-https://code.forgejo.org/forgejo/runner}"
|
|
local version="${2:-v2.0.0}"
|
|
local forgejo="${3:-http://$(cat forgejo-ip):3000/}"
|
|
|
|
dependencies
|
|
download $runner_repository $version
|
|
register $forgejo
|
|
run
|
|
}
|
|
|
|
function teardown() {
|
|
if test -f forgejo-runner-pid ; then
|
|
kill -TERM $(cat forgejo-runner-pid)
|
|
rm -f forgejo-runner-pid
|
|
fi
|
|
}
|
|
|
|
"$@"
|