mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-11-27 08:40:57 -05:00
0dee755317
for backward compatibility DIR defaults to $(pwd) also create the additional convenience files: * forgejocli * forgejo-url * forgejo-auth-url which includes the user and password
81 lines
2.6 KiB
Bash
Executable file
81 lines
2.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
set -e
|
|
|
|
PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: '
|
|
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
source $SELF_DIR/forgejo-lib.sh
|
|
|
|
: ${FORGEJO_RUNNER_CONFIG:=$SELF_DIR/runner-config.yaml}
|
|
: ${DIR:=$(pwd)}
|
|
|
|
function dependencies() {
|
|
if ! which make curl daemon > /dev/null ; then
|
|
apt-get install -y -qq make curl daemon
|
|
fi
|
|
}
|
|
|
|
function download() {
|
|
local runner_repository="$1"
|
|
local version="$2"
|
|
|
|
if ! which forgejo-runner > /dev/null; then
|
|
if ! curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-${version#v}-linux-amd64 > /usr/local/bin/forgejo-runner ; then
|
|
# backward compatibility for for the naming scheme prior to 3.0.0
|
|
curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-linux-amd64 > /usr/local/bin/forgejo-runner
|
|
fi
|
|
chmod 755 /usr/local/bin/forgejo-runner
|
|
fi
|
|
}
|
|
|
|
function register() {
|
|
local forgejo="$1"
|
|
mktemp -d > $DIR/forgejo-runner-home
|
|
$DIR/forgejocli actions generate-runner-token | tee $DIR/forgejo-runner-token
|
|
(
|
|
cd $DIR
|
|
timeout --signal=KILL 30 forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat $DIR/forgejo-runner-token) --labels docker:docker://code.forgejo.org/oci/node:20-bookworm,ubuntu-latest:docker://code.forgejo.org/oci/node:20-bookworm,self-hosted:lxc://debian:bookworm
|
|
)
|
|
}
|
|
|
|
function run() {
|
|
rm -f $DIR/forgejo-runner.log
|
|
daemon --chdir=$DIR --unsafe \
|
|
--env="TERM=$TERM" --env="HOME=$(cat $DIR/forgejo-runner-home)" --env="PATH=$PATH" --env="USER=$USER" --env="TERM=dumb" --env="USERNAME=$USERNAME" --env="LANG=$LANG" \
|
|
--pidfile=$DIR/forgejo-runner-pid --errlog=$DIR/forgejo-runner.log --output=$DIR/forgejo-runner.log -- \
|
|
forgejo-runner --config $FORGEJO_RUNNER_CONFIG daemon
|
|
sleep 1
|
|
cat $DIR/forgejo-runner.log
|
|
}
|
|
|
|
function reload() {
|
|
teardown
|
|
rm -f $DIR/forgejo-runner.log
|
|
run
|
|
}
|
|
|
|
function setup() {
|
|
local default_runner_repository="$(cat $SELF_DIR/RUNNER_REPOSITORY)"
|
|
local runner_repository="${1:-${default_runner_repository}}"
|
|
local default_version="$(cat $SELF_DIR/RUNNER_VERSION)"
|
|
local version="${2:-${default_version}}"
|
|
local forgejo="${3:-http://$(cat $DIR/forgejo-ip):3000/}"
|
|
|
|
dependencies
|
|
if [[ "$version" =~ ^@ ]] ; then
|
|
local branch=${version##@}
|
|
build_runner $runner_repository $branch
|
|
else
|
|
download $runner_repository $version
|
|
fi
|
|
register $forgejo
|
|
run
|
|
}
|
|
|
|
function teardown() {
|
|
stop_daemon forgejo-runner
|
|
rm -fr $(cat $DIR/forgejo-runner-home)
|
|
}
|
|
|
|
"$@"
|