kutsujalle gitops commit
This commit is contained in:
@@ -119,10 +119,44 @@ jobs:
|
||||
if [ "$STATUS" = "completed" ]; then
|
||||
if [ "$CONCLUSION" = "success" ]; then
|
||||
echo "GitOps workflow completed successfully"
|
||||
BRANCH_RESP=$(curl -s --connect-timeout 5 --max-time 10 \
|
||||
"${GITEA_API_URL}/api/v1/repos/${GITOPS_REPO}/branches/main" \
|
||||
-H "Authorization: token $GITEA_TOKEN") || true
|
||||
GITOPS_COMMIT=$(echo "$BRANCH_RESP" | jq -r '.commit.id // empty')
|
||||
|
||||
# 1. List recent commits from GitOps repo
|
||||
COMMITS=$(curl -s --connect-timeout 5 --max-time 10 \
|
||||
"${GITEA_API_URL}/api/v1/repos/${GITOPS_REPO}/commits?sha=main&limit=10" \
|
||||
-H "Authorization: token $GITEA_TOKEN")
|
||||
|
||||
# 2. Find commit by message: "gitops: update version to X.Y.Z"
|
||||
SEARCH_MSG="gitops: update version to ${GITOPS_VERSION}"
|
||||
GITOPS_COMMIT=$(echo "$COMMITS" | jq -r \
|
||||
--arg msg "$SEARCH_MSG" \
|
||||
'[.[] | select(.commit.message | contains($msg))] | .[0].sha // empty')
|
||||
|
||||
# 3. If not found → no change → use HEAD
|
||||
if [ -z "$GITOPS_COMMIT" ]; then
|
||||
GITOPS_COMMIT=$(echo "$COMMITS" | jq -r '.[0].sha // empty')
|
||||
fi
|
||||
|
||||
# 4. Set commit status on caller's own commit
|
||||
PREFIX="${GITOPS_TAG_PREFIX%/}"
|
||||
if [ -n "$PREFIX" ]; then
|
||||
CONTEXT="gitops/$(basename "${GITOPS_SOURCE_REPO}")/${PREFIX}"
|
||||
DESCRIPTION="GitOps: ${PREFIX} ${GITOPS_VERSION}"
|
||||
else
|
||||
CONTEXT="gitops/$(basename "${GITOPS_SOURCE_REPO}")"
|
||||
DESCRIPTION="GitOps: ${GITOPS_VERSION}"
|
||||
fi
|
||||
STATUS_URL="${GITEA_API_URL}/api/v1/repos/${GITOPS_SOURCE_REPO}/statuses/${GITOPS_SOURCE_COMMIT}"
|
||||
STATUS_BODY=$(jq -nc \
|
||||
--arg state "success" \
|
||||
--arg description "$DESCRIPTION" \
|
||||
--arg context "$CONTEXT" \
|
||||
--arg target_url "${GITEA_API_URL}/${GITOPS_REPO}/commit/${GITOPS_COMMIT}" \
|
||||
'{state: $state, target_url: $target_url, description: $description, context: $context}')
|
||||
curl -s -X POST "$STATUS_URL" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$STATUS_BODY" || true
|
||||
|
||||
echo "GITOPS_COMMIT=$GITOPS_COMMIT" >> "$GITHUB_OUTPUT"
|
||||
echo "$GITOPS_COMMIT" > /tmp/gitops-commit
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user