From d37076a4e9e6ca88217be9a26aa26c5128972ba5 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 27 Mar 2023 17:17:17 +0200 Subject: [PATCH] recursive tests --- .forgejo/workflows/integration.yml | 8 ++- testdata/run.sh | 95 ++++++++++++++++++++++++++ testdata/try-setup-forgejo-release.yml | 11 +++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100755 testdata/run.sh create mode 100644 testdata/try-setup-forgejo-release.yml diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index d8d14ea..b7897b2 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -8,8 +8,14 @@ jobs: uses: https://code.forgejo.org/actions/setup-forgejo@v1 with: user: testuser + password: admin1234 image-version: 1.19 - - run: | + - name: 001 + run: | + testdata/run.sh push_self http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser setup-forgejo-release + testdata/run.sh workflow http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser try-setup-forgejo-release + - name: 002 + run: | set -ex curl -sS ${{ steps.forgejo.outputs.url }}/api/forgejo/v1/version | grep 1.19 export FORGEJO="${{ steps.forgejo.outputs.url }}" diff --git a/testdata/run.sh b/testdata/run.sh new file mode 100755 index 0000000..4f2637e --- /dev/null +++ b/testdata/run.sh @@ -0,0 +1,95 @@ +#!/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 40); do + if check_status "$forgejo" "$repo" "$sha"; then + break + fi + sleep 5 + done + if ! test "$(check_status "$forgejo" "$repo" "$sha")" = "success" ; then + cat forgejo-runner.log + 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}" + local owner="${2}" + local workflow="${3}" + + push "$forgejo" "$owner" "$workflow" + wait_success "$forgejo" "$owner/$workflow" $(cat $DIR/$workflow/SHA) +} + +function push_self() { + local forgejo="$1" + local owner="$2" + local self="$3" + + 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/$self + 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 + ) +} + +"$@" diff --git a/testdata/try-setup-forgejo-release.yml b/testdata/try-setup-forgejo-release.yml new file mode 100644 index 0000000..8fd502f --- /dev/null +++ b/testdata/try-setup-forgejo-release.yml @@ -0,0 +1,11 @@ +name: Setup Forgejo Release +run-name: ${{ github.actor }} is setting up Forgejo Release +on: [push] +jobs: + setup-forgejo: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: SELF/setup-forgejo-release@vTest + - run: | + type forgejo-release.sh