|
|
@@ -9,10 +9,14 @@ on:
|
|
|
|
default: false
|
|
|
|
default: false
|
|
|
|
type: boolean
|
|
|
|
type: boolean
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
concurrency:
|
|
|
|
|
|
|
|
group: release-${{ github.repository }}
|
|
|
|
|
|
|
|
cancel-in-progress: false
|
|
|
|
|
|
|
|
|
|
|
|
env:
|
|
|
|
env:
|
|
|
|
GITEA_URL: http://gitea-http.gitea.svc.cluster.local:3000
|
|
|
|
GITEA_URL: http://gitea-http.gitea.svc.cluster.local:3000
|
|
|
|
RELEASE_TOKEN_FILE: /runner-secrets/release-token
|
|
|
|
RELEASE_TOKEN_FILE: /runner-secrets/release-token
|
|
|
|
GIT_CLIFF_VERSION: "2.11.0"
|
|
|
|
GIT_CLIFF_VERSION: "2.12.0"
|
|
|
|
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
jobs:
|
|
|
|
preconditions:
|
|
|
|
preconditions:
|
|
|
@@ -84,27 +88,28 @@ jobs:
|
|
|
|
REPO=$(echo "${REPOSITORY}" | cut -d'/' -f2)
|
|
|
|
REPO=$(echo "${REPOSITORY}" | cut -d'/' -f2)
|
|
|
|
API_URL="${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}"
|
|
|
|
API_URL="${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Fallback to main if DEFAULT_BRANCH is empty
|
|
|
|
|
|
|
|
BASE_BRANCH="${DEFAULT_BRANCH:-main}"
|
|
|
|
|
|
|
|
echo "Using base branch: ${BASE_BRANCH}"
|
|
|
|
|
|
|
|
|
|
|
|
TITLE="chore(release): prepare for ${VERSION}"
|
|
|
|
TITLE="chore(release): prepare for ${VERSION}"
|
|
|
|
# Read CHANGES.md and escape for JSON
|
|
|
|
# Read CHANGES.md content and add note (jq --arg will handle JSON escaping)
|
|
|
|
DESCRIPTION=$(cat CHANGES.md | jq -Rs .)
|
|
|
|
CHANGES_CONTENT=$(cat CHANGES.md)
|
|
|
|
DESCRIPTION="${DESCRIPTION:1:-1}" # Remove surrounding quotes from jq
|
|
|
|
PR_NOTE="**Note:** Please use **Squash Merge** when merging this PR."
|
|
|
|
|
|
|
|
DESCRIPTION="${CHANGES_CONTENT}"$'\n\n---\n\n'"${PR_NOTE}"
|
|
|
|
# Add squash merge reminder
|
|
|
|
|
|
|
|
DESCRIPTION="${DESCRIPTION}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
**Note:** Please use **Squash Merge** when merging this PR."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "Checking for existing release PRs..."
|
|
|
|
|
|
|
|
PRS=$(curl -sf \
|
|
|
|
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
|
|
|
|
"${API_URL}/pulls?state=open" | jq '[.[] | select(.head.ref == "next-release")]')
|
|
|
|
|
|
|
|
PR_INDEX=$(echo "${PRS}" | jq -r '.[0].number // empty')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Delete existing next-release branch to start fresh (auto-closes any open PR)
|
|
|
|
echo "Checking for existing next-release branch..."
|
|
|
|
echo "Checking for existing next-release branch..."
|
|
|
|
BRANCH_EXISTS=$(curl -sf \
|
|
|
|
BRANCH_CHECK=$(curl -s --retry 3 --retry-delay 2 --retry-connrefused -w "%{http_code}" -o /dev/null \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
"${API_URL}/branches/next-release" 2>/dev/null && echo "true" || echo "false")
|
|
|
|
"${API_URL}/branches/next-release")
|
|
|
|
|
|
|
|
if [ "${BRANCH_CHECK}" = "200" ]; then
|
|
|
|
|
|
|
|
echo "Deleting existing next-release branch..."
|
|
|
|
|
|
|
|
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X DELETE \
|
|
|
|
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
|
|
|
|
"${API_URL}/branches/next-release"
|
|
|
|
|
|
|
|
echo "Branch deleted"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Prepare CHANGELOG.md content
|
|
|
|
# Prepare CHANGELOG.md content
|
|
|
|
CHANGELOG_CONTENT=$(base64 -w0 < CHANGELOG.md)
|
|
|
|
CHANGELOG_CONTENT=$(base64 -w0 < CHANGELOG.md)
|
|
|
@@ -113,46 +118,54 @@ jobs:
|
|
|
|
VERSION_JSON=$(jq -n --arg v "${VERSION}" '{"version":$v}')
|
|
|
|
VERSION_JSON=$(jq -n --arg v "${VERSION}" '{"version":$v}')
|
|
|
|
VERSION_CONTENT=$(echo "${VERSION_JSON}" | base64 -w0)
|
|
|
|
VERSION_CONTENT=$(echo "${VERSION_JSON}" | base64 -w0)
|
|
|
|
|
|
|
|
|
|
|
|
if [ "${BRANCH_EXISTS}" = "true" ]; then
|
|
|
|
echo "Creating new next-release branch from ${BASE_BRANCH}..."
|
|
|
|
echo "Updating existing next-release branch..."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get SHA of existing CHANGELOG.md
|
|
|
|
# Check if CHANGELOG.md exists on base branch to determine create vs update
|
|
|
|
CHANGELOG_SHA=$(curl -sf \
|
|
|
|
CHANGELOG_SHA=$(curl -sf --retry 3 --retry-delay 2 --retry-connrefused \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
"${API_URL}/contents/CHANGELOG.md?ref=next-release" | jq -r '.sha // empty')
|
|
|
|
"${API_URL}/contents/CHANGELOG.md?ref=${BASE_BRANCH}" | jq -r '.sha // empty')
|
|
|
|
|
|
|
|
|
|
|
|
# Update or create CHANGELOG.md
|
|
|
|
|
|
|
|
if [ -n "${CHANGELOG_SHA}" ]; then
|
|
|
|
if [ -n "${CHANGELOG_SHA}" ]; then
|
|
|
|
curl -sf -X PUT \
|
|
|
|
echo "Updating CHANGELOG.md (exists on ${BASE_BRANCH}) on new branch..."
|
|
|
|
|
|
|
|
RESPONSE=$(curl -s --retry 3 --retry-delay 2 --retry-connrefused -w "\n%{http_code}" -X PUT \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
--data "$(jq -n \
|
|
|
|
--data "$(jq -n \
|
|
|
|
--arg content "${CHANGELOG_CONTENT}" \
|
|
|
|
--arg content "${CHANGELOG_CONTENT}" \
|
|
|
|
--arg sha "${CHANGELOG_SHA}" \
|
|
|
|
--arg sha "${CHANGELOG_SHA}" \
|
|
|
|
--arg message "${TITLE}" \
|
|
|
|
--arg message "${TITLE}" \
|
|
|
|
--arg branch "next-release" \
|
|
|
|
--arg branch "${BASE_BRANCH}" \
|
|
|
|
'{content: $content, sha: $sha, message: $message, branch: $branch}')" \
|
|
|
|
--arg new_branch "next-release" \
|
|
|
|
"${API_URL}/contents/CHANGELOG.md"
|
|
|
|
'{content: $content, sha: $sha, message: $message, branch: $branch, new_branch: $new_branch}')" \
|
|
|
|
|
|
|
|
"${API_URL}/contents/CHANGELOG.md")
|
|
|
|
else
|
|
|
|
else
|
|
|
|
curl -sf -X POST \
|
|
|
|
echo "Creating CHANGELOG.md on new branch..."
|
|
|
|
|
|
|
|
RESPONSE=$(curl -s --retry 3 --retry-delay 2 --retry-connrefused -w "\n%{http_code}" -X POST \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
--data "$(jq -n \
|
|
|
|
--data "$(jq -n \
|
|
|
|
--arg content "${CHANGELOG_CONTENT}" \
|
|
|
|
--arg content "${CHANGELOG_CONTENT}" \
|
|
|
|
--arg message "${TITLE}" \
|
|
|
|
--arg message "${TITLE}" \
|
|
|
|
--arg branch "next-release" \
|
|
|
|
--arg branch "${BASE_BRANCH}" \
|
|
|
|
'{content: $content, message: $message, branch: $branch, new_branch: $branch}')" \
|
|
|
|
--arg new_branch "next-release" \
|
|
|
|
"${API_URL}/contents/CHANGELOG.md"
|
|
|
|
'{content: $content, message: $message, branch: $branch, new_branch: $new_branch}')" \
|
|
|
|
|
|
|
|
"${API_URL}/contents/CHANGELOG.md")
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
HTTP_CODE=$(echo "${RESPONSE}" | tail -1)
|
|
|
|
|
|
|
|
BODY=$(echo "${RESPONSE}" | sed '$d')
|
|
|
|
|
|
|
|
if [ "${HTTP_CODE}" -ge 400 ]; then
|
|
|
|
|
|
|
|
echo "Error with CHANGELOG.md: ${BODY}"
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Get SHA of existing .version
|
|
|
|
# Check if .version exists on base branch
|
|
|
|
VERSION_SHA=$(curl -sf \
|
|
|
|
VERSION_SHA=$(curl -sf --retry 3 --retry-delay 2 --retry-connrefused \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
"${API_URL}/contents/.version?ref=next-release" | jq -r '.sha // empty')
|
|
|
|
"${API_URL}/contents/.version?ref=${BASE_BRANCH}" | jq -r '.sha // empty')
|
|
|
|
|
|
|
|
|
|
|
|
# Update or create .version
|
|
|
|
|
|
|
|
if [ -n "${VERSION_SHA}" ]; then
|
|
|
|
if [ -n "${VERSION_SHA}" ]; then
|
|
|
|
curl -sf -X PUT \
|
|
|
|
echo "Updating .version on next-release branch..."
|
|
|
|
|
|
|
|
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X PUT \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
--data "$(jq -n \
|
|
|
|
--data "$(jq -n \
|
|
|
@@ -163,31 +176,8 @@ jobs:
|
|
|
|
'{content: $content, sha: $sha, message: $message, branch: $branch}')" \
|
|
|
|
'{content: $content, sha: $sha, message: $message, branch: $branch}')" \
|
|
|
|
"${API_URL}/contents/.version"
|
|
|
|
"${API_URL}/contents/.version"
|
|
|
|
else
|
|
|
|
else
|
|
|
|
curl -sf -X POST \
|
|
|
|
echo "Creating .version on next-release branch..."
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X POST \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
|
|
|
--data "$(jq -n \
|
|
|
|
|
|
|
|
--arg content "${VERSION_CONTENT}" \
|
|
|
|
|
|
|
|
--arg message "${TITLE}" \
|
|
|
|
|
|
|
|
--arg branch "next-release" \
|
|
|
|
|
|
|
|
'{content: $content, message: $message, branch: $branch}')" \
|
|
|
|
|
|
|
|
"${API_URL}/contents/.version"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "Creating new next-release branch with CHANGELOG.md..."
|
|
|
|
|
|
|
|
curl -sf -X POST \
|
|
|
|
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
|
|
|
--data "$(jq -n \
|
|
|
|
|
|
|
|
--arg content "${CHANGELOG_CONTENT}" \
|
|
|
|
|
|
|
|
--arg message "${TITLE}" \
|
|
|
|
|
|
|
|
--arg branch "${DEFAULT_BRANCH}" \
|
|
|
|
|
|
|
|
--arg new_branch "next-release" \
|
|
|
|
|
|
|
|
'{content: $content, message: $message, branch: $branch, new_branch: $new_branch}')" \
|
|
|
|
|
|
|
|
"${API_URL}/contents/CHANGELOG.md"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "Adding .version to next-release branch..."
|
|
|
|
|
|
|
|
curl -sf -X POST \
|
|
|
|
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
--data "$(jq -n \
|
|
|
|
--data "$(jq -n \
|
|
|
@@ -198,29 +188,52 @@ jobs:
|
|
|
|
"${API_URL}/contents/.version"
|
|
|
|
"${API_URL}/contents/.version"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ -n "${PR_INDEX}" ]; then
|
|
|
|
|
|
|
|
echo "Updating existing PR #${PR_INDEX}..."
|
|
|
|
|
|
|
|
curl -sf -X PATCH \
|
|
|
|
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
|
|
|
--data "$(jq -n \
|
|
|
|
|
|
|
|
--arg title "${TITLE}" \
|
|
|
|
|
|
|
|
--arg body "${DESCRIPTION}" \
|
|
|
|
|
|
|
|
'{title: $title, body: $body}')" \
|
|
|
|
|
|
|
|
"${API_URL}/pulls/${PR_INDEX}"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "Creating new PR..."
|
|
|
|
echo "Creating new PR..."
|
|
|
|
curl -sf -X POST \
|
|
|
|
echo "Waiting for next-release branch to be ready..."
|
|
|
|
|
|
|
|
for i in $(seq 1 10); do
|
|
|
|
|
|
|
|
BRANCH_STATUS=$(curl -s --retry 3 --retry-delay 2 --retry-connrefused \
|
|
|
|
|
|
|
|
-w "%{http_code}" -o /dev/null \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
"${API_URL}/branches/next-release")
|
|
|
|
--data "$(jq -n \
|
|
|
|
if [ "${BRANCH_STATUS}" = "200" ]; then
|
|
|
|
|
|
|
|
echo "Branch ready after ${i} attempt(s)"
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${i}" = "10" ]; then
|
|
|
|
|
|
|
|
echo "Branch next-release not found after 10 attempts, giving up"
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Branch not ready yet (attempt ${i}/10), waiting..."
|
|
|
|
|
|
|
|
sleep 3
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PR_DATA=$(jq -n \
|
|
|
|
--arg title "${TITLE}" \
|
|
|
|
--arg title "${TITLE}" \
|
|
|
|
--arg body "${DESCRIPTION}" \
|
|
|
|
--arg body "${DESCRIPTION}" \
|
|
|
|
--arg head "next-release" \
|
|
|
|
--arg head "next-release" \
|
|
|
|
--arg base "${DEFAULT_BRANCH}" \
|
|
|
|
--arg base "${BASE_BRANCH}" \
|
|
|
|
'{title: $title, body: $body, head: $head, base: $base}')" \
|
|
|
|
'{title: $title, body: $body, head: $head, base: $base}')
|
|
|
|
"${API_URL}/pulls"
|
|
|
|
|
|
|
|
|
|
|
|
for i in $(seq 1 5); do
|
|
|
|
|
|
|
|
RESPONSE=$(curl -s --retry 3 --retry-delay 2 --retry-connrefused \
|
|
|
|
|
|
|
|
-w "\n%{http_code}" -X POST \
|
|
|
|
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
|
|
|
--data "${PR_DATA}" \
|
|
|
|
|
|
|
|
"${API_URL}/pulls")
|
|
|
|
|
|
|
|
HTTP_CODE=$(echo "${RESPONSE}" | tail -1)
|
|
|
|
|
|
|
|
BODY=$(echo "${RESPONSE}" | sed '$d')
|
|
|
|
|
|
|
|
if [ "${HTTP_CODE}" -lt 400 ]; then
|
|
|
|
|
|
|
|
echo "PR created successfully"
|
|
|
|
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${i}" = "5" ]; then
|
|
|
|
|
|
|
|
echo "Error creating PR after 5 attempts (HTTP ${HTTP_CODE}): ${BODY}"
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "PR creation attempt ${i}/5 failed (HTTP ${HTTP_CODE}), retrying..."
|
|
|
|
|
|
|
|
sleep 3
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
create-release:
|
|
|
|
create-release:
|
|
|
|
name: Create Release
|
|
|
|
name: Create Release
|
|
|
@@ -275,11 +288,10 @@ jobs:
|
|
|
|
REPO=$(echo "${REPOSITORY}" | cut -d'/' -f2)
|
|
|
|
REPO=$(echo "${REPOSITORY}" | cut -d'/' -f2)
|
|
|
|
API_URL="${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}"
|
|
|
|
API_URL="${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}"
|
|
|
|
|
|
|
|
|
|
|
|
MESSAGE=$(cat CHANGES.md | jq -Rs .)
|
|
|
|
MESSAGE=$(cat CHANGES.md)
|
|
|
|
MESSAGE="${MESSAGE:1:-1}" # Remove surrounding quotes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "Creating release ${VERSION}..."
|
|
|
|
echo "Creating release ${VERSION}..."
|
|
|
|
curl -sf -X POST \
|
|
|
|
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X POST \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
--data "$(jq -n \
|
|
|
|
--data "$(jq -n \
|
|
|
@@ -341,7 +353,7 @@ jobs:
|
|
|
|
API_URL="${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}"
|
|
|
|
API_URL="${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}"
|
|
|
|
|
|
|
|
|
|
|
|
echo "Creating tag ${VERSION}..."
|
|
|
|
echo "Creating tag ${VERSION}..."
|
|
|
|
curl -sf -X POST \
|
|
|
|
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X POST \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Authorization: token ${TOKEN}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
--data "$(jq -n \
|
|
|
|
--data "$(jq -n \
|
|
|
|