1
0
Fork 0
mirror of https://code.forgejo.org/actions/setup-forgejo synced 2025-07-09 02:06:00 +02:00

basic integration

This commit is contained in:
Earl Warren 2023-03-25 14:34:41 +01:00
parent 9628aaca86
commit d2336cb7ef
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
5 changed files with 113 additions and 15 deletions

18
testdata/demo.yml vendored Normal file
View 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
View 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)
}
"$@"