Files
gitea-ci-library/scripts/report-status.sh
T
moilanik 0655372a86
CI / load-config (push) Successful in 12s
ci-bats Bats tests
ci-cucumber Cucumber tests passed
ci-build Build complete
CI / feature (push) Successful in 1m24s
CI / main (push) Has been skipped
piilloparametrit eksplisiittisiksi
2026-06-13 16:21:47 +03:00

53 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
STATE="${1:-}"
DESCRIPTION="${2:-}"
URL="${3:-}"
GITEA_API_URL="${4:-}"
GITEA_TOKEN="${5:-}"
KEY="${6:-commit-${GITHUB_SHA:0:8}}"
PAGES_HOST="${7:-}"
REPORT_PATH="${8:-}"
ROOT_COMMIT="${9:-}"
ROOT_REPO="${10:-}"
[ -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 argument is required" >&2 && exit 1
[ -z "$GITEA_TOKEN" ] && echo "ERROR: gitea_token argument is required" >&2 && exit 1
if [ -n "$REPORT_PATH" ]; then
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/${REPORT_PATH}"
elif [ -n "$PAGES_HOST" ]; then
URL="${GITEA_API_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
fi
if [ -n "$ROOT_COMMIT" ] && [ -n "$ROOT_REPO" ]; then
REPO="$ROOT_REPO"
COMMIT="$ROOT_COMMIT"
else
REPO="${GITHUB_REPOSITORY:-}"
COMMIT="${GITHUB_SHA:-}"
fi
[ -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\"}")
if [ "$HTTP_CODE" = "201" ]; then
exit 0
fi
if [ -z "$HTTP_CODE" ]; then
echo "ERROR: Failed to connect to Gitea API at $GITEA_API_URL" >&2
else
echo "ERROR: API returned HTTP $HTTP_CODE" >&2
fi
exit 1