Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8205215c17 | |||
| 36514286aa | |||
| cc271abedb | |||
| 8297002dc5 |
@@ -0,0 +1,66 @@
|
|||||||
|
name: Auto PR
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'feat/**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
open-pr:
|
||||||
|
runs-on: [macos, host]
|
||||||
|
steps:
|
||||||
|
- name: Create Pull Request via Gitea API
|
||||||
|
env:
|
||||||
|
CI_TOKEN: ${{ secrets.CI_TOKEN }}
|
||||||
|
GITEA_BASE_URL: https://gitea.jaybe.dev
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
HEAD_BRANCH: ${{ github.ref_name }}
|
||||||
|
BASE_BRANCH: main
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if [ -z "${CI_TOKEN:-}" ]; then
|
||||||
|
echo "GITEA_TOKEN not set; skipping auto-pr"; exit 0; fi
|
||||||
|
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
||||||
|
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
||||||
|
TITLE="auto: PR for $HEAD_BRANCH"
|
||||||
|
BODY="Automated PR created on push to $HEAD_BRANCH"
|
||||||
|
echo "Creating PR $HEAD_BRANCH -> $BASE_BRANCH for $OWNER/$NAME"
|
||||||
|
HTTP_CODE=$(curl -sS -o /tmp/pr_resp.json -w "%{http_code}" -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: token ${CI_TOKEN}" \
|
||||||
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls" \
|
||||||
|
-d "{\"head\":\"${HEAD_BRANCH}\",\"base\":\"${BASE_BRANCH}\",\"title\":\"${TITLE}\",\"body\":\"${BODY}\"}") || true
|
||||||
|
echo "API status: $HTTP_CODE"
|
||||||
|
if [ "$HTTP_CODE" = "201" ]; then
|
||||||
|
echo "PR created"; cat /tmp/pr_resp.json
|
||||||
|
PR_NUMBER=$(cat /tmp/pr_resp.json | sed -n 's/.*"number":\([0-9]*\).*/\1/p' | head -n1)
|
||||||
|
else
|
||||||
|
echo "PR not created (possibly exists). Response:"; cat /tmp/pr_resp.json || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Retry to resolve PR number by listing open PRs and matching head/base
|
||||||
|
i=0
|
||||||
|
while [ -z "${PR_NUMBER:-}" ] && [ $i -lt 10 ]; do
|
||||||
|
i=$((i+1))
|
||||||
|
echo "[retry $i] Resolving PR number for $HEAD_BRANCH -> $BASE_BRANCH"
|
||||||
|
curl -sS -o /tmp/pr_list.json -H "Authorization: token ${CI_TOKEN}" \
|
||||||
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls?state=open" || true
|
||||||
|
# Extract PR number matching head.ref==HEAD_BRANCH and base.ref==BASE_BRANCH
|
||||||
|
PR_NUMBER=$(awk -v hb="$HEAD_BRANCH" -v bb="$BASE_BRANCH" 'BEGIN{RS="},"; pr=""} {
|
||||||
|
if($0 ~ /\"head\":\{[^}]*\"ref\":\"" hb "\"/ && $0 ~ /\"base\":\{[^}]*\"ref\":\"" bb "\"/){
|
||||||
|
if (match($0, /\"number\":([0-9]+)/, m)) { print m[1]; exit }
|
||||||
|
}
|
||||||
|
}' /tmp/pr_list.json)
|
||||||
|
if [ -z "${PR_NUMBER:-}" ]; then sleep 2; fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -n "${PR_NUMBER:-}" ]; then
|
||||||
|
echo "Adding 'automerge' label to PR #$PR_NUMBER"
|
||||||
|
curl -sS -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: token ${CI_TOKEN}" \
|
||||||
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}/labels" \
|
||||||
|
-d '["automerge"]' || true
|
||||||
|
else
|
||||||
|
echo "PR number could not be determined after retries; skipping label add"
|
||||||
|
fi
|
||||||
+9
-17
@@ -34,6 +34,15 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
CI: true
|
CI: true
|
||||||
|
|
||||||
|
- name: Upload Playwright report
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: playwright-report
|
||||||
|
path: playwright-report
|
||||||
|
if-no-files-found: ignore
|
||||||
|
retention-days: 3
|
||||||
|
|
||||||
- name: Auto-merge PR on green
|
- name: Auto-merge PR on green
|
||||||
if: ${{ github.event_name == 'pull_request' }}
|
if: ${{ github.event_name == 'pull_request' }}
|
||||||
env:
|
env:
|
||||||
@@ -47,14 +56,6 @@ jobs:
|
|||||||
echo "CI_TOKEN not set; skipping auto-merge"; exit 0; fi
|
echo "CI_TOKEN not set; skipping auto-merge"; exit 0; fi
|
||||||
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
||||||
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
||||||
echo "Checking labels for PR #$PR_NUMBER on $OWNER/$NAME"
|
|
||||||
LABELS_JSON=$(curl -sS -X GET \
|
|
||||||
-H "Authorization: token ${CI_TOKEN}" \
|
|
||||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}")
|
|
||||||
echo "Labels payload: $LABELS_JSON" | sed 's/.\{200\}$/.../'
|
|
||||||
if ! echo "$LABELS_JSON" | grep -qi '"name":"automerge"'; then
|
|
||||||
echo "Label 'automerge' not present; skipping merge"; exit 0; fi
|
|
||||||
echo "Label 'automerge' present; proceeding to merge"
|
|
||||||
echo "Merging PR #$PR_NUMBER for $OWNER/$NAME"
|
echo "Merging PR #$PR_NUMBER for $OWNER/$NAME"
|
||||||
RESP=$(curl -sS -X POST \
|
RESP=$(curl -sS -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
@@ -62,12 +63,3 @@ jobs:
|
|||||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls/${PR_NUMBER}/merge" \
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls/${PR_NUMBER}/merge" \
|
||||||
-d '{"Do":"merge","MergeMessage":"auto-merge: CI green"}' || true)
|
-d '{"Do":"merge","MergeMessage":"auto-merge: CI green"}' || true)
|
||||||
echo "API response: $RESP"
|
echo "API response: $RESP"
|
||||||
|
|
||||||
- name: Upload Playwright report
|
|
||||||
if: always()
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: playwright-report
|
|
||||||
path: playwright-report
|
|
||||||
if-no-files-found: ignore
|
|
||||||
retention-days: 3
|
|
||||||
|
|||||||
Reference in New Issue
Block a user