Merge pull request 'fix(release): replace rebase with branch recreation to prevent PR merge conflicts' (#17) from fix-release-pr-conflicts into main
Reviewed-on: #17
This commit was merged in pull request #17.
This commit is contained in:
+80
-171
@@ -9,6 +9,10 @@ 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
|
||||||
@@ -94,39 +98,18 @@ jobs:
|
|||||||
PR_NOTE="**Note:** Please use **Squash Merge** when merging this PR."
|
PR_NOTE="**Note:** Please use **Squash Merge** when merging this PR."
|
||||||
DESCRIPTION="${CHANGES_CONTENT}"$'\n\n---\n\n'"${PR_NOTE}"
|
DESCRIPTION="${CHANGES_CONTENT}"$'\n\n---\n\n'"${PR_NOTE}"
|
||||||
|
|
||||||
echo "Checking for existing release PRs..."
|
# Delete existing next-release branch to start fresh (auto-closes any open PR)
|
||||||
PRS=$(curl -sf --retry 3 --retry-delay 2 --retry-connrefused \
|
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
"${API_URL}/pulls?state=open" | jq '[.[] | select(.head.ref == "next-release")]')
|
|
||||||
PR_INDEX=$(echo "${PRS}" | jq -r '.[0].number // empty')
|
|
||||||
|
|
||||||
# If PR exists, rebase the branch onto the latest base branch
|
|
||||||
if [ -n "${PR_INDEX}" ]; then
|
|
||||||
echo "Rebasing PR #${PR_INDEX} branch onto ${BASE_BRANCH}..."
|
|
||||||
REBASE_RESPONSE=$(curl -s --retry 3 --retry-delay 2 --retry-connrefused -w "\n%{http_code}" -X POST \
|
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
"${API_URL}/pulls/${PR_INDEX}/update?style=rebase")
|
|
||||||
REBASE_CODE=$(echo "${REBASE_RESPONSE}" | tail -1)
|
|
||||||
if [ "${REBASE_CODE}" = "200" ]; then
|
|
||||||
echo "Successfully rebased branch onto ${BASE_BRANCH}"
|
|
||||||
elif [ "${REBASE_CODE}" = "409" ]; then
|
|
||||||
echo "Branch already up to date or rebase conflict - continuing with update"
|
|
||||||
else
|
|
||||||
echo "Warning: Rebase returned ${REBASE_CODE}, continuing anyway"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Checking for existing next-release branch..."
|
echo "Checking for existing next-release branch..."
|
||||||
BRANCH_CHECK=$(curl -s --retry 3 --retry-delay 2 --retry-connrefused -w "%{http_code}" -o /dev/null \
|
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")
|
"${API_URL}/branches/next-release")
|
||||||
echo "Branch check HTTP status: ${BRANCH_CHECK}"
|
|
||||||
if [ "${BRANCH_CHECK}" = "200" ]; then
|
if [ "${BRANCH_CHECK}" = "200" ]; then
|
||||||
BRANCH_EXISTS="true"
|
echo "Deleting existing next-release branch..."
|
||||||
else
|
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X DELETE \
|
||||||
BRANCH_EXISTS="false"
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
"${API_URL}/branches/next-release"
|
||||||
|
echo "Branch deleted"
|
||||||
fi
|
fi
|
||||||
echo "Branch exists: ${BRANCH_EXISTS}"
|
|
||||||
|
|
||||||
# Prepare CHANGELOG.md content
|
# Prepare CHANGELOG.md content
|
||||||
CHANGELOG_CONTENT=$(base64 -w0 < CHANGELOG.md)
|
CHANGELOG_CONTENT=$(base64 -w0 < CHANGELOG.md)
|
||||||
@@ -135,162 +118,88 @@ 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 --retry 3 --retry-delay 2 --retry-connrefused \
|
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
|
echo "Updating CHANGELOG.md (exists on ${BASE_BRANCH}) on new branch..."
|
||||||
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X PUT \
|
RESPONSE=$(curl -s --retry 3 --retry-delay 2 --retry-connrefused -w "\n%{http_code}" -X PUT \
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
--data "$(jq -n \
|
|
||||||
--arg content "${CHANGELOG_CONTENT}" \
|
|
||||||
--arg sha "${CHANGELOG_SHA}" \
|
|
||||||
--arg message "${TITLE}" \
|
|
||||||
--arg branch "next-release" \
|
|
||||||
'{content: $content, sha: $sha, message: $message, branch: $branch}')" \
|
|
||||||
"${API_URL}/contents/CHANGELOG.md"
|
|
||||||
else
|
|
||||||
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X POST \
|
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
--data "$(jq -n \
|
|
||||||
--arg content "${CHANGELOG_CONTENT}" \
|
|
||||||
--arg message "${TITLE}" \
|
|
||||||
--arg branch "next-release" \
|
|
||||||
'{content: $content, message: $message, branch: $branch, new_branch: $branch}')" \
|
|
||||||
"${API_URL}/contents/CHANGELOG.md"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get SHA of existing .version
|
|
||||||
VERSION_SHA=$(curl -sf --retry 3 --retry-delay 2 --retry-connrefused \
|
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
"${API_URL}/contents/.version?ref=next-release" | jq -r '.sha // empty')
|
|
||||||
|
|
||||||
# Update or create .version
|
|
||||||
if [ -n "${VERSION_SHA}" ]; then
|
|
||||||
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X PUT \
|
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
--data "$(jq -n \
|
|
||||||
--arg content "${VERSION_CONTENT}" \
|
|
||||||
--arg sha "${VERSION_SHA}" \
|
|
||||||
--arg message "${TITLE}" \
|
|
||||||
--arg branch "next-release" \
|
|
||||||
'{content: $content, sha: $sha, message: $message, branch: $branch}')" \
|
|
||||||
"${API_URL}/contents/.version"
|
|
||||||
else
|
|
||||||
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X POST \
|
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
-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 from ${BASE_BRANCH}..."
|
|
||||||
|
|
||||||
# Check if CHANGELOG.md exists on base branch to determine create vs update
|
|
||||||
CHANGELOG_SHA=$(curl -sf --retry 3 --retry-delay 2 --retry-connrefused \
|
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
"${API_URL}/contents/CHANGELOG.md?ref=${BASE_BRANCH}" | jq -r '.sha // empty')
|
|
||||||
|
|
||||||
if [ -n "${CHANGELOG_SHA}" ]; then
|
|
||||||
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 "Content-Type: application/json" \
|
|
||||||
--data "$(jq -n \
|
|
||||||
--arg content "${CHANGELOG_CONTENT}" \
|
|
||||||
--arg sha "${CHANGELOG_SHA}" \
|
|
||||||
--arg message "${TITLE}" \
|
|
||||||
--arg branch "${BASE_BRANCH}" \
|
|
||||||
--arg new_branch "next-release" \
|
|
||||||
'{content: $content, sha: $sha, message: $message, branch: $branch, new_branch: $new_branch}')" \
|
|
||||||
"${API_URL}/contents/CHANGELOG.md")
|
|
||||||
else
|
|
||||||
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 "Content-Type: application/json" \
|
|
||||||
--data "$(jq -n \
|
|
||||||
--arg content "${CHANGELOG_CONTENT}" \
|
|
||||||
--arg message "${TITLE}" \
|
|
||||||
--arg branch "${BASE_BRANCH}" \
|
|
||||||
--arg new_branch "next-release" \
|
|
||||||
'{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
|
|
||||||
|
|
||||||
# Check if .version exists on base branch
|
|
||||||
VERSION_SHA=$(curl -sf --retry 3 --retry-delay 2 --retry-connrefused \
|
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
"${API_URL}/contents/.version?ref=${BASE_BRANCH}" | jq -r '.sha // empty')
|
|
||||||
|
|
||||||
if [ -n "${VERSION_SHA}" ]; then
|
|
||||||
echo "Updating .version on next-release branch..."
|
|
||||||
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X PUT \
|
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
--data "$(jq -n \
|
|
||||||
--arg content "${VERSION_CONTENT}" \
|
|
||||||
--arg sha "${VERSION_SHA}" \
|
|
||||||
--arg message "${TITLE}" \
|
|
||||||
--arg branch "next-release" \
|
|
||||||
'{content: $content, sha: $sha, message: $message, branch: $branch}')" \
|
|
||||||
"${API_URL}/contents/.version"
|
|
||||||
else
|
|
||||||
echo "Creating .version on next-release branch..."
|
|
||||||
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X POST \
|
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
-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
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${PR_INDEX}" ]; then
|
|
||||||
echo "Updating existing PR #${PR_INDEX}..."
|
|
||||||
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X PATCH \
|
|
||||||
-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 title "${TITLE}" \
|
--arg content "${CHANGELOG_CONTENT}" \
|
||||||
--arg body "${DESCRIPTION}" \
|
--arg sha "${CHANGELOG_SHA}" \
|
||||||
'{title: $title, body: $body}')" \
|
--arg message "${TITLE}" \
|
||||||
"${API_URL}/pulls/${PR_INDEX}"
|
--arg branch "${BASE_BRANCH}" \
|
||||||
|
--arg new_branch "next-release" \
|
||||||
|
'{content: $content, sha: $sha, message: $message, branch: $branch, new_branch: $new_branch}')" \
|
||||||
|
"${API_URL}/contents/CHANGELOG.md")
|
||||||
else
|
else
|
||||||
echo "Creating new PR..."
|
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 "Content-Type: application/json" \
|
||||||
|
--data "$(jq -n \
|
||||||
|
--arg content "${CHANGELOG_CONTENT}" \
|
||||||
|
--arg message "${TITLE}" \
|
||||||
|
--arg branch "${BASE_BRANCH}" \
|
||||||
|
--arg new_branch "next-release" \
|
||||||
|
'{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
|
||||||
|
|
||||||
|
# Check if .version exists on base branch
|
||||||
|
VERSION_SHA=$(curl -sf --retry 3 --retry-delay 2 --retry-connrefused \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
"${API_URL}/contents/.version?ref=${BASE_BRANCH}" | jq -r '.sha // empty')
|
||||||
|
|
||||||
|
if [ -n "${VERSION_SHA}" ]; then
|
||||||
|
echo "Updating .version on next-release branch..."
|
||||||
|
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X PUT \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
--data "$(jq -n \
|
||||||
|
--arg content "${VERSION_CONTENT}" \
|
||||||
|
--arg sha "${VERSION_SHA}" \
|
||||||
|
--arg message "${TITLE}" \
|
||||||
|
--arg branch "next-release" \
|
||||||
|
'{content: $content, sha: $sha, message: $message, branch: $branch}')" \
|
||||||
|
"${API_URL}/contents/.version"
|
||||||
|
else
|
||||||
|
echo "Creating .version on next-release branch..."
|
||||||
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -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 \
|
||||||
--arg title "${TITLE}" \
|
--arg content "${VERSION_CONTENT}" \
|
||||||
--arg body "${DESCRIPTION}" \
|
--arg message "${TITLE}" \
|
||||||
--arg head "next-release" \
|
--arg branch "next-release" \
|
||||||
--arg base "${DEFAULT_BRANCH}" \
|
'{content: $content, message: $message, branch: $branch}')" \
|
||||||
'{title: $title, body: $body, head: $head, base: $base}')" \
|
"${API_URL}/contents/.version"
|
||||||
"${API_URL}/pulls"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Creating new PR..."
|
||||||
|
curl -sf --retry 3 --retry-delay 2 --retry-connrefused -X POST \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
--data "$(jq -n \
|
||||||
|
--arg title "${TITLE}" \
|
||||||
|
--arg body "${DESCRIPTION}" \
|
||||||
|
--arg head "next-release" \
|
||||||
|
--arg base "${DEFAULT_BRANCH}" \
|
||||||
|
'{title: $title, body: $body, head: $head, base: $base}')" \
|
||||||
|
"${API_URL}/pulls"
|
||||||
|
|
||||||
create-release:
|
create-release:
|
||||||
name: Create Release
|
name: Create Release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
Reference in New Issue
Block a user