#!/bin/bash # SPDX-License-Identifier: MIT set -ex SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source $SELF_DIR/forgejo-lib.sh : ${LOOPS:=80} : ${LOOP_DELAY:=5} WORKDIR=$(mktemp -d) : ${DIR:=$(pwd)} trap "rm -fr $WORKDIR" EXIT 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" local sha="$3" forgejo-curl.sh api_json $url/api/v1/repos/$repo/commits/$sha/status } function check_status() { local url="$1" local repo="$2" local sha="$3" local expected_status="$4" local expected_description="$5" get_status $url $repo $sha >/tmp/status.json local status="$(jq --raw-output .state SHA ) } function push_workflow() { local directory="$1" local url="$2" local owner="$3" local project="$4" local self_action="$5" local token="$6" if test -z "$token"; then echo missing token argument return 1 fi push "$directory" "$url" "$owner" "$project" "$self_action" "$token" } function run_workflow() { local directory="$1" local url="$2" local owner="$3" local project="$4" local self_action="$5" local token="$6" push_workflow "$directory" "$url" "$owner" "$project" "$self_action" "$token" wait_success "$url" "$owner/$project" $(cat $WORKDIR/$project/SHA) } function clear_runner_cache() { if test -f $DIR/forgejo-runner-home; then rm -fr $(cat $DIR/forgejo-runner-home)/.cache/act fi } function push_self_action() { local url="$1" local owner="$2" local self_action="$3" local tag="$4" clear_runner_cache local dir="$WORKDIR/self" git diff --exit-code git clone . $dir ( cd $dir rm -fr .forgejo .git git init git checkout -b main git remote add origin "$url/$owner/$self_action" 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 $tag HEAD git push --force origin $tag ) } function dependencies() { if ! which jq curl >/dev/null; then apt-get -qq install -y jq curl fi } dependencies "$@"