diff --git a/.gitea/workflows/gitops-dispatch.yml b/.gitea/workflows/gitops-dispatch.yml index aeadab7..acc69dc 100644 --- a/.gitea/workflows/gitops-dispatch.yml +++ b/.gitea/workflows/gitops-dispatch.yml @@ -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 diff --git a/git-pages/README.md b/git-pages/README.md index b0e1c51..701eef4 100644 --- a/git-pages/README.md +++ b/git-pages/README.md @@ -122,7 +122,7 @@ helm upgrade --install git-pages ./git-pages \ helm template git-pages ./git-pages -f "$VALUES" ``` - + --- ## CI-julkaisu