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:
earl-warren 2023-12-19 15:53:37 +00:00
commit c7106eb215
16 changed files with 402 additions and 159 deletions

View file

@ -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

View 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)

View file

@ -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)

View 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

View file

@ -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

View file

@ -5,6 +5,12 @@
Setup Forgejo and a runner. 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. The forgejo-test-helper.sh script is available to help test and debug actions.
`forgejo=http://root:admin1234@${{ steps.forgejo.outputs.host-port }}` `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 | Container image | `false` | codeberg.org/forgejo/forgejo |
| image-version | Container image version | `false` | 1.20 | | image-version | Container image version | `false` | 1.20 |
| binary | URL to a Forgejo binary | `false` | |
| user | Administrator user name | `false` | root | | user | Administrator user name | `false` | root |
| password | Administrator password | `false` | admin1234 | | password | Administrator password | `false` | admin1234 |
| runner | Runner repository | `false` | https://code.forgejo.org/forgejo/runner | | 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 | | 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 | | 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 | | install-only | Only install Forgejo and the Forgejo runner, do not launch them | `false` | false |

View file

@ -4,6 +4,12 @@ author: 'Forgejo authors'
description: | description: |
Setup Forgejo and a runner. 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. The forgejo-test-helper.sh script is available to help test and debug actions.
`forgejo=http://root:admin1234@${{ steps.forgejo.outputs.host-port }}` `forgejo=http://root:admin1234@${{ steps.forgejo.outputs.host-port }}`
@ -35,6 +41,8 @@ inputs:
image-version: image-version:
description: 'Container image version' description: 'Container image version'
default: '1.20' default: '1.20'
binary:
description: 'URL to a Forgejo binary'
user: user:
description: 'Administrator user name' description: 'Administrator user name'
default: 'root' default: 'root'
@ -88,10 +96,17 @@ runs:
echo "install-only is true, do not run Forgejo" echo "install-only is true, do not run Forgejo"
exit 0 exit 0
fi fi
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 }} export CONTAINER=${{ inputs.container }}
forgejo.sh setup ${{ inputs.user }} "${{ inputs.password }}" ${{ inputs.image }} ${{ inputs.image-version }} 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/ forgejo-runner.sh setup ${{ inputs.runner }} ${{ inputs.runner-version }} $(cat forgejo-url)
echo url="http://$(cat forgejo-ip):3000" >> $GITHUB_OUTPUT fi
echo url="$(cat forgejo-url)" >> $GITHUB_OUTPUT
echo host-port="$(cat forgejo-ip):3000" >> $GITHUB_OUTPUT echo host-port="$(cat forgejo-ip):3000" >> $GITHUB_OUTPUT
echo token=$(cat forgejo-token) >> $GITHUB_OUTPUT echo token=$(cat forgejo-token) >> $GITHUB_OUTPUT
echo runner-logs="$(pwd)/forgejo-runner.log" >> $GITHUB_OUTPUT echo runner-logs="$(pwd)/forgejo-runner.log" >> $GITHUB_OUTPUT

39
forgejo-binary-app.ini Normal file
View 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
View 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
"$@"

View file

@ -1,10 +1,49 @@
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
set -ex set -e
export DEBIAN_FRONTEND=noninteractive 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() { function dependency_go() {
go_version="1.21.4.linux-amd64" # Set the desired Go version here go_version="1.21.4.linux-amd64" # Set the desired Go version here

View file

@ -1,13 +1,14 @@
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
set -ex set -e
PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: ' PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: '
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 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} : ${FORGEJO_RUNNER_CONFIG:=$SELF_DIR/runner-config.yaml}
: ${DIR:=$(pwd)}
function dependencies() { function dependencies() {
if ! which make curl daemon > /dev/null ; then if ! which make curl daemon > /dev/null ; then
@ -30,24 +31,27 @@ function download() {
function register() { function register() {
local forgejo="$1" local forgejo="$1"
mktemp -d > forgejo-runner-home mktemp -d > $DIR/forgejo-runner-home
docker exec --user 1000 forgejo forgejo actions generate-runner-token > forgejo-runner-token $DIR/forgejocli actions generate-runner-token | tee $DIR/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 (
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() { function run() {
rm -f forgejo-runner.log rm -f $DIR/forgejo-runner.log
daemon --chdir=$(pwd) --unsafe \ daemon --chdir=$DIR --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" \ --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=$(pwd)/forgejo-runner-pid --errlog=$(pwd)/forgejo-runner.log --output=$(pwd)/forgejo-runner.log -- \ --pidfile=$DIR/forgejo-runner-pid --errlog=$DIR/forgejo-runner.log --output=$DIR/forgejo-runner.log -- \
forgejo-runner --config $FORGEJO_RUNNER_CONFIG daemon forgejo-runner --config $FORGEJO_RUNNER_CONFIG daemon
sleep 1 sleep 1
cat forgejo-runner.log cat $DIR/forgejo-runner.log
} }
function reload() { function reload() {
teardown teardown
rm -f forgejo-runner.log rm -f $DIR/forgejo-runner.log
run run
} }
@ -56,7 +60,7 @@ function setup() {
local runner_repository="${1:-${default_runner_repository}}" local runner_repository="${1:-${default_runner_repository}}"
local default_version="$(cat $SELF_DIR/RUNNER_VERSION)" local default_version="$(cat $SELF_DIR/RUNNER_VERSION)"
local version="${2:-${default_version}}" local version="${2:-${default_version}}"
local forgejo="${3:-http://$(cat forgejo-ip):3000/}" local forgejo="${3:-http://$(cat $DIR/forgejo-ip):3000/}"
dependencies dependencies
if [[ "$version" =~ ^@ ]] ; then if [[ "$version" =~ ^@ ]] ; then
@ -69,27 +73,9 @@ function setup() {
run 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() { function teardown() {
stop_daemon forgejo-runner stop_daemon forgejo-runner
rm -fr $(cat forgejo-runner-home) rm -fr $(cat $DIR/forgejo-runner-home)
} }
"$@" "$@"

View file

@ -4,13 +4,15 @@
set -ex set -ex
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $SELF_DIR/forgejo-runner-lib.sh source $SELF_DIR/forgejo-lib.sh
: ${LOOPS:=80} : ${LOOPS:=80}
: ${LOOP_DELAY:=5} : ${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() { function branch_tip() {
local url="$1" local url="$1"
@ -89,7 +91,7 @@ function push() {
local self_action="$5" local self_action="$5"
local token="$6" local token="$6"
local dir="$DIR/$project" local dir="$WORKDIR/$project"
rsync -a --exclude .git $directory/ $dir/ rsync -a --exclude .git $directory/ $dir/
local workflows=$dir/.forgejo/workflows/*.yml local workflows=$dir/.forgejo/workflows/*.yml
@ -139,12 +141,12 @@ function run_workflow() {
local token="$6" local token="$6"
push_workflow "$directory" "$url" "$owner" "$project" "$self_action" "$token" 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() { function clear_runner_cache() {
if test -f forgejo-runner-home ; then if test -f $DIR/forgejo-runner-home ; then
rm -fr $(cat forgejo-runner-home)/.cache/act rm -fr $(cat $DIR/forgejo-runner-home)/.cache/act
fi fi
} }
@ -156,7 +158,7 @@ function push_self_action() {
clear_runner_cache clear_runner_cache
local dir="$DIR/self" local dir="$WORKDIR/self"
git diff --exit-code git diff --exit-code
git clone . $dir git clone . $dir
( (

View file

@ -3,28 +3,12 @@
set -e 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 if ${VERBOSE:-false}; then set -x; fi
: ${CONTAINER:=forgejo} : ${CONTAINER:=forgejo}
: ${RETRY_DELAYS:=1 1 5 5 15 30} : ${DIR:=$(pwd)}
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
}
function run() { function run() {
local image="$1" 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" \ -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 -d $image:$version
local ip="$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" ${CONTAINER})" 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 exec ${CONTAINER} sed -i -e "s|localhost|$ip|" /data/gitea/conf/app.ini
docker restart ${CONTAINER} docker restart ${CONTAINER}
} }
@ -62,21 +49,22 @@ function setup() {
run $image $version run $image $version
sleep 5 # for some reason trying to run "forgejo admin" while forgejo is booting will permanently break everything 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 if $DIR/forgejocli admin user list --admin | grep "$user" ; then
docker exec --user 1000 ${CONTAINER} forgejo admin user change-password --username "$user" --password "$password" $DIR/forgejocli admin user change-password --username "$user" --password "$password"
else 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 fi
# #
# The 'sudo' scope was removed in Forgejo v1.20 and is ignored # 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 echo "http://${user}:${password}@$(cat $DIR/forgejo-ip):3000" > $DIR/forgejo-auth-url
retry forgejo-curl.sh --user "$user" --password "$password" --token @forgejo-token login http://$(cat forgejo-ip):3000 $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 # Redundant with forgejo-curl.sh, kept around for backward compatibility 09/2023
# #
( echo -n 'Authorization: token ' ; cat forgejo-token ) > forgejo-header ( echo -n 'Authorization: token ' ; cat $DIR/forgejo-token ) > $DIR/forgejo-header
( echo "#!/bin/sh" ; echo 'curl -sS -H "Content-Type: application/json" -H @'$(pwd)/forgejo-header' "$@"' ) > forgejo-api && chmod +x forgejo-api ( 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() { function teardown() {

View file

@ -2,8 +2,8 @@ on: [push]
jobs: jobs:
ls: ls:
runs-on: docker runs-on: docker
container:
image: code.forgejo.org/oci/alpine:3.19
steps: steps:
- uses: actions/checkout@v3
- run: | - run: |
ls ${{ github.workspace }} echo ${{ github.workspace }}

View 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 }}