fix pr create

This commit is contained in:
Meliox 2026-06-07 16:55:07 +02:00
parent 07b0392399
commit 5ffbaf7b07

View File

@ -1,23 +1,22 @@
name: Open / Update PR name: Open / Update Version Bump PR
# Triggered by any push to a non-main branch where src/ files changed. # Triggered by any push to main where src/ files changed.
# Opens a PR to main if one does not exist, or updates its body if it does. # This happens when a feature PR is merged to main.
# Creates a dedicated chore/version-bump branch and opens a PR from it.
# When creating a new PR it assigns the default "bump:patch" label. # When creating a new PR it assigns the default "bump:patch" label.
# When updating an existing PR the label is NOT changed, preserving any # When updating an existing PR the label is NOT changed, preserving any
# manual label change (e.g. bump:minor, bump:major) made by a reviewer. # manual label change (e.g. bump:minor, bump:major) made by a reviewer.
# # The bot guard prevents this from firing on changelog commits.
# Pre-requisite: create the label once in the repo:
# gh label create "bump:patch" --color "0075ca" --description "Default patch-version bump"
on: on:
push: push:
branches-ignore: branches:
- main - main
paths: paths:
- 'src/**' - 'src/**'
permissions: permissions:
contents: read contents: write
pull-requests: write pull-requests: write
jobs: jobs:
@ -29,43 +28,57 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Collect src/ commits on this branch - name: Collect src/ commits from merge
id: commits id: commits
run: | run: |
LOG=$(git log "origin/main..HEAD" --oneline -- src/ | head -50) LOG=$(git log "HEAD~1..HEAD" --oneline -- src/ | head -50)
EOF=$(dd if=/dev/urandom bs=15 count=1 2>/dev/null | base64) EOF=$(openssl rand -hex 16)
echo "log<<$EOF" >> "$GITHUB_OUTPUT" echo "log<<$EOF" >> "$GITHUB_OUTPUT"
echo "$LOG" >> "$GITHUB_OUTPUT" echo "$LOG" >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT" echo "$EOF" >> "$GITHUB_OUTPUT"
- name: Create or update PR - name: Create or reset version bump branch
run: |
git checkout -B chore/version-bump
git push origin chore/version-bump --force
- name: Create or update version bump PR
env: env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: ${{ github.ref_name }} COMMITS: ${{ steps.commits.outputs.log }}
COMMITS: ${{ steps.commits.outputs.log }}
run: | run: |
TITLE="feat: $BRANCH" BUMP_BRANCH="chore/version-bump"
VERSION=$(grep -m1 '(' debian/changelog | sed 's/.*(\(.*\)).*/\1/')
TITLE="chore: bump pve-mod to v${VERSION}"
{ {
echo "## Changes in \`$BRANCH\`" echo "## Changes merged to main"
echo "" echo ""
echo "${COMMITS:-No src/ changes detected.}" echo "${COMMITS:-No src/ changes detected.}"
echo ""
echo "---"
echo "*Apply a bump:minor or bump:major label before merging if needed.*"
echo "*Default label is bump:patch.*"
} > /tmp/pr-body.md } > /tmp/pr-body.md
EXISTING=$(gh pr list \ EXISTING=$(gh pr list \
--head "$BRANCH" \ --head "$BUMP_BRANCH" \
--base main \
--json number --jq '.[0].number' 2>/dev/null || true) --json number --jq '.[0].number' 2>/dev/null || true)
if [[ -n "$EXISTING" ]]; then if [[ -n "$EXISTING" ]]; then
gh pr edit "$EXISTING" --body-file /tmp/pr-body.md gh pr edit "$EXISTING" \
echo "Updated PR #$EXISTING body (label unchanged)" --title "$TITLE" \
--body-file /tmp/pr-body.md
echo "Updated PR #${EXISTING} body and title (label unchanged)"
else else
gh pr create \ gh pr create \
--title "$TITLE" \ --title "$TITLE" \
--body-file /tmp/pr-body.md \ --body-file /tmp/pr-body.md \
--base main \ --base main \
--head "$BRANCH" \ --head "$BUMP_BRANCH" \
--label "bump:patch" --label "bump:patch"
echo "Opened new PR with label bump:patch" echo "Opened new version bump PR with label bump:patch"
fi fi