ci: run on the cohaise runner label #1

Merged
Esiah merged 6 commits from feat/nextjs-showcase-crm-refresh into main 2026-11-16 00:08:18 +00:00
Showing only changes of commit 305cfa5631 - Show all commits
+36 -31
View File
@@ -1,47 +1,52 @@
name: Auto Create PR
name: PR — Ouverture automatique
on:
push:
branches-ignore:
- main
branches-ignore: [main]
workflow_dispatch:
jobs:
create-pr:
# Same act_runner label as deploy.yml (config: labels: ["cohaise:host"]).
runs-on: cohaise
runs-on: [self-hosted, cohaise-cloud]
permissions:
contents: read
contents: write
pull-requests: write
steps:
- name: Create Pull Request
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Ouvrir (ou vérifier) la pull request
env:
# Built-in job token: no secret or personal token to configure.
TOKEN: ${{ github.token }}
API_URL: ${{ github.api_url }}
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
API: ${{ github.server_url }}/api/v1
REPO: ${{ github.repository }}
BRANCH: ${{ github.ref_name }}
MESSAGE: ${{ github.event.head_commit.message }}
run: |
set -eu
if [ "$BRANCH" = "main" ]; then
echo "main est la base : aucune PR à ouvrir."
exit 0
fi
title=$(git log -1 --pretty=%s)
body=$(git log -1 --pretty=%b)
[ -n "$body" ] || body="PR automatique de $BRANCH vers main."
TITLE=$(printf '%s' "$MESSAGE" | head -n 1)
TITLE=${TITLE:-"Update $BRANCH"}
TITLE=$(printf '%s' "$TITLE" | sed 's/\\/\\\\/g; s/"/\\"/g')
open=$(curl -fsS -H "Authorization: token $GITEA_TOKEN" \
"$API/repos/$REPO/pulls?state=open&limit=50" \
| python3 -c 'import json,os,sys; b=os.environ["BRANCH"]; print(sum(1 for p in json.load(sys.stdin) if p.get("head", {}).get("ref") == b))')
if [ "$open" -gt 0 ]; then
echo "Une PR est déjà ouverte pour $BRANCH."
exit 0
fi
STATUS=$(curl -sS -o /tmp/pr.json -w '%{http_code}' \
-X POST \
-H "Authorization: token ${TOKEN}" \
-H 'Content-Type: application/json' \
--data "{\"head\":\"${BRANCH}\",\"base\":\"main\",\"title\":\"${TITLE}\",\"body\":\"Automated PR from ${BRANCH} to main.\"}" \
"${API_URL}/repos/${REPO}/pulls")
case "$STATUS" in
201) echo "Pull request created." ;;
409) echo "Pull request already exists." ;;
422) echo "Nothing to open a pull request for." ;;
*)
cat /tmp/pr.json
exit 1
;;
esac
python3 - "$BRANCH" "$title" "$body" <<'PY' | curl -fsS -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
--data-binary @- \
"$API/repos/$REPO/pulls"
import json, sys
branch, title, body = sys.argv[1], sys.argv[2], sys.argv[3]
print(json.dumps({"base": "main", "head": branch, "title": title, "body": body}))
PY
echo "PR créée."