forked from SteamWar/SteamWar
@@ -36,9 +36,17 @@ jobs:
|
|||||||
|
|
||||||
api_url="${GITHUB_API_URL:-${GITHUB_SERVER_URL}/api/v1}"
|
api_url="${GITHUB_API_URL:-${GITHUB_SERVER_URL}/api/v1}"
|
||||||
|
|
||||||
|
echo "Backport debug: event=${GITHUB_EVENT_NAME:-unknown}"
|
||||||
|
echo "Backport debug: server=${GITHUB_SERVER_URL}"
|
||||||
|
echo "Backport debug: api=${api_url}"
|
||||||
|
echo "Backport debug: repository=${GITHUB_REPOSITORY}"
|
||||||
|
echo "Backport debug: action=$(jq -r '.action // ""' "$GITHUB_EVENT_PATH")"
|
||||||
|
|
||||||
merged="$(jq -r '.pull_request.merged // (.pull_request.merged_at != null)' "$GITHUB_EVENT_PATH")"
|
merged="$(jq -r '.pull_request.merged // (.pull_request.merged_at != null)' "$GITHUB_EVENT_PATH")"
|
||||||
base_branch="$(jq -r '.pull_request.base.ref' "$GITHUB_EVENT_PATH")"
|
base_branch="$(jq -r '.pull_request.base.ref' "$GITHUB_EVENT_PATH")"
|
||||||
has_disable_label="$(jq -r --arg disable_backport_label "$DISABLE_BACKPORT_LABEL" 'any(.pull_request.labels[]?; .name == $disable_backport_label)' "$GITHUB_EVENT_PATH")"
|
has_disable_label="$(jq -r --arg disable_backport_label "$DISABLE_BACKPORT_LABEL" 'any(.pull_request.labels[]?; .name == $disable_backport_label)' "$GITHUB_EVENT_PATH")"
|
||||||
|
echo "Backport debug: pr=$(jq -r '.pull_request.number // ""' "$GITHUB_EVENT_PATH") base=${base_branch} merged=${merged}"
|
||||||
|
echo "Backport debug: disable label present=${has_disable_label}"
|
||||||
|
|
||||||
{
|
{
|
||||||
echo "should_backport=$([[ "$merged" == "true" && "$base_branch" == "main" && "$has_disable_label" != "true" ]] && echo true || echo false)"
|
echo "should_backport=$([[ "$merged" == "true" && "$base_branch" == "main" && "$has_disable_label" != "true" ]] && echo true || echo false)"
|
||||||
@@ -73,6 +81,44 @@ jobs:
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
api_url="${GITHUB_API_URL:-${GITHUB_SERVER_URL}/api/v1}"
|
api_url="${GITHUB_API_URL:-${GITHUB_SERVER_URL}/api/v1}"
|
||||||
|
repo_api_path="/repos/${GITHUB_REPOSITORY}"
|
||||||
|
|
||||||
|
api_request() {
|
||||||
|
local method="$1"
|
||||||
|
local path="$2"
|
||||||
|
local output="$3"
|
||||||
|
local data_file="${4:-}"
|
||||||
|
local status
|
||||||
|
local args=(-sS -X "$method" -H "Accept: application/json" -H "Authorization: token ${GITHUB_TOKEN}" -w "%{http_code}" -o "$output")
|
||||||
|
|
||||||
|
if [[ -n "$data_file" ]]; then
|
||||||
|
args+=(-H "Content-Type: application/json" --data-binary "@${data_file}")
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Backport debug: ${method} ${path}"
|
||||||
|
if ! status="$(curl "${args[@]}" "${api_url}${path}")"; then
|
||||||
|
echo "Backport debug: ${method} ${path} failed before HTTP status was captured."
|
||||||
|
if [[ -s "$output" ]]; then
|
||||||
|
echo "Backport debug: response body:"
|
||||||
|
cat "$output"
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Backport debug: ${method} ${path} -> HTTP ${status}"
|
||||||
|
if [[ ! "$status" =~ ^2 ]]; then
|
||||||
|
echo "Backport debug: response body:"
|
||||||
|
cat "$output"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Backport debug: event=${GITHUB_EVENT_NAME:-unknown}"
|
||||||
|
echo "Backport debug: server=${GITHUB_SERVER_URL}"
|
||||||
|
echo "Backport debug: api=${api_url}"
|
||||||
|
echo "Backport debug: repository=${GITHUB_REPOSITORY}"
|
||||||
|
echo "Backport debug: pr=${PR_NUMBER}"
|
||||||
|
echo "Backport debug: actor=${GITHUB_ACTOR:-unknown}"
|
||||||
|
|
||||||
git config user.name "SteamWar Backport Bot"
|
git config user.name "SteamWar Backport Bot"
|
||||||
git config user.email "actions@steamwar.de"
|
git config user.email "actions@steamwar.de"
|
||||||
@@ -84,10 +130,14 @@ jobs:
|
|||||||
|
|
||||||
git fetch --prune origin '+refs/heads/version/*:refs/remotes/origin/version/*'
|
git fetch --prune origin '+refs/heads/version/*:refs/remotes/origin/version/*'
|
||||||
|
|
||||||
curl -fsSL \
|
api_request GET "${repo_api_path}" repo-debug.json
|
||||||
|
jq -r '"Backport debug: repo permissions admin=\(.permissions.admin // "unknown") push=\(.permissions.push // "unknown") pull=\(.permissions.pull // "unknown")"' repo-debug.json || true
|
||||||
|
|
||||||
|
echo "Backport debug: GET ${repo_api_path}/pulls/${PR_NUMBER}.diff"
|
||||||
|
curl -fsSL -w "Backport debug: GET ${repo_api_path}/pulls/${PR_NUMBER}.diff -> HTTP %{http_code}\n" \
|
||||||
-H "Accept: text/plain" \
|
-H "Accept: text/plain" \
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||||
"${api_url}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}.diff" \
|
"${api_url}${repo_api_path}/pulls/${PR_NUMBER}.diff" \
|
||||||
-o pull-request.diff
|
-o pull-request.diff
|
||||||
|
|
||||||
if ! grep -Eq "^diff --git a/${BACKPORT_PATH}/" pull-request.diff; then
|
if ! grep -Eq "^diff --git a/${BACKPORT_PATH}/" pull-request.diff; then
|
||||||
@@ -121,11 +171,8 @@ jobs:
|
|||||||
git commit -m "Backport CommonCore changes from #${PR_NUMBER}" -m "${PR_TITLE}"
|
git commit -m "Backport CommonCore changes from #${PR_NUMBER}" -m "${PR_TITLE}"
|
||||||
git push --force-with-lease origin "${backport_branch}"
|
git push --force-with-lease origin "${backport_branch}"
|
||||||
|
|
||||||
open_pr_number="$(curl -fsS \
|
api_request GET "${repo_api_path}/pulls?state=open" open-pulls.json
|
||||||
-H "Accept: application/json" \
|
open_pr_number="$(jq -r --arg base "$target_branch" --arg head "$backport_branch" '[.[] | select(.base.ref == $base and .head.ref == $head) | (.number // .index)][0] // empty' open-pulls.json)"
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
||||||
"${api_url}/repos/${GITHUB_REPOSITORY}/pulls?state=open" \
|
|
||||||
| jq -r --arg base "$target_branch" --arg head "$backport_branch" '[.[] | select(.base.ref == $base and .head.ref == $head) | (.number // .index)][0] // empty')"
|
|
||||||
|
|
||||||
if [[ -n "$open_pr_number" ]]; then
|
if [[ -n "$open_pr_number" ]]; then
|
||||||
echo "Backport PR #${open_pr_number} already exists for ${target_branch}."
|
echo "Backport PR #${open_pr_number} already exists for ${target_branch}."
|
||||||
@@ -134,15 +181,13 @@ jobs:
|
|||||||
|
|
||||||
pr_body="$(printf 'Automatic CommonCore backport of #%s.\n\nOriginal PR title: %s\n\nOnly files below `CommonCore/` are included.' "$PR_NUMBER" "$PR_TITLE")"
|
pr_body="$(printf 'Automatic CommonCore backport of #%s.\n\nOriginal PR title: %s\n\nOnly files below `CommonCore/` are included.' "$PR_NUMBER" "$PR_TITLE")"
|
||||||
|
|
||||||
curl -fsS -X POST \
|
jq -n \
|
||||||
-H "Accept: application/json" \
|
--arg base "$target_branch" \
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
--arg head "$backport_branch" \
|
||||||
-H "Content-Type: application/json" \
|
--arg title "Backport CommonCore changes from #${PR_NUMBER} to ${target_branch}" \
|
||||||
-d "$(jq -n \
|
--arg body "$pr_body" \
|
||||||
--arg base "$target_branch" \
|
'{base: $base, head: $head, title: $title, body: $body}' > create-pull.json
|
||||||
--arg head "$backport_branch" \
|
|
||||||
--arg title "Backport CommonCore changes from #${PR_NUMBER} to ${target_branch}" \
|
echo "Backport debug: create PR base=${target_branch} head=${backport_branch}"
|
||||||
--arg body "$pr_body" \
|
api_request POST "${repo_api_path}/pulls" create-pull-response.json create-pull.json
|
||||||
'{base: $base, head: $head, title: $title, body: $body}')" \
|
|
||||||
"${api_url}/repos/${GITHUB_REPOSITORY}/pulls"
|
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user