mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-11-30 10:11:03 -05:00
ensure all files are created in a designated directory
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
This commit is contained in:
parent
02ca9d26bf
commit
0dee755317
3 changed files with 43 additions and 30 deletions
|
@ -1,13 +1,14 @@
|
|||
#!/bin/bash
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
set -ex
|
||||
set -e
|
||||
|
||||
PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: '
|
||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $SELF_DIR/forgejo-runner-lib.sh
|
||||
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
|
||||
|
@ -30,24 +31,27 @@ function download() {
|
|||
|
||||
function register() {
|
||||
local forgejo="$1"
|
||||
mktemp -d > forgejo-runner-home
|
||||
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 docker:docker://code.forgejo.org/oci/node:20-bookworm,ubuntu-latest:docker://code.forgejo.org/oci/node:20-buster,self-hosted:lxc://debian:bookworm
|
||||
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 forgejo-runner.log
|
||||
daemon --chdir=$(pwd) --unsafe \
|
||||
--env="TERM=$TERM" --env="HOME=$(cat forgejo-runner-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 -- \
|
||||
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 forgejo-runner.log
|
||||
cat $DIR/forgejo-runner.log
|
||||
}
|
||||
|
||||
function reload() {
|
||||
teardown
|
||||
rm -f forgejo-runner.log
|
||||
rm -f $DIR/forgejo-runner.log
|
||||
run
|
||||
}
|
||||
|
||||
|
@ -56,7 +60,7 @@ function setup() {
|
|||
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 forgejo-ip):3000/}"
|
||||
local forgejo="${3:-http://$(cat $DIR/forgejo-ip):3000/}"
|
||||
|
||||
dependencies
|
||||
if [[ "$version" =~ ^@ ]] ; then
|
||||
|
@ -71,7 +75,7 @@ function setup() {
|
|||
|
||||
function teardown() {
|
||||
stop_daemon forgejo-runner
|
||||
rm -fr $(cat forgejo-runner-home)
|
||||
rm -fr $(cat $DIR/forgejo-runner-home)
|
||||
}
|
||||
|
||||
"$@"
|
||||
|
|
|
@ -4,13 +4,15 @@
|
|||
set -ex
|
||||
|
||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $SELF_DIR/forgejo-runner-lib.sh
|
||||
source $SELF_DIR/forgejo-lib.sh
|
||||
|
||||
: ${LOOPS:=80}
|
||||
: ${LOOP_DELAY:=5}
|
||||
DIR=$(mktemp -d)
|
||||
WORKDIR=$(mktemp -d)
|
||||
: ${DIR:=$(pwd)}
|
||||
export DOT=$DIR
|
||||
|
||||
trap "rm -fr $DIR" EXIT
|
||||
trap "rm -fr $WORKDIR" EXIT
|
||||
|
||||
function branch_tip() {
|
||||
local url="$1"
|
||||
|
@ -89,7 +91,7 @@ function push() {
|
|||
local self_action="$5"
|
||||
local token="$6"
|
||||
|
||||
local dir="$DIR/$project"
|
||||
local dir="$WORKDIR/$project"
|
||||
rsync -a --exclude .git $directory/ $dir/
|
||||
|
||||
local workflows=$dir/.forgejo/workflows/*.yml
|
||||
|
@ -139,12 +141,12 @@ function run_workflow() {
|
|||
local token="$6"
|
||||
|
||||
push_workflow "$directory" "$url" "$owner" "$project" "$self_action" "$token"
|
||||
wait_success "$url" "$owner/$project" $(cat $DIR/$project/SHA)
|
||||
wait_success "$url" "$owner/$project" $(cat $WORKDIR/$project/SHA)
|
||||
}
|
||||
|
||||
function clear_runner_cache() {
|
||||
if test -f forgejo-runner-home ; then
|
||||
rm -fr $(cat forgejo-runner-home)/.cache/act
|
||||
if test -f $DIR/forgejo-runner-home ; then
|
||||
rm -fr $(cat $DIR/forgejo-runner-home)/.cache/act
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -156,7 +158,7 @@ function push_self_action() {
|
|||
|
||||
clear_runner_cache
|
||||
|
||||
local dir="$DIR/self"
|
||||
local dir="$WORKDIR/self"
|
||||
git diff --exit-code
|
||||
git clone . $dir
|
||||
(
|
||||
|
|
25
forgejo.sh
25
forgejo.sh
|
@ -3,9 +3,12 @@
|
|||
|
||||
set -e
|
||||
|
||||
DIR=/tmp
|
||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $SELF_DIR/forgejo-lib.sh
|
||||
|
||||
if ${VERBOSE:-false}; then set -x; fi
|
||||
: ${CONTAINER:=forgejo}
|
||||
: ${DIR:=$(pwd)}
|
||||
|
||||
function run() {
|
||||
local image="$1"
|
||||
|
@ -29,7 +32,10 @@ function run() {
|
|||
-e "FORGEJO__repository__DEFAULT_REPO_UNITS=repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages,$actions_unit" \
|
||||
-d $image:$version
|
||||
local ip="$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" ${CONTAINER})"
|
||||
echo $ip > forgejo-ip
|
||||
echo 'docker exec --user 1000 '${CONTAINER}' forgejo "$@"' > $DIR/forgejocli
|
||||
chmod +x $DIR/forgejocli
|
||||
echo $ip > $DIR/forgejo-ip
|
||||
echo "http://$(cat $DIR/forgejo-ip):3000" > $DIR/forgejo-url
|
||||
docker exec ${CONTAINER} sed -i -e "s|localhost|$ip|" /data/gitea/conf/app.ini
|
||||
docker restart ${CONTAINER}
|
||||
}
|
||||
|
@ -43,21 +49,22 @@ function setup() {
|
|||
run $image $version
|
||||
|
||||
sleep 5 # for some reason trying to run "forgejo admin" while forgejo is booting will permanently break everything
|
||||
if docker exec --user 1000 ${CONTAINER} forgejo admin user list --admin | grep "$user" ; then
|
||||
docker exec --user 1000 ${CONTAINER} forgejo admin user change-password --username "$user" --password "$password"
|
||||
if $DIR/forgejocli admin user list --admin | grep "$user" ; then
|
||||
$DIR/forgejocli admin user change-password --username "$user" --password "$password"
|
||||
else
|
||||
retry docker exec --user 1000 ${CONTAINER} forgejo admin user create --admin --username "$user" --password "$password" --email "$user@example.com"
|
||||
retry $DIR/forgejocli admin user create --admin --username "$user" --password "$password" --email "$user@example.com"
|
||||
fi
|
||||
#
|
||||
# The 'sudo' scope was removed in Forgejo v1.20 and is ignored
|
||||
#
|
||||
docker exec --user 1000 ${CONTAINER} forgejo admin user generate-access-token -u $user --raw --scopes 'all,sudo' > forgejo-token
|
||||
retry forgejo-curl.sh --user "$user" --password "$password" --token @forgejo-token login http://$(cat forgejo-ip):3000
|
||||
echo "http://${user}:${password}@$(cat $DIR/forgejo-ip):3000" > $DIR/forgejo-auth-url
|
||||
$DIR/forgejocli admin user generate-access-token -u $user --raw --scopes 'all,sudo' > $DIR/forgejo-token
|
||||
retry forgejo-curl.sh --user "$user" --password "$password" --token @$DIR/forgejo-token login http://$(cat $DIR/forgejo-ip):3000
|
||||
#
|
||||
# Redundant with forgejo-curl.sh, kept around for backward compatibility 09/2023
|
||||
#
|
||||
( echo -n 'Authorization: token ' ; cat forgejo-token ) > forgejo-header
|
||||
( echo "#!/bin/sh" ; echo 'curl -sS -H "Content-Type: application/json" -H @'$(pwd)/forgejo-header' "$@"' ) > forgejo-api && chmod +x forgejo-api
|
||||
( echo -n 'Authorization: token ' ; cat $DIR/forgejo-token ) > $DIR/forgejo-header
|
||||
( echo "#!/bin/sh" ; echo 'curl -sS -H "Content-Type: application/json" -H @'$DIR/forgejo-header' "$@"' ) > $DIR/forgejo-api && chmod +x $DIR/forgejo-api
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
|
|
Loading…
Reference in a new issue