From 7b5b59d8218d0af95ac20d074351e2615215064d Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sat, 7 Oct 2023 23:27:24 +0200 Subject: [PATCH] do not rely on a hacky way to obtain the sha of the branch --- .forgejo/workflows/integration.yml | 7 ++++--- README.md | 3 +-- action.yml | 3 +-- forgejo-test-helper.sh | 10 +++++++++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index 05bf9fa..d8ee5e1 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -31,10 +31,11 @@ jobs: # forgejo-runner.sh setup export FORGEJO_RUNNER_LOGS=forgejo-runner.log + url=http://root:admin1234@$(cat forgejo-ip):3000 + token=$(cat forgejo-token) echo "============================ demo ===================" - ./forgejo-test-helper.sh run_workflow testdata/demo http://root:admin1234@$(cat forgejo-ip):3000 root demo setup-forgejo $(cat forgejo-token) > /tmp/output - grep '^sha=' /tmp/output + forgejo-test-helper.sh run_workflow testdata/demo $url root demo setup-forgejo $token function run() { local example=$1 @@ -51,7 +52,7 @@ jobs: echo "============================ RUN example-$example ===================" bash -ex $EXAMPLE_DIR/run.sh || return 1 else - forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token) || return 1 + forgejo-test-helper.sh run_workflow testdata/example-$example $url root example-$example setup-forgejo $token || return 1 fi if test -f $EXAMPLE_DIR/teardown.sh ; then diff --git a/README.md b/README.md index 2b18601..f430992 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,7 @@ The forgejo-test-helper.sh script is available to help test and debug actions. `testrepo/.forgejo/workflows/*.yml` are replaced with `$forgejo/root/myaction`. * `forgejo-test-helper.sh push testrepo $forgejo root testrepo` Creates the repository `$forgejo/root/testrepo` and populates it with the - content of the `testrepo` directory. The SHA of the tip of the repository - is in the output, on a line starting with `sha=`. + content of the `testrepo` directory. * `forgejo-test-helper.sh build_runner $forgejo/forgejo/runner v3.0.1` Builds the forgejo runner from source in `./forgejo-runner/forgejo-runner`. `export PATH=$(pwd)/forgejo-runner:$PATH` will ensure that calling `forgejo-runner.sh` diff --git a/action.yml b/action.yml index 086d9e9..a9bc3f4 100644 --- a/action.yml +++ b/action.yml @@ -19,8 +19,7 @@ description: | `testrepo/.forgejo/workflows/*.yml` are replaced with `$forgejo/root/myaction`. * `forgejo-test-helper.sh push testrepo $forgejo root testrepo` Creates the repository `$forgejo/root/testrepo` and populates it with the - content of the `testrepo` directory. The SHA of the tip of the repository - is in the output, on a line starting with `sha=`. + content of the `testrepo` directory. * `forgejo-test-helper.sh build_runner $forgejo/forgejo/runner v3.0.1` Builds the forgejo runner from source in `./forgejo-runner/forgejo-runner`. `export PATH=$(pwd)/forgejo-runner:$PATH` will ensure that calling `forgejo-runner.sh` diff --git a/forgejo-test-helper.sh b/forgejo-test-helper.sh index 01dae72..39ccca9 100755 --- a/forgejo-test-helper.sh +++ b/forgejo-test-helper.sh @@ -44,6 +44,15 @@ function build_runner() { forgejo-runner --version } +function branch_tip() { + local url="$1" + local repo="$2" + local branch="$3" + + forgejo.sh retry forgejo-curl.sh api_json $url/api/v1/repos/$repo/branches/$branch >& /dev/null + forgejo-curl.sh api_json $url/api/v1/repos/$repo/branches/$branch | jq --raw-output .commit.id +} + function get_status() { local url="$1" local repo="$2" @@ -111,7 +120,6 @@ function push() { git push --force -u origin main sha=$(git rev-parse HEAD) echo $sha > SHA - echo sha=$sha ) }