@@ -19,6 +19,9 @@ permissions:
1919 contents : write
2020 pull-requests : write
2121
22+ env :
23+ BRANCH_NAME : " bot/sync-cli-docs"
24+
2225jobs :
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