Merge pull request 'automatically build from source if the version is @branch' (#66) from earl-warren/setup-forgejo:wip-version into main

Reviewed-on: https://code.forgejo.org/actions/setup-forgejo/pulls/66
Reviewed-by: dachary <dachary@noreply.code.forgejo.org>
This commit is contained in:
earl-warren 2023-10-15 14:28:21 +00:00
commit 63eec0e8f3
10 changed files with 83 additions and 70 deletions

View file

@ -9,16 +9,8 @@ jobs:
LXC_IP_PREFIX=10.0.9 ./forgejo-dependencies.sh LXC_IP_PREFIX=10.0.9 ./forgejo-dependencies.sh
export PATH=$(pwd):$PATH export PATH=$(pwd):$PATH
forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.20 forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.20
# forgejo-runner.sh setup
# Uncomment the following for a shortcut to debugging the Forgejo runner.
# It will build the runner from a designated repository and branch instead of
# downloading it from a canonical release.
#
# ./forgejo-test-helper.sh build_runner http://code.forgejo.org/forgejo/runner branch-under-debug
# export PATH=$(pwd)/forgejo-runner:$PATH
#
./forgejo-runner.sh setup
export FORGEJO_RUNNER_LOGS=forgejo-runner.log export FORGEJO_RUNNER_LOGS=forgejo-runner.log
echo "============================ sanity-check ===================" 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 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) 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

@ -21,14 +21,6 @@ jobs:
LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh
export PATH=$(pwd):$PATH export PATH=$(pwd):$PATH
forgejo.sh setup root admin1234 ${{ matrix.info.image }} ${{ matrix.info.version }} forgejo.sh setup root admin1234 ${{ matrix.info.image }} ${{ matrix.info.version }}
#
# Uncomment the following for a shortcut to debugging the Forgejo runner.
# It will build the runner from a designated repository and branch instead of
# downloading it from a canonical release.
#
#./forgejo-test-helper.sh build_runner http://code.forgejo.org/earl-warren/runner wip-sync
#export PATH=$(pwd)/forgejo-runner:$PATH
#
forgejo-runner.sh setup forgejo-runner.sh setup
export FORGEJO_RUNNER_LOGS=forgejo-runner.log export FORGEJO_RUNNER_LOGS=forgejo-runner.log
url=http://root:admin1234@$(cat forgejo-ip):3000 url=http://root:admin1234@$(cat forgejo-ip):3000

View file

@ -21,11 +21,6 @@ The forgejo-test-helper.sh script is available to help test and debug actions.
* `forgejo-test-helper.sh push testrepo $forgejo root testrepo` * `forgejo-test-helper.sh push testrepo $forgejo root testrepo`
Creates the repository `$forgejo/root/testrepo` and populates it with the Creates the repository `$forgejo/root/testrepo` and populates it with the
content of the `testrepo` directory. content of the `testrepo` directory.
* `forgejo-test-helper.sh build_runner $forgejo/forgejo/runner v3.0.1`
Builds the forgejo runner from source in `./forgejo-runner/forgejo-runner`.
`export PATH=$(pwd)/forgejo-runner:$PATH` will ensure that calling `forgejo-runner.sh`
will use this binary instead of downloading a released version of the runner.
If the version is not specified, build from the main branch.
The combination of `push_self_action` and `run_workflow` allows to The combination of `push_self_action` and `run_workflow` allows to
run Forgejo Actions workflows from `testrepo` that use the action run Forgejo Actions workflows from `testrepo` that use the action

1
RUNNER_REPOSITORY Normal file
View file

@ -0,0 +1 @@
https://code.forgejo.org/forgejo/runner

1
RUNNER_VERSION Normal file
View file

@ -0,0 +1 @@
v3.0.1

View file

@ -20,11 +20,6 @@ description: |
* `forgejo-test-helper.sh push testrepo $forgejo root testrepo` * `forgejo-test-helper.sh push testrepo $forgejo root testrepo`
Creates the repository `$forgejo/root/testrepo` and populates it with the Creates the repository `$forgejo/root/testrepo` and populates it with the
content of the `testrepo` directory. content of the `testrepo` directory.
* `forgejo-test-helper.sh build_runner $forgejo/forgejo/runner v3.0.1`
Builds the forgejo runner from source in `./forgejo-runner/forgejo-runner`.
`export PATH=$(pwd)/forgejo-runner:$PATH` will ensure that calling `forgejo-runner.sh`
will use this binary instead of downloading a released version of the runner.
If the version is not specified, build from the main branch.
The combination of `push_self_action` and `run_workflow` allows to The combination of `push_self_action` and `run_workflow` allows to
run Forgejo Actions workflows from `testrepo` that use the action run Forgejo Actions workflows from `testrepo` that use the action
@ -47,10 +42,10 @@ inputs:
description: 'Administrator password' description: 'Administrator password'
default: 'admin1234' default: 'admin1234'
runner: runner:
description: 'Runner git repository' description: 'Runner repository'
default: 'https://code.forgejo.org/forgejo/runner' default: 'https://code.forgejo.org/forgejo/runner'
runner-version: runner-version:
description: 'Runner version' description: 'Runner version. If it starts with @ (for instance @featurebranch), the runner will be built from source using the specified branch.'
default: 'v3.0.1' default: 'v3.0.1'
container: container:
description: 'Name of the container running the Forgejo instance' description: 'Name of the container running the Forgejo instance'

42
forgejo-runner-lib.sh Normal file
View file

@ -0,0 +1,42 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
set -ex
export DEBIAN_FRONTEND=noninteractive
function dependency_go() {
go_version="1.21.3.linux-amd64" # Set the desired Go version here
if ! which wget tar > /dev/null ; then
apt-get install -y -qq wget tar
fi
if ! which go > /dev/null ; then
wget --quiet "https://go.dev/dl/go$go_version.tar.gz"
tar zxf "go$go_version.tar.gz"
export PATH="$(pwd)/go/bin:$PATH"
fi
}
function checkout() {
local git="$1"
git clone --depth 1 $git forgejo-runner
}
function build_runner() {
local git="$1"
local version="${2:-main}"
local dir=$(mktemp -d)
(
cd $dir
checkout "$git"
dependency_go
cd forgejo-runner
git checkout "$version"
make build
)
mv $dir/forgejo-runner/forgejo-runner .
./forgejo-runner --version
rm -fr "$dir"
}

View file

@ -3,12 +3,15 @@
set -ex set -ex
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
: ${FORGEJO_RUNNER_CONFIG:=$SELF_DIR/runner-config.yaml} : ${FORGEJO_RUNNER_CONFIG:=$SELF_DIR/runner-config.yaml}
function dependencies() { function dependencies() {
if ! which curl daemon > /dev/null ; then if ! which make curl daemon > /dev/null ; then
apt-get install -y -qq curl daemon apt-get install -y -qq make curl daemon
fi fi
} }
@ -49,12 +52,19 @@ function reload() {
} }
function setup() { function setup() {
local runner_repository="${1:-https://code.forgejo.org/forgejo/runner}" local default_runner_repository="$(cat $SELF_DIR/RUNNER_REPOSITORY)"
local version="${2:-v3.0.1}" 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 forgejo-ip):3000/}"
dependencies dependencies
if [[ "$version" =~ ^@ ]] ; then
local branch=${version##@}
build_runner $runner_repository $branch
else
download $runner_repository $version download $runner_repository $version
fi
register $forgejo register $forgejo
run run
} }

View file

@ -3,7 +3,8 @@
set -ex set -ex
export DEBIAN_FRONTEND=noninteractive SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $SELF_DIR/forgejo-runner-lib.sh
: ${LOOPS:=80} : ${LOOPS:=80}
: ${LOOP_DELAY:=5} : ${LOOP_DELAY:=5}
@ -11,39 +12,6 @@ DIR=$(mktemp -d)
trap "rm -fr $DIR" EXIT trap "rm -fr $DIR" EXIT
function dependency_go() {
go_version="1.21.1.linux-amd64" # Set the desired Go version here
if ! which go > /dev/null ; then
apt-get update
apt-get install -y -qq wget tar
wget --quiet "https://go.dev/dl/go$go_version.tar.gz"
tar zxf "go$go_version.tar.gz"
export PATH="$(pwd)/go/bin:$PATH"
fi
}
function checkout() {
local git="$1"
rm -fr forgejo-runner
git clone $git forgejo-runner
}
function build_runner() {
local git="$1"
local version="${2:-main}"
(
checkout "$git"
dependency_go
cd forgejo-runner
git checkout "$version"
make build
)
export PATH=$PATH:$(pwd)/forgejo-runner
forgejo-runner --version
}
function branch_tip() { function branch_tip() {
local url="$1" local url="$1"
local repo="$2" local repo="$2"

17
utils/upgrade-runner.sh Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
set -e
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
REPOSITORY="$1"
VERSION="$2"
echo $VERSION > $ROOT_DIR/RUNNER_VERSION
sed -i -e 's^| runner-version | Runner version |.*^| runner-version | Runner version | `false` | '$VERSION' |^' $ROOT_DIR/README.md
sed -i -e "/runner-version:/{n;n;s^.*default:.*^ default: '$VERSION'^}" $ROOT_DIR/action.yml
echo $REPOSITORY > $ROOT_DIR/RUNNER_REPOSITORY
sed -i -e 's^| runner | Runner git repository |.*^| runner | Runner git repository | `false` | '$REPOSITORY' |^' $ROOT_DIR/README.md
sed -i -e "/runner:/{n;n;s^.*default:.*^ default: '$REPOSITORY'^}" $ROOT_DIR/action.yml