bfd0428a78
CI Feature / Load example-gitea-env.conf to pipeline env (push) Successful in 27s
acc-tests Cucumber test report
CI Feature / Cucumber tests (push) Successful in 1m19s
unit-tests Bats test report
CI Feature / Bats tests (push) Failing after 2m0s
CI Feature / Report Summary (push) Successful in 5s
48 lines
1.6 KiB
Bash
Executable File
48 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env sh
|
|
set -eu
|
|
|
|
STATE="${1:-}"
|
|
DESCRIPTION="${2:-}"
|
|
SHA8=$(echo "${GITHUB_SHA:-}" | cut -c1-8)
|
|
KEY="${3:-commit-${SHA8}}"
|
|
SUITE="${4:-}"
|
|
CUSTOM_URL="${5:-}"
|
|
|
|
[ -z "$STATE" ] && echo "ERROR: state argument is required" >&2 && exit 1
|
|
[ -z "$DESCRIPTION" ] && echo "ERROR: description argument is required" >&2 && exit 1
|
|
[ -z "${GITEA_API_URL:-}" ] && echo "ERROR: GITEA_API_URL is not set" >&2 && exit 1
|
|
[ -z "${GITEA_TOKEN:-}" ] && echo "ERROR: GITEA_TOKEN is not set" >&2 && exit 1
|
|
|
|
if [ -n "$CUSTOM_URL" ]; then
|
|
URL="$CUSTOM_URL"
|
|
elif [ -n "$SUITE" ]; then
|
|
SUITE="${SUITE%/}/"
|
|
SHA8_CUT=$(echo "$GITHUB_SHA" | cut -c1-8)
|
|
URL="${GIT_PAGES_URL}/${GITHUB_REPOSITORY}/reports/${SHA8_CUT}/${SUITE}"
|
|
else
|
|
URL="${GITEA_API_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
|
|
fi
|
|
|
|
REPO="${ROOT_REPO:-${GITHUB_REPOSITORY:-}}"
|
|
COMMIT="${ROOT_COMMIT:-${GITHUB_SHA:-}}"
|
|
|
|
[ -z "$REPO" ] && echo "ERROR: GITHUB_REPOSITORY is not set" >&2 && exit 1
|
|
[ -z "$COMMIT" ] && echo "ERROR: GITHUB_SHA is not set" >&2 && exit 1
|
|
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
-X POST "$GITEA_API_URL/api/v1/repos/$REPO/statuses/$COMMIT" \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"state\":\"$STATE\",\"target_url\":\"$URL\",\"description\":\"$DESCRIPTION\",\"context\":\"$KEY\"}" || true)
|
|
|
|
if [ "$HTTP_CODE" = "201" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
if [ -z "$HTTP_CODE" ] || [ "$HTTP_CODE" = "000" ]; then
|
|
echo "gitea-ci-library - ERROR: Failed to connect to Gitea API at $GITEA_API_URL" >&2
|
|
else
|
|
echo "gitea-ci-library - ERROR: gitea-ci-library, API returned HTTP $HTTP_CODE" >&2
|
|
fi
|
|
exit 1
|