diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2e49cf139..6c5d363b9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,17 +50,34 @@ jobs: git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - BRANCH="docs/auto-update-$(date +%s)" - git checkout -b "$BRANCH" + EXISTING_BRANCH=$(gh pr list --author "app/github-actions" --search "docs: regenerate API documentation in:title" --state open --json headRefName --jq '.[0].headRefName' 2>/dev/null || echo "") + CREATE_PR=true + + if [ -n "$EXISTING_BRANCH" ] && [ "$EXISTING_BRANCH" != "null" ]; then + BRANCH="$EXISTING_BRANCH" + echo "Found existing docs PR on branch $BRANCH, updating it" + git checkout -B "$BRANCH" + CREATE_PR=false + else + BRANCH="docs/auto-update-$(date +%s)" + git checkout -b "$BRANCH" + fi + git add docs/ + if git diff --cached --quiet; then + echo "No new docs changes to commit" + exit 0 + fi git commit -m "docs: regenerate API documentation" - git push origin "$BRANCH" + git push --force-with-lease origin "$BRANCH" - gh pr create \ - --title "docs: regenerate API documentation" \ - --body "Automated documentation update from release" \ - --base main \ - --head "$BRANCH" + if [ "$CREATE_PR" = true ]; then + gh pr create \ + --title "docs: regenerate API documentation" \ + --body "Automated documentation update from release" \ + --base main \ + --head "$BRANCH" + fi else echo "No changes in generated docs" fi