mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-12-25 22:32:12 -05:00
Merge pull request 'forgejo-binary.sh instead of always running from OCI' (#108) from earl-warren/setup-forgejo:wip-binary into main
Reviewed-on: https://code.forgejo.org/actions/setup-forgejo/pulls/108 Reviewed-by: dachary <dachary@noreply.code.forgejo.org>
This commit is contained in:
commit
c7106eb215
16 changed files with 402 additions and 159 deletions
|
@ -1,28 +0,0 @@
|
|||
on:
|
||||
push:
|
||||
paths:
|
||||
- forgejo.sh
|
||||
- .forgejo/workflows/forgejo-sh.yml
|
||||
pull_request:
|
||||
paths:
|
||||
- forgejo.sh
|
||||
- .forgejo/workflows/forgejo-sh.yml
|
||||
|
||||
jobs:
|
||||
forgejo-sh:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: |
|
||||
set -x
|
||||
export PATH=$(pwd):$PATH
|
||||
forgejo-dependencies.sh install_docker
|
||||
(
|
||||
echo codeberg.org/forgejo/forgejo 1.19.4-0
|
||||
echo codeberg.org/forgejo/forgejo 1.20.5-0
|
||||
echo codeberg.org/forgejo-experimental/forgejo 1.21.0-7-rc2
|
||||
) | while read url version ; do
|
||||
echo "=========================== launching forgejo v$version =========="
|
||||
forgejo.sh setup root admin1234 $url $version
|
||||
forgejo.sh teardown
|
||||
done
|
33
.forgejo/workflows/integration-action.yml
Normal file
33
.forgejo/workflows/integration-action.yml
Normal file
|
@ -0,0 +1,33 @@
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
- 'v*'
|
||||
pull_request:
|
||||
|
||||
#
|
||||
# Testing that action.yml works as intended, the other tests do not do hat.
|
||||
#
|
||||
jobs:
|
||||
integration-action:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: forgejo.sh & forgejo-runner.sh
|
||||
run: |
|
||||
LXC_IP_PREFIX=10.0.9 ./forgejo-dependencies.sh
|
||||
export PATH=$(pwd):$PATH
|
||||
forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.20
|
||||
forgejo-runner.sh setup
|
||||
echo "============================ upload setup-forgejo ==================="
|
||||
forgejo-test-helper.sh push_self_action $(cat forgejo-auth-url) root setup-forgejo vTest
|
||||
- name: lxc-run-forgejo-binary
|
||||
run: |
|
||||
export PATH=$(pwd):$PATH
|
||||
export FORGEJO_RUNNER_LOGS=forgejo-runner.log
|
||||
forgejo-test-helper.sh run_workflow testdata/lxc-run-forgejo-binary $(cat forgejo-auth-url) root lxc-run-forgejo-binary setup-forgejo $(cat forgejo-token)
|
||||
- name: lxc-run-forgejo-oci
|
||||
run: |
|
||||
export PATH=$(pwd):$PATH
|
||||
export FORGEJO_RUNNER_LOGS=forgejo-runner.log
|
||||
forgejo-test-helper.sh run_workflow testdata/lxc-run-forgejo-oci $(cat forgejo-auth-url) root lxc-run-forgejo-oci setup-forgejo $(cat forgejo-token)
|
|
@ -1,22 +0,0 @@
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
- 'v*'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
integration-nested:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: |
|
||||
set -x
|
||||
LXC_IP_PREFIX=10.0.9 ./forgejo-dependencies.sh
|
||||
export PATH=$(pwd):$PATH
|
||||
forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.20
|
||||
forgejo-runner.sh setup
|
||||
export FORGEJO_RUNNER_LOGS=forgejo-runner.log
|
||||
echo "============================ sanity-check ==================="
|
||||
forgejo-test-helper.sh push_self_action http://root:admin1234@$(cat forgejo-ip):3000 root setup-forgejo vTest
|
||||
forgejo-test-helper.sh run_workflow testdata/sanity-checks http://root:admin1234@$(cat forgejo-ip):3000 root sanity-check setup-forgejo $(cat forgejo-token)
|
70
.forgejo/workflows/integration-scripts.yml
Normal file
70
.forgejo/workflows/integration-scripts.yml
Normal file
|
@ -0,0 +1,70 @@
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
- 'v*'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
integration:
|
||||
runs-on: self-hosted
|
||||
strategy:
|
||||
matrix:
|
||||
info:
|
||||
- version: "1.21"
|
||||
image: codeberg.org/forgejo/forgejo
|
||||
- version: "1.20"
|
||||
image: codeberg.org/forgejo/forgejo
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- shell: bash
|
||||
run: |
|
||||
LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh
|
||||
export PATH=$(pwd):$PATH
|
||||
forgejo.sh setup root admin1234 ${{ matrix.info.image }} ${{ matrix.info.version }}
|
||||
forgejo-runner.sh setup
|
||||
export FORGEJO_RUNNER_LOGS=forgejo-runner.log
|
||||
url=http://root:admin1234@$(cat forgejo-ip):3000
|
||||
token=$(cat forgejo-token)
|
||||
|
||||
echo "============================ demo ==================="
|
||||
forgejo-test-helper.sh run_workflow testdata/demo $url root demo setup-forgejo $token
|
||||
echo "============================ IPv6 ==================="
|
||||
forgejo-test-helper.sh run_workflow testdata/ipv6 $url root ipv6 setup-forgejo $token
|
||||
|
||||
binary:
|
||||
runs-on: self-hosted
|
||||
strategy:
|
||||
matrix:
|
||||
- binary: https://codeberg.org/forgejo/forgejo/releases/download/v1.21.2-1/forgejo-1.21.2-1-linux-amd64
|
||||
- binary: https://codeberg.org/forgejo/forgejo/releases/download/v1.20.6-1/forgejo-1.20.6-1-linux-amd64
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- shell: bash
|
||||
run: |
|
||||
set -x
|
||||
export DIR=$(mktemp -d)
|
||||
export PATH=$(pwd):$PATH
|
||||
LXC_IP_PREFIX=10.0.10 forgejo-dependencies.sh
|
||||
|
||||
forgejo-binary.sh ensure_user forgejo
|
||||
chown forgejo $DIR /usr/local/bin
|
||||
su -c "DIR=$DIR bash -x forgejo-binary.sh setup root admin1234 ${{ matrix.binary }}" forgejo
|
||||
|
||||
su -c "DIR=$DIR bash -x forgejo-runner.sh setup" forgejo
|
||||
export FORGEJO_RUNNER_LOGS=$DIR/forgejo-runner.log
|
||||
url=$(cat $DIR/forgejo-auth-url)
|
||||
token=$(cat $DIR/forgejo-token)
|
||||
|
||||
echo "============================ demo ==================="
|
||||
FORGEJO_RUNNER_DIR=$DIR forgejo-test-helper.sh run_workflow testdata/demo $url root demo setup-forgejo $token
|
||||
|
||||
su -c "DIR=$DIR forgejo-binary.sh teardown" forgejo
|
||||
|
||||
echo "============================ verify zip downloading ==================="
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt -q install -qq -y zip
|
||||
mv $DIR/forgejo /tmp/forgejo
|
||||
( cd /tmp ; zip forgejo.zip forgejo )
|
||||
forgejo-binary.sh download file:///tmp/forgejo.zip
|
||||
cmp --quiet /tmp/forgejo $DIR/forgejo
|
|
@ -1,33 +0,0 @@
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
- 'v*'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
integration:
|
||||
runs-on: self-hosted
|
||||
strategy:
|
||||
matrix:
|
||||
info:
|
||||
- version: "1.21"
|
||||
image: codeberg.org/forgejo/forgejo
|
||||
- version: "1.20"
|
||||
image: codeberg.org/forgejo/forgejo
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- shell: bash
|
||||
run: |
|
||||
LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh
|
||||
export PATH=$(pwd):$PATH
|
||||
forgejo.sh setup root admin1234 ${{ matrix.info.image }} ${{ matrix.info.version }}
|
||||
forgejo-runner.sh setup
|
||||
export FORGEJO_RUNNER_LOGS=forgejo-runner.log
|
||||
url=http://root:admin1234@$(cat forgejo-ip):3000
|
||||
token=$(cat forgejo-token)
|
||||
|
||||
echo "============================ demo ==================="
|
||||
forgejo-test-helper.sh run_workflow testdata/demo $url root demo setup-forgejo $token
|
||||
echo "============================ IPv6 ==================="
|
||||
forgejo-test-helper.sh run_workflow testdata/ipv6 $url root ipv6 setup-forgejo $token
|
|
@ -5,6 +5,12 @@
|
|||
|
||||
Setup Forgejo and a runner.
|
||||
|
||||
If `binary` is specified, Forgejo downloads the binary from the URL and uses
|
||||
it to start an instance.
|
||||
|
||||
Otherwise, `image` and `image-version` must be specified and Forgejo
|
||||
runs from the corresponding container image using docker.
|
||||
|
||||
The forgejo-test-helper.sh script is available to help test and debug actions.
|
||||
|
||||
`forgejo=http://root:admin1234@${{ steps.forgejo.outputs.host-port }}`
|
||||
|
@ -40,10 +46,11 @@ that [provides a LXC container](https://forgejo.org/docs/next/user/actions/#jobs
|
|||
| --- | --- | --- | --- |
|
||||
| image | Container image | `false` | codeberg.org/forgejo/forgejo |
|
||||
| image-version | Container image version | `false` | 1.20 |
|
||||
| binary | URL to a Forgejo binary | `false` | |
|
||||
| user | Administrator user name | `false` | root |
|
||||
| password | Administrator password | `false` | admin1234 |
|
||||
| runner | Runner repository | `false` | https://code.forgejo.org/forgejo/runner |
|
||||
| runner-version | Runner version. If it starts with @ (for instance @featurebranch), the runner will be built from source using the specified branch. | `false` | v3.0.1 |
|
||||
| runner-version | Runner version. If it starts with @ (for instance @featurebranch), the runner will be built from source using the specified branch. | `false` | v3.3.0 |
|
||||
| container | Name of the container running the Forgejo instance | `false` | forgejo |
|
||||
| lxc-ip-prefix | Class C IP prefix used by LXC | `false` | 10.0.23 |
|
||||
| install-only | Only install Forgejo and the Forgejo runner, do not launch them | `false` | false |
|
||||
|
|
23
action.yml
23
action.yml
|
@ -4,6 +4,12 @@ author: 'Forgejo authors'
|
|||
description: |
|
||||
Setup Forgejo and a runner.
|
||||
|
||||
If `binary` is specified, Forgejo downloads the binary from the URL and uses
|
||||
it to start an instance.
|
||||
|
||||
Otherwise, `image` and `image-version` must be specified and Forgejo
|
||||
runs from the corresponding container image using docker.
|
||||
|
||||
The forgejo-test-helper.sh script is available to help test and debug actions.
|
||||
|
||||
`forgejo=http://root:admin1234@${{ steps.forgejo.outputs.host-port }}`
|
||||
|
@ -35,6 +41,8 @@ inputs:
|
|||
image-version:
|
||||
description: 'Container image version'
|
||||
default: '1.20'
|
||||
binary:
|
||||
description: 'URL to a Forgejo binary'
|
||||
user:
|
||||
description: 'Administrator user name'
|
||||
default: 'root'
|
||||
|
@ -88,10 +96,17 @@ runs:
|
|||
echo "install-only is true, do not run Forgejo"
|
||||
exit 0
|
||||
fi
|
||||
export CONTAINER=${{ inputs.container }}
|
||||
forgejo.sh setup ${{ inputs.user }} "${{ inputs.password }}" ${{ inputs.image }} ${{ inputs.image-version }}
|
||||
forgejo-runner.sh setup ${{ inputs.runner }} ${{ inputs.runner-version }} http://$(cat forgejo-ip):3000/
|
||||
echo url="http://$(cat forgejo-ip):3000" >> $GITHUB_OUTPUT
|
||||
if test "${{ inputs.binary }}"; then
|
||||
forgejo-binary.sh ensure_user forgejo
|
||||
chown forgejo $(pwd) /usr/local/bin
|
||||
su -c "DIR=$(pwd) forgejo-binary.sh setup ${{ inputs.user }} ${{ inputs.password }} ${{ inputs.binary }}" forgejo
|
||||
su -c "DIR=$(pwd) forgejo-runner.sh setup ${{ inputs.runner }} ${{ inputs.runner-version }} $(cat forgejo-url)" forgejo
|
||||
else
|
||||
export CONTAINER=${{ inputs.container }}
|
||||
forgejo.sh setup ${{ inputs.user }} "${{ inputs.password }}" ${{ inputs.image }} ${{ inputs.image-version }}
|
||||
forgejo-runner.sh setup ${{ inputs.runner }} ${{ inputs.runner-version }} $(cat forgejo-url)
|
||||
fi
|
||||
echo url="$(cat forgejo-url)" >> $GITHUB_OUTPUT
|
||||
echo host-port="$(cat forgejo-ip):3000" >> $GITHUB_OUTPUT
|
||||
echo token=$(cat forgejo-token) >> $GITHUB_OUTPUT
|
||||
echo runner-logs="$(pwd)/forgejo-runner.log" >> $GITHUB_OUTPUT
|
||||
|
|
39
forgejo-binary-app.ini
Normal file
39
forgejo-binary-app.ini
Normal file
|
@ -0,0 +1,39 @@
|
|||
RUN_MODE = prod
|
||||
WORK_PATH = ${WORK_PATH}
|
||||
|
||||
[server]
|
||||
APP_DATA_PATH = ${WORK_PATH}/data
|
||||
HTTP_PORT = 3000
|
||||
LFS_START_SERVER = true
|
||||
|
||||
[database]
|
||||
DB_TYPE = sqlite3
|
||||
PATH = ${WORK_PATH}/forgejo.db
|
||||
|
||||
[log]
|
||||
MODE = file
|
||||
LEVEL = trace
|
||||
ROUTER = file
|
||||
|
||||
[log.file]
|
||||
FILE_NAME = forgejo.log
|
||||
|
||||
[security]
|
||||
INSTALL_LOCK = true
|
||||
|
||||
[repository]
|
||||
ENABLE_PUSH_CREATE_USER = true
|
||||
DEFAULT_PUSH_CREATE_PRIVATE = false
|
||||
DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages,repo.actions
|
||||
|
||||
[actions]
|
||||
ENABLED = true
|
||||
|
||||
[queue]
|
||||
TYPE = immediate
|
||||
|
||||
[queue.code_indexer]
|
||||
TYPE = immediate
|
||||
|
||||
[queue.push_update]
|
||||
TYPE = immediate
|
121
forgejo-binary.sh
Executable file
121
forgejo-binary.sh
Executable file
|
@ -0,0 +1,121 @@
|
|||
#!/bin/bash
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
set -e
|
||||
|
||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $SELF_DIR/forgejo-lib.sh
|
||||
|
||||
: ${DIR:=/tmp/forgejo-binary}
|
||||
|
||||
if ${VERBOSE:-false}; then set -x; fi
|
||||
|
||||
function maybe_sudo() {
|
||||
if test $(id -u) != 0 ; then
|
||||
SUDO=sudo
|
||||
fi
|
||||
}
|
||||
|
||||
function ensure_user() {
|
||||
local user=$1
|
||||
|
||||
dependencies
|
||||
adduser --quiet --comment $user --disabled-password $user
|
||||
adduser $user sudo
|
||||
adduser $user docker
|
||||
sed -i -e 's/^%sudo.*/%sudo ALL=(ALL:ALL) NOPASSWD:ALL/' /etc/sudoers
|
||||
}
|
||||
|
||||
function dependencies() {
|
||||
maybe_sudo
|
||||
if ! which sudo curl daemon jq git-lfs ip sqlite3 envsubst unzip > /dev/null ; then
|
||||
$SUDO apt-get update -qq
|
||||
$SUDO apt-get -q install -y -qq sudo curl daemon jq git-lfs iproute2 sqlite3 gettext-base unzip
|
||||
fi
|
||||
}
|
||||
|
||||
function cleanup_logs() {
|
||||
local work_path=$DIR/forgejo-work-path
|
||||
|
||||
rm -f $DIR/*.log
|
||||
rm -f $work_path/log/*.log
|
||||
}
|
||||
|
||||
function download() {
|
||||
local url="$1"
|
||||
|
||||
if ! test -f $DIR/forgejo ; then
|
||||
curl -sS $url > $DIR/forgejo.tmp
|
||||
if file $DIR/forgejo.tmp | grep --quiet 'Zip archive' ; then
|
||||
unzip $DIR/forgejo.tmp -d $DIR
|
||||
rm -f $DIR/forgejo.tmp
|
||||
else
|
||||
mv $DIR/forgejo.tmp $DIR/forgejo
|
||||
fi
|
||||
chmod +x $DIR/forgejo
|
||||
fi
|
||||
echo $DIR/forgejo --version
|
||||
$DIR/forgejo --version
|
||||
}
|
||||
|
||||
function create_user() {
|
||||
local user="$1"
|
||||
local password="$2"
|
||||
local work_path=$DIR/forgejo-work-path
|
||||
|
||||
if test -f $work_path/forgejo-token; then
|
||||
return
|
||||
fi
|
||||
|
||||
$DIR/forgejocli admin user create --admin --username "$user" --password "$password" --email "$user@example.com"
|
||||
$DIR/forgejocli admin user generate-access-token -u "$user" --raw --scopes all > $DIR/forgejo-token
|
||||
export DOT=$DIR
|
||||
local url="http://$(cat $DIR/forgejo-ip):3000"
|
||||
echo "$url" > $DIR/forgejo-url
|
||||
echo "http://${user}:${password}@$(cat $DIR/forgejo-ip):3000" > $DIR/forgejo-auth-url
|
||||
retry forgejo-curl.sh --user "$user" --password "$password" --token @$DIR/forgejo-token login "$url"
|
||||
echo forgejo-curl.sh api_json $url/api/forgejo/v1/version
|
||||
forgejo-curl.sh api_json $url/api/forgejo/v1/version
|
||||
}
|
||||
|
||||
function start_forgejo() {
|
||||
local work_path=$DIR/forgejo-work-path
|
||||
daemon --chdir=$DIR --unsafe --env="TERM=$TERM" --env="HOME=$HOME" --env="PATH=$PATH" --pidfile=$DIR/forgejo-pid --errlog=$DIR/forgejo-err.log --output=$DIR/forgejo-out.log -- $DIR/forgejo --config $work_path/app.ini --work-path $work_path
|
||||
if ! retry grep 'Starting server on' $work_path/log/forgejo.log ; then
|
||||
cat $DIR/*.log
|
||||
cat $work_path/log/*.log
|
||||
return 1
|
||||
fi
|
||||
echo "$DIR/forgejo --config $work_path/app.ini --work-path $work_path" '"$@"' > $DIR/forgejocli
|
||||
chmod +x $DIR/forgejocli
|
||||
hostname -I | cut -f1 -d' ' > $DIR/forgejo-ip
|
||||
}
|
||||
|
||||
function reset_forgejo() {
|
||||
local config=$1
|
||||
local work_path=$DIR/forgejo-work-path
|
||||
rm -fr $work_path
|
||||
mkdir -p $work_path
|
||||
WORK_PATH=$work_path envsubst < $SELF_DIR/$config-app.ini > $work_path/app.ini
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
stop_daemon forgejo $DIR
|
||||
cleanup_logs
|
||||
}
|
||||
|
||||
function setup() {
|
||||
local user="${1:-root}"
|
||||
local password="${2:-admin1234}"
|
||||
local url="${3:-https://codeberg.org/forgejo/forgejo/releases/download/v1.21.2-1/forgejo-1.21.2-1-linux-amd64}"
|
||||
|
||||
dependencies
|
||||
download "$url"
|
||||
reset_forgejo forgejo-binary
|
||||
start_forgejo
|
||||
create_user "$user" "$password"
|
||||
}
|
||||
|
||||
mkdir -p $DIR
|
||||
|
||||
"$@"
|
|
@ -1,10 +1,49 @@
|
|||
#!/bin/bash
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
set -ex
|
||||
set -e
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
: ${RETRY_DELAYS:=1 1 5 5 15 30}
|
||||
|
||||
function retry() {
|
||||
local tmp=/tmp
|
||||
rm -f $tmp/retry.out
|
||||
success=false
|
||||
for delay in $RETRY_DELAYS ; do
|
||||
if "$@" >> $tmp/retry.out 2>&1 ; then
|
||||
success=true
|
||||
break
|
||||
fi
|
||||
cat $tmp/retry.out
|
||||
echo waiting $delay
|
||||
sleep $delay
|
||||
done
|
||||
if test $success = false ; then
|
||||
cat $tmp/retry.out
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function stop_daemon() {
|
||||
local daemon=$1
|
||||
local dir=${2:-.}
|
||||
|
||||
if test -f $dir/$daemon-pid ; then
|
||||
local pid=$(cat $dir/$daemon-pid)
|
||||
kill -TERM $pid
|
||||
pidwait $pid || true
|
||||
for delay in 1 1 2 2 5 5 ; do
|
||||
if ! test -f $dir/$daemon-pid ; then
|
||||
break
|
||||
fi
|
||||
sleep $delay
|
||||
done
|
||||
! test -f $dir/$daemon-pid
|
||||
fi
|
||||
}
|
||||
|
||||
function dependency_go() {
|
||||
go_version="1.21.4.linux-amd64" # Set the desired Go version here
|
||||
|
|
@ -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:16-bullseye,ubuntu-latest:docker://code.forgejo.org/oci/node:16-buster,self-hosted:lxc://debian:bullseye
|
||||
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
|
||||
|
@ -69,27 +73,9 @@ function setup() {
|
|||
run
|
||||
}
|
||||
|
||||
function stop_daemon() {
|
||||
local daemon=$1
|
||||
local DIR=.
|
||||
|
||||
if test -f $DIR/$daemon-pid ; then
|
||||
local pid=$(cat $DIR/$daemon-pid)
|
||||
kill -TERM $pid
|
||||
pidwait $pid || true
|
||||
for delay in 1 1 2 2 5 5 ; do
|
||||
if ! test -f $DIR/$daemon-pid ; then
|
||||
break
|
||||
fi
|
||||
sleep $delay
|
||||
done
|
||||
! test -f $DIR/$daemon-pid
|
||||
fi
|
||||
}
|
||||
|
||||
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
|
||||
(
|
||||
|
|
44
forgejo.sh
44
forgejo.sh
|
@ -3,28 +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}
|
||||
: ${RETRY_DELAYS:=1 1 5 5 15 30}
|
||||
|
||||
function retry() {
|
||||
rm -f $DIR/retry.out
|
||||
success=false
|
||||
for delay in $RETRY_DELAYS ; do
|
||||
if "$@" >> $DIR/retry.out 2>&1 ; then
|
||||
success=true
|
||||
break
|
||||
fi
|
||||
cat $DIR/retry.out
|
||||
echo waiting $delay
|
||||
sleep $delay
|
||||
done
|
||||
if test $success = false ; then
|
||||
cat $DIR/retry.out
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
: ${DIR:=$(pwd)}
|
||||
|
||||
function run() {
|
||||
local image="$1"
|
||||
|
@ -48,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}
|
||||
}
|
||||
|
@ -62,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() {
|
||||
|
|
6
testdata/demo/.forgejo/workflows/test.yml
vendored
6
testdata/demo/.forgejo/workflows/test.yml
vendored
|
@ -2,8 +2,8 @@ on: [push]
|
|||
jobs:
|
||||
ls:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: code.forgejo.org/oci/alpine:3.19
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: |
|
||||
ls ${{ github.workspace }}
|
||||
|
||||
echo ${{ github.workspace }}
|
||||
|
|
26
testdata/lxc-run-forgejo-binary/.forgejo/workflows/test.yml
vendored
Normal file
26
testdata/lxc-run-forgejo-binary/.forgejo/workflows/test.yml
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
# SPDX-License-Identifier: MIT
|
||||
on: [push]
|
||||
jobs:
|
||||
setup-binary:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- run: |
|
||||
echo +++++++++++++++++++++++++++++++++++++++++++
|
||||
echo about to actions/checkout@v3 for SELF@vTest
|
||||
- uses: actions/checkout@v3
|
||||
- id: forgejo
|
||||
uses: SELF@vTest
|
||||
with:
|
||||
binary: https://codeberg.org/forgejo/forgejo/releases/download/v1.20.6-1/forgejo-1.20.6-1-linux-amd64
|
||||
- run: |
|
||||
echo +++++++++++++++++++++++++++++++++++++++++++
|
||||
echo sanity checking the reset of setup-forgejo
|
||||
set -ex
|
||||
test "${{ steps.forgejo.outputs.token }}"
|
||||
test "FORGEJO_TOKEN" -a "FORGEJO_TOKEN" != F'O'RGEJO_TOKEN
|
||||
curl ${{ steps.forgejo.outputs.url }}/api/forgejo/v1/version >& version.out
|
||||
if ! grep --quiet 1.20 version.out ; then
|
||||
cat version.out
|
||||
exit 1
|
||||
fi
|
||||
test -f ${{ steps.forgejo.outputs.runner-file }}
|
Loading…
Reference in a new issue