mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-11-27 08:40:57 -05:00
move scripts one directory up
This commit is contained in:
parent
73b5ae449f
commit
9628aaca86
4 changed files with 139 additions and 19 deletions
|
@ -3,10 +3,13 @@ jobs:
|
|||
integration:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v3
|
||||
- run: |
|
||||
set -x
|
||||
echo deb http://deb.debian.org/debian bullseye-backports main | tee /etc/apt/sources.list.d/backports.list && apt-get update
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --quiet -y -t bullseye-backports git docker.io
|
||||
|
||||
./forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo:1.19
|
||||
./forgejo-runner.sh setup
|
||||
git remote add test http://root:admin1234@0.0.0.0:8781/actions/forgejo.git
|
||||
git push test
|
||||
|
||||
|
|
29
action.yml
29
action.yml
|
@ -1,23 +1,20 @@
|
|||
name: 'Hello World'
|
||||
description: 'Greet someone'
|
||||
name: 'Forgejo'
|
||||
description: 'Forgejo'
|
||||
inputs:
|
||||
who-to-greet: # id of input
|
||||
description: 'Who to greet'
|
||||
required: true
|
||||
default: 'World'
|
||||
forgejo-image: # id of input
|
||||
description: 'Forgejo image'
|
||||
default: 'codeberg.org/forgejo/forgejo:v1.19'
|
||||
outputs:
|
||||
random-number:
|
||||
description: "Random number"
|
||||
value: ${{ steps.random-number-generator.outputs.random-number }}
|
||||
description: "Token"
|
||||
value: "token"
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- run: echo Hello ${{ inputs.who-to-greet }}.
|
||||
shell: bash
|
||||
- id: random-number-generator
|
||||
run: echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
|
||||
shell: bash
|
||||
- run: goodbye.sh
|
||||
- run: |
|
||||
set -x
|
||||
echo deb http://deb.debian.org/debian bullseye-backports main | tee /etc/apt/sources.list.d/backports.list && apt-get update
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --quiet -y -t bullseye-backports git docker.io
|
||||
./forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo:1.19
|
||||
./forgejo-runner.sh setup
|
||||
shell: bash
|
||||
|
|
65
forgejo-runner.sh
Executable file
65
forgejo-runner.sh
Executable file
|
@ -0,0 +1,65 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
function dependencies() {
|
||||
if ! which go > /dev/null ; then
|
||||
apt-get update
|
||||
apt-get install -y -qq wget tar
|
||||
wget https://go.dev/dl/go1.20.2.linux-amd64.tar.gz
|
||||
tar zxf go1.20.2.linux-amd64.tar.gz
|
||||
export PATH=$PATH:$(pwd)/go/bin
|
||||
fi
|
||||
if ! which make > /dev/null ; then
|
||||
apt-get install -y -qq make
|
||||
fi
|
||||
}
|
||||
|
||||
function checkout() {
|
||||
local git="$1"
|
||||
if ! test -d forgejo-runner ; then
|
||||
git clone $git forgejo-runner
|
||||
fi
|
||||
}
|
||||
|
||||
function build() {
|
||||
local version="$1"
|
||||
|
||||
(
|
||||
cd forgejo-runner
|
||||
git checkout $version
|
||||
make build
|
||||
)
|
||||
}
|
||||
|
||||
function register() {
|
||||
local forgejo="$1"
|
||||
docker exec --user 1000 forgejo forgejo actions --registration-token-admin > forgejo-runner-token
|
||||
timeout --signal=KILL 30 ./forgejo-runner/forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat forgejo-runner-token)
|
||||
}
|
||||
|
||||
function run() {
|
||||
./forgejo-runner/forgejo-runner daemon >& forgejo-runner.log &
|
||||
echo $! > forgejo-runner-pid
|
||||
}
|
||||
|
||||
function setup() {
|
||||
local git="${1:-https://codeberg.org/forgejo/runner}"
|
||||
local version="${1:-v1.4.1}"
|
||||
local forgejo="${1:-http://0.0.0.0:8781/}"
|
||||
|
||||
dependencies
|
||||
checkout $git
|
||||
build $version
|
||||
register $forgejo
|
||||
run
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
if test -f forgejo-runner-pid ; then
|
||||
kill -9 $(cat forgejo-runner-pid)
|
||||
rm -f forgejo-runner-pid
|
||||
fi
|
||||
}
|
||||
|
||||
"$@"
|
55
forgejo.sh
Executable file
55
forgejo.sh
Executable file
|
@ -0,0 +1,55 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
function wait_for() {
|
||||
rm -f /tmp/setup-forgejo.out
|
||||
success=false
|
||||
for delay in 1 1 5 5 15 15 15 30 30 30 30 ; do
|
||||
if "$@" >> /tmp/setup-forgejo.out 2>&1 ; then
|
||||
success=true
|
||||
break
|
||||
fi
|
||||
cat /tmp/setup-forgejo.out
|
||||
echo waiting $delay
|
||||
sleep $delay
|
||||
done
|
||||
if test $success = false ; then
|
||||
cat /tmp/setup-forgejo.out
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function setup() {
|
||||
local user="${1:-root}"
|
||||
local password="${2:-admin1234}"
|
||||
local image="${3:-codeberg.org/forgejo/forgejo:1.19}"
|
||||
|
||||
docker run --name forgejo -p 8781:3000 -p 2721:22 \
|
||||
-e "RUN_MODE=dev" \
|
||||
-e "FORGEJO__security__INSTALL_LOCK=true" \
|
||||
-e "FORGEJO__log__LEVEL=debug" \
|
||||
-e "FORGEJO__server__SSH_PORT=2721" \
|
||||
-e "FORGEJO__actions__ENABLED=true" \
|
||||
-e "FORGEJO__repository__ENABLE_PUSH_CREATE_USER=true" \
|
||||
-e "FORGEJO__repository__DEFAULT_PUSH_CREATE_PRIVATE=true" \
|
||||
-e "FORGEJO__repository__DEFAULT_REPO_UNITS=repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages,actions.actions" \
|
||||
-d $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"
|
||||
else
|
||||
wait_for docker exec --user 1000 forgejo 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 > 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-api && chmod +x forgejo-api
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
docker stop forgejo >& /dev/null || true
|
||||
docker rm -f forgejo >& /dev/null || true
|
||||
}
|
||||
|
||||
"$@"
|
Loading…
Reference in a new issue