do not rely on a hacky way to obtain the sha of the branch

This commit is contained in:
Earl Warren 2023-10-07 23:27:24 +02:00
parent 179856df25
commit 7b5b59d821
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
4 changed files with 15 additions and 8 deletions

View file

@ -31,10 +31,11 @@ jobs:
# #
forgejo-runner.sh setup forgejo-runner.sh setup
export FORGEJO_RUNNER_LOGS=forgejo-runner.log export FORGEJO_RUNNER_LOGS=forgejo-runner.log
url=http://root:admin1234@$(cat forgejo-ip):3000
token=$(cat forgejo-token)
echo "============================ demo ===================" 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 forgejo-test-helper.sh run_workflow testdata/demo $url root demo setup-forgejo $token
grep '^sha=' /tmp/output
function run() { function run() {
local example=$1 local example=$1
@ -51,7 +52,7 @@ jobs:
echo "============================ RUN example-$example ===================" echo "============================ RUN example-$example ==================="
bash -ex $EXAMPLE_DIR/run.sh || return 1 bash -ex $EXAMPLE_DIR/run.sh || return 1
else 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 fi
if test -f $EXAMPLE_DIR/teardown.sh ; then if test -f $EXAMPLE_DIR/teardown.sh ; then

View file

@ -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`. `testrepo/.forgejo/workflows/*.yml` are replaced with `$forgejo/root/myaction`.
* `forgejo-test-helper.sh push testrepo $forgejo root testrepo` * `forgejo-test-helper.sh push testrepo $forgejo root testrepo`
Creates the repository `$forgejo/root/testrepo` and populates it with the Creates the repository `$forgejo/root/testrepo` and populates it with the
content of the `testrepo` directory. The SHA of the tip of the repository content of the `testrepo` directory.
is in the output, on a line starting with `sha=`.
* `forgejo-test-helper.sh build_runner $forgejo/forgejo/runner v3.0.1` * `forgejo-test-helper.sh build_runner $forgejo/forgejo/runner v3.0.1`
Builds the forgejo runner from source in `./forgejo-runner/forgejo-runner`. Builds the forgejo runner from source in `./forgejo-runner/forgejo-runner`.
`export PATH=$(pwd)/forgejo-runner:$PATH` will ensure that calling `forgejo-runner.sh` `export PATH=$(pwd)/forgejo-runner:$PATH` will ensure that calling `forgejo-runner.sh`

View file

@ -19,8 +19,7 @@ description: |
`testrepo/.forgejo/workflows/*.yml` are replaced with `$forgejo/root/myaction`. `testrepo/.forgejo/workflows/*.yml` are replaced with `$forgejo/root/myaction`.
* `forgejo-test-helper.sh push testrepo $forgejo root testrepo` * `forgejo-test-helper.sh push testrepo $forgejo root testrepo`
Creates the repository `$forgejo/root/testrepo` and populates it with the Creates the repository `$forgejo/root/testrepo` and populates it with the
content of the `testrepo` directory. The SHA of the tip of the repository content of the `testrepo` directory.
is in the output, on a line starting with `sha=`.
* `forgejo-test-helper.sh build_runner $forgejo/forgejo/runner v3.0.1` * `forgejo-test-helper.sh build_runner $forgejo/forgejo/runner v3.0.1`
Builds the forgejo runner from source in `./forgejo-runner/forgejo-runner`. Builds the forgejo runner from source in `./forgejo-runner/forgejo-runner`.
`export PATH=$(pwd)/forgejo-runner:$PATH` will ensure that calling `forgejo-runner.sh` `export PATH=$(pwd)/forgejo-runner:$PATH` will ensure that calling `forgejo-runner.sh`

View file

@ -44,6 +44,15 @@ function build_runner() {
forgejo-runner --version 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() { function get_status() {
local url="$1" local url="$1"
local repo="$2" local repo="$2"
@ -111,7 +120,6 @@ function push() {
git push --force -u origin main git push --force -u origin main
sha=$(git rev-parse HEAD) sha=$(git rev-parse HEAD)
echo $sha > SHA echo $sha > SHA
echo sha=$sha
) )
} }