ci: create pull requests with the built-in Gitea token
Auto Create PR / create-pr (push) Failing after 0s
Auto Create PR / create-pr (push) Failing after 0s
Open a PR to main on every push to another branch, using the automatic job token and the Gitea API instead of the GitHub CLI and a GH_TOKEN. Run on the same act_runner label as the deploy workflow.
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
name: Auto Create PR
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches-ignore:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
create-pr:
|
||||||
|
# Same act_runner label as deploy.yml (config: labels: ["cohaise:host"]).
|
||||||
|
runs-on: cohaise
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Create Pull Request
|
||||||
|
env:
|
||||||
|
# Built-in job token: no secret or personal token to configure.
|
||||||
|
TOKEN: ${{ github.token }}
|
||||||
|
API_URL: ${{ github.api_url }}
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
BRANCH: ${{ github.ref_name }}
|
||||||
|
MESSAGE: ${{ github.event.head_commit.message }}
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
TITLE=$(printf '%s' "$MESSAGE" | head -n 1)
|
||||||
|
TITLE=${TITLE:-"Update $BRANCH"}
|
||||||
|
TITLE=$(printf '%s' "$TITLE" | sed 's/\\/\\\\/g; s/"/\\"/g')
|
||||||
|
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user