mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-11-27 08:40:57 -05:00
65 lines
1.5 KiB
Bash
Executable file
65 lines
1.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
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 > /dev/null ; then
|
|
apt-get install -y -qq make
|
|
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() {
|
|
./forgejo-runner/forgejo-runner daemon >& forgejo-runner.log &
|
|
echo $! > forgejo-runner-pid
|
|
}
|
|
|
|
function setup() {
|
|
local git="${1:-https://codeberg.org/forgejo/runner}"
|
|
local version="${1:-v1.4.1}"
|
|
local forgejo="${1:-http://$(cat forgejo-ip):3000/}"
|
|
|
|
dependencies
|
|
checkout $git
|
|
build $version
|
|
register $forgejo
|
|
run
|
|
}
|
|
|
|
function teardown() {
|
|
if test -f forgejo-runner-pid ; then
|
|
kill -9 $(cat forgejo-runner-pid)
|
|
rm -f forgejo-runner-pid
|
|
fi
|
|
}
|
|
|
|
"$@"
|