Skip to content

Commit 8de91a8

Browse files
authored
Merge pull request #23925 from vvoland/gha-sync-cli-docs-singlepr
gha/sync-cli-docs: Update existing PR instead of creating new ones
2 parents 772dfc3 + 1b1b173 commit 8de91a8

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

.github/workflows/sync-cli-docs.yml

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ permissions:
1919
contents: write
2020
pull-requests: write
2121

22+
env:
23+
BRANCH_NAME: "bot/sync-cli-docs"
24+
2225
jobs:
2326
sync-cli-docs:
2427
runs-on: ubuntu-24.04
@@ -54,10 +57,10 @@ jobs:
5457
-
5558
name: Create update branch
5659
id: create-branch
60+
env:
61+
BRANCH_NAME: ${{ env.BRANCH_NAME }}
5762
run: |
58-
BRANCH_NAME="bot/sync-cli-docs-$(date +%Y%m%d-%H%M%S)"
5963
git checkout -b "$BRANCH_NAME"
60-
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
6164
git config user.name "github-actions[bot]"
6265
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
6366
-
@@ -84,12 +87,13 @@ jobs:
8487
name: Show PR
8588
if: steps.sync.outputs.changes == 'true'
8689
run: |
87-
git show "${{ steps.create-branch.outputs.branch_name }}"
90+
git show "${{ env.BRANCH_NAME }}"
8891
-
89-
name: Create Pull Request
92+
name: Create or update Pull Request
9093
if: steps.sync.outputs.changes == 'true' && github.event_name != 'pull_request'
9194
env:
9295
GH_TOKEN: ${{ github.token }}
96+
BRANCH_NAME: ${{ env.BRANCH_NAME }}
9397
PR_TITLE: "cli: sync docs with cli ${{ steps.get-version.outputs.version }}"
9498
PR_BODY: |
9599
## Summary
@@ -104,27 +108,19 @@ jobs:
104108
> **Reviewer:** Please close and reopen this PR to trigger CI checks.
105109
> See: https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/trigger-a-workflow#triggering-a-workflow-from-a-workflow
106110
run: |
107-
CLI_VERSION="${{ steps.get-version.outputs.version }}"
108-
109-
# Check for existing PR
110-
EXISTING_PR=$(gh pr list --state open --json title,url --jq ".[] | select(.title | contains(\"$PR_TITLE\")) | .url" | head -n 1)
111+
# Check for existing PR from this branch
112+
EXISTING_PR=$(gh pr list --state open --head "$BRANCH_NAME" --json url --jq ".[0].url")
111113
112114
if [ -n "$EXISTING_PR" ]; then
113-
echo "PR already exists for CLI version $CLI_VERSION" >> "$GITHUB_STEP_SUMMARY"
114-
echo "Existing PR: $EXISTING_PR" >> "$GITHUB_STEP_SUMMARY"
115-
116-
# Add a bump comment
117-
gh pr comment "$EXISTING_PR" --body "🔄 @engine PTAL"
118-
echo "Added bump comment to PR" >> "$GITHUB_STEP_SUMMARY"
119-
120-
exit 0
115+
echo "Updating existing PR: $EXISTING_PR" >> "$GITHUB_STEP_SUMMARY"
116+
git push -u origin "$BRANCH_NAME" --force
117+
gh pr edit "$EXISTING_PR" --title "$PR_TITLE" --body "$PR_BODY"
118+
else
119+
echo "Creating new PR" >> "$GITHUB_STEP_SUMMARY"
120+
git push -u origin "$BRANCH_NAME"
121+
gh pr create \
122+
--title "$PR_TITLE" \
123+
--body "$PR_BODY" \
124+
--base main \
125+
--head "$BRANCH_NAME"
121126
fi
122-
123-
echo "Creating PR for CLI version $CLI_VERSION" >> "$GITHUB_STEP_SUMMARY"
124-
125-
git push -u origin "${{ steps.create-branch.outputs.branch_name }}"
126-
gh pr create \
127-
--title "$PR_TITLE" \
128-
--body "$PR_BODY" \
129-
--base main \
130-
--head "${{ steps.create-branch.outputs.branch_name }}"

0 commit comments

Comments
 (0)