mirror of
https://code.forgejo.org/actions/setup-forgejo
synced 2025-07-12 19:56:00 +02:00
refactor and publish forgejo-test-helper.sh
This commit is contained in:
parent
202709a555
commit
5e74823706
8 changed files with 156 additions and 121 deletions
18
testdata/demo.yml
vendored
18
testdata/demo.yml
vendored
|
@ -1,18 +0,0 @@
|
|||
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 }}."
|
9
testdata/demo/.forgejo/workflows/test.yml
vendored
Normal file
9
testdata/demo/.forgejo/workflows/test.yml
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
on: [push]
|
||||
jobs:
|
||||
ls:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: |
|
||||
ls ${{ github.workspace }}
|
||||
|
96
testdata/run.sh
vendored
96
testdata/run.sh
vendored
|
@ -1,96 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
: ${FORGEJO_RUNNER_LOGS:=forgejo-runner.log}
|
||||
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 40); do
|
||||
if check_status "$forgejo" "$repo" "$sha"; then
|
||||
break
|
||||
fi
|
||||
tail $FORGEJO_RUNNER_LOGS
|
||||
sleep 5
|
||||
done
|
||||
if ! test "$(check_status "$forgejo" "$repo" "$sha")" = "success" ; then
|
||||
cat $FORGEJO_RUNNER_LOGS
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function push() {
|
||||
local forgejo="$1"
|
||||
local owner="$2"
|
||||
local workflow="$3"
|
||||
|
||||
local dir="$DIR/$workflow"
|
||||
mkdir -p $dir/.forgejo/workflows
|
||||
sed -e "s|SELF|$forgejo/$owner|" \
|
||||
< $DATA/$workflow.yml > $dir/.forgejo/workflows/$workflow.yml
|
||||
(
|
||||
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 workflow() {
|
||||
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/$workflow/SHA)
|
||||
}
|
||||
|
||||
function push_self() {
|
||||
local forgejo="$1"
|
||||
local owner="$2"
|
||||
|
||||
local dir="$DIR/self"
|
||||
git clone . $dir
|
||||
(
|
||||
cd $dir
|
||||
rm -fr .forgejo .git
|
||||
git init
|
||||
git checkout -b main
|
||||
git remote add origin $forgejo/$owner/setup-forgejo
|
||||
git config user.email root@example.com
|
||||
git config user.name username
|
||||
git add .
|
||||
git commit -m 'initial commit'
|
||||
git push --force origin main
|
||||
git tag --force vTest HEAD
|
||||
git push --force origin vTest
|
||||
)
|
||||
}
|
||||
|
||||
"$@"
|
|
@ -7,7 +7,7 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- id: forgejo
|
||||
uses: SELF/setup-forgejo@vTest
|
||||
uses: SELF@vTest
|
||||
with:
|
||||
image-version: 1.19
|
||||
- run: |
|
Loading…
Add table
Add a link
Reference in a new issue