diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index 5822b44..8341815 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -1,4 +1,4 @@ -on: [ push ] +on: [ push, pull_request ] jobs: integration: runs-on: self-hosted diff --git a/.forgejo/workflows/unit.yml b/.forgejo/workflows/unit.yml deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md index 6aaa822..55a87cb 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ It can only be run on the `self-hosted` platform, running on a host with LXC ins | password | Administrator password | `false` | admin1234 | | runner | Runner git repository | `false` | https://code.forgejo.org/forgejo/runner | | runner-version | Runner version | `false` | v1.4.1 | +| 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 | diff --git a/action.yml b/action.yml index 12522e1..4089ea0 100644 --- a/action.yml +++ b/action.yml @@ -45,6 +45,9 @@ inputs: runner-version: description: 'Runner version' default: 'v1.4.1' + container: + description: 'Name of the container running the Forgejo instance' + default: 'forgejo' lxc-ip-prefix: description: 'Class C IP prefix used by LXC' default: '10.0.23' @@ -71,6 +74,7 @@ runs: run: | cd $(mktemp -d) LXC_IP_PREFIX=${{ inputs.lxc-ip-prefix }} dependencies.sh + 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 diff --git a/forgejo.sh b/forgejo.sh index aa579e2..ad7f13d 100755 --- a/forgejo.sh +++ b/forgejo.sh @@ -1,7 +1,11 @@ #!/bin/bash # SPDX-License-Identifier: MIT -set -ex +set -e + +if ${VERBOSE:-false}; then set -x; fi + +: ${CONTAINER:=forgejo} function wait_for() { rm -f /tmp/setup-forgejo.out @@ -24,7 +28,7 @@ function wait_for() { function run() { local image="$1" - docker run --name forgejo \ + docker run --name ${CONTAINER} \ -e "RUN_MODE=dev" \ -e "FORGEJO__security__INSTALL_LOCK=true" \ -e "FORGEJO__log__LEVEL=debug" \ @@ -33,10 +37,10 @@ function run() { -e "FORGEJO__repository__DEFAULT_PUSH_CREATE_PRIVATE=false" \ -e "FORGEJO__repository__DEFAULT_REPO_UNITS=repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages,actions.actions" \ -d $image - local ip="$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" forgejo)" + local ip="$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" ${CONTAINER})" echo $ip > forgejo-ip - docker exec forgejo sed -i -e "s|localhost|$ip|" /data/gitea/conf/app.ini - docker restart forgejo + docker exec ${CONTAINER} sed -i -e "s|localhost|$ip|" /data/gitea/conf/app.ini + docker restart ${CONTAINER} } function setup() { @@ -47,19 +51,19 @@ function setup() { run $image sleep 5 # for some reason trying to run "forgejo admin" while forgejo is booting will permanently break everything - if docker exec --user 1000 forgejo forgejo admin user list --admin | grep "$user" ; then - docker exec --user 1000 forgejo forgejo admin user change-password --username "$user" --password "$password" + 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" else - wait_for docker exec --user 1000 forgejo forgejo admin user create --admin --username "$user" --password "$password" --email "$user@example.com" + wait_for docker exec --user 1000 ${CONTAINER} forgejo admin user create --admin --username "$user" --password "$password" --email "$user@example.com" fi - docker exec --user 1000 forgejo forgejo admin user generate-access-token -u $user --raw --scopes 'all,sudo' > forgejo-token + docker exec --user 1000 ${CONTAINER} forgejo admin user generate-access-token -u $user --raw --scopes 'all,sudo' > forgejo-token ( 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 } function teardown() { - docker stop forgejo >& /dev/null || true - docker rm -f forgejo >& /dev/null || true + docker stop ${CONTAINER} >& /dev/null || true + docker rm -f ${CONTAINER} >& /dev/null || true } "$@"