mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-11-23 22:00:56 -05:00
67 lines
1.6 KiB
Bash
Executable file
67 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
set -ex
|
|
|
|
function dependencies() {
|
|
if ! which go > /dev/null ; then
|
|
apt-get update
|
|
apt-get install -y -qq wget tar
|
|
wget https://go.dev/dl/go1.20.2.linux-amd64.tar.gz
|
|
tar zxf go1.20.2.linux-amd64.tar.gz
|
|
export PATH=$PATH:$(pwd)/go/bin
|
|
fi
|
|
if ! which make daemon > /dev/null ; then
|
|
apt-get install -y -qq make daemon
|
|
fi
|
|
}
|
|
|
|
function checkout() {
|
|
local git="$1"
|
|
if ! test -d forgejo-runner ; then
|
|
git clone $git forgejo-runner
|
|
fi
|
|
}
|
|
|
|
function build() {
|
|
local version="$1"
|
|
|
|
(
|
|
cd forgejo-runner
|
|
git checkout $version
|
|
make build
|
|
)
|
|
}
|
|
|
|
function register() {
|
|
local forgejo="$1"
|
|
docker exec --user 1000 forgejo forgejo actions --registration-token-admin > forgejo-runner-token
|
|
timeout --signal=KILL 30 ./forgejo-runner/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 ./forgejo-runner/forgejo-runner daemon
|
|
sleep 1
|
|
cat forgejo-runner.log
|
|
}
|
|
|
|
function setup() {
|
|
local git="${1:-https://codeberg.org/forgejo/runner}"
|
|
local version="${2:-v1.4.1}"
|
|
local forgejo="${3:-http://$(cat forgejo-ip):3000/}"
|
|
|
|
dependencies
|
|
checkout $git
|
|
build $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
|
|
}
|
|
|
|
"$@"
|