Files
niko 2bef079d03
CI Main / Load example-gitea-env.conf to pipeline env (push) Successful in 22s
CI Main / Check existing artifact (push) Successful in 18s
acc-tests Cucumber test report
unit-tests Bats test report
CI Main / Cucumber tests (push) Successful in 1m25s
CI Main / Bats tests (push) Successful in 1m26s
ci-docker-build-push Docker build & push 0.2.19 OK
CI Main / Build & Push Docker (push) Successful in 47s
CI Main / Report Summary (push) Successful in 6s
CI Main / Move provider version tag (push) Successful in 16s
Fix/ci kontin no internet vaatimus (#34)
Co-authored-by: moilanik <niko.moilanen@tietoevry.com>
Reviewed-on: #34
2026-06-20 14:36:42 +03:00

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