mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-11-23 22:40:58 -05:00
basic integration
This commit is contained in:
parent
9628aaca86
commit
d2336cb7ef
5 changed files with 113 additions and 15 deletions
|
@ -10,6 +10,4 @@ jobs:
|
|||
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
|
||||
|
||||
testdata/run.sh main http://root:admin1234@$(cat forgejo-ip):3000 root demo
|
||||
|
|
|
@ -46,7 +46,7 @@ function run() {
|
|||
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/}"
|
||||
local forgejo="${1:-http://$(cat forgejo-ip):3000/}"
|
||||
|
||||
dependencies
|
||||
checkout $git
|
||||
|
|
37
forgejo.sh
37
forgejo.sh
|
@ -20,21 +20,36 @@ function wait_for() {
|
|||
fi
|
||||
}
|
||||
|
||||
function run_docker() {
|
||||
local image="$1"
|
||||
|
||||
}
|
||||
|
||||
function run() {
|
||||
local image="$1"
|
||||
|
||||
docker run --name forgejo \
|
||||
-e "RUN_MODE=dev" \
|
||||
-e "FORGEJO__security__INSTALL_LOCK=true" \
|
||||
-e "FORGEJO__log__LEVEL=debug" \
|
||||
-e "FORGEJO__server__ROOT_URL=http://0.0.0.0:3000/" \
|
||||
-e "FORGEJO__actions__ENABLED=true" \
|
||||
-e "FORGEJO__repository__ENABLE_PUSH_CREATE_USER=true" \
|
||||
-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)"
|
||||
echo $ip > forgejo-ip
|
||||
docker exec forgejo sed -i -e "s|/0.0.0.0:3000/|/$ip:3000/|" /data/gitea/conf/app.ini
|
||||
docker restart forgejo
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
|
@ -44,7 +59,7 @@ function setup() {
|
|||
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
|
||||
( echo "#!/bin/sh" ; echo 'curl -sS -H "Content-Type: application/json" -H @'$(pwd)/forgejo-header' "$@"' ) > forgejo-api && chmod +x forgejo-api
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
|
|
18
testdata/demo.yml
vendored
Normal file
18
testdata/demo.yml
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
name: Demo
|
||||
run-name: ${{ github.actor }} is testing
|
||||
on: [push]
|
||||
jobs:
|
||||
Explore-CI:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event."
|
||||
- run: echo "This job is now running on a ${{ runner.os }} server."
|
||||
- run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
- run: echo "The ${{ github.repository }} repository has been cloned to the runner."
|
||||
- run: echo "The workflow is now ready to test your code on the runner."
|
||||
- name: List files in the repository
|
||||
run: |
|
||||
ls ${{ github.workspace }}
|
||||
- run: echo "This job's status is ${{ job.status }}."
|
67
testdata/run.sh
vendored
Executable file
67
testdata/run.sh
vendored
Executable file
|
@ -0,0 +1,67 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
DATA=$(dirname $0)
|
||||
DIR=$(mktemp -d)
|
||||
|
||||
#trap "rm -fr $DIR" EXIT
|
||||
|
||||
function check_status() {
|
||||
local forgejo="$1"
|
||||
local repo="$2"
|
||||
local sha="$3"
|
||||
|
||||
if ! which jq > /dev/null ; then
|
||||
apt-get install -y -qq jq
|
||||
fi
|
||||
local state=$(curl --fail -sS "$forgejo/api/v1/repos/$repo/commits/$sha/status" | jq --raw-output .state)
|
||||
echo $state
|
||||
test "$state" != "" -a "$state" != "pending" -a "$state" != "running" -a "$state" != "null"
|
||||
}
|
||||
|
||||
function wait_success() {
|
||||
local forgejo="$1"
|
||||
local repo="$2"
|
||||
local sha="$3"
|
||||
|
||||
for i in $(seq 180); do
|
||||
if check_status "$forgejo" "$repo" "$sha"; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
test "$(check_status "$forgejo" "$repo" "$sha")" = "success"
|
||||
}
|
||||
|
||||
function push() {
|
||||
local forgejo="$1"
|
||||
local owner="$2"
|
||||
local workflow="$3"
|
||||
|
||||
mkdir -p $DIR/.forgejo/workflows
|
||||
cp $DATA/$workflow.yml $DIR/.forgejo/workflows
|
||||
(
|
||||
cd $DIR
|
||||
git init
|
||||
git checkout -b main
|
||||
git config user.email root@example.com
|
||||
git config user.name username
|
||||
git add .
|
||||
git commit -m 'initial commit'
|
||||
git remote add origin $forgejo/$owner/$workflow
|
||||
git push --force -u origin main
|
||||
git rev-parse HEAD > SHA
|
||||
)
|
||||
}
|
||||
|
||||
function main() {
|
||||
local forgejo="${1:-http://root:admin1234@$(forgejo-ip):3000}"
|
||||
local owner="${2:-root}"
|
||||
local workflow="${3:-demo}"
|
||||
|
||||
push "$forgejo" "$owner" "$workflow"
|
||||
wait_success "$forgejo" "$owner/$workflow" $(cat $DIR/SHA)
|
||||
}
|
||||
|
||||
"$@"
|
Loading…
Reference in a new issue