Skip to content

Commit 72d3e14

Browse files
committed
gha/sync-cli-docs: Detect existing PR
Add deduplication logic to prevent multiple PRs for the same CLI version and enhance PR management. When an existing PR is found, the workflow adds a bump comment instead of creating a duplicate. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
1 parent 91fa587 commit 72d3e14

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
./hack/sync-cli-docs.sh HEAD cli-source
6666
EXIT_CODE=$?
6767
set -e
68-
68+
6969
if [ $EXIT_CODE -eq 0 ]; then
7070
echo "changes=true" >> "$GITHUB_OUTPUT"
7171
echo "Changes detected - syncing CLI docs" >> "$GITHUB_STEP_SUMMARY"
@@ -87,14 +87,41 @@ jobs:
8787
if: steps.sync.outputs.changes == 'true' && github.event_name != 'pull_request'
8888
env:
8989
GH_TOKEN: ${{ github.token }}
90+
PR_TITLE: "cli: sync docs with cli ${{ steps.get-version.outputs.version }}"
9091
PR_BODY: |
9192
## Summary
9293
9394
Automated sync of CLI documentation from docker/cli repository.
95+
96+
**CLI Version:** ${{ steps.get-version.outputs.version }}
97+
98+
---
99+
100+
> [!IMPORTANT]
101+
> **Reviewer:** Please close and reopen this PR to trigger CI checks.
102+
> See: https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/trigger-a-workflow#triggering-a-workflow-from-a-workflow
94103
run: |
104+
CLI_VERSION="${{ steps.get-version.outputs.version }}"
105+
106+
# Check for existing PR
107+
EXISTING_PR=$(gh pr list --state open --json title,url --jq ".[] | select(.title | contains(\"$PR_TITLE\")) | .url" | head -n 1)
108+
109+
if [ -n "$EXISTING_PR" ]; then
110+
echo "PR already exists for CLI version $CLI_VERSION" >> "$GITHUB_STEP_SUMMARY"
111+
echo "Existing PR: $EXISTING_PR" >> "$GITHUB_STEP_SUMMARY"
112+
113+
# Add a bump comment
114+
gh pr comment "$EXISTING_PR" --body "🔄 @engine PTAL"
115+
echo "Added bump comment to PR" >> "$GITHUB_STEP_SUMMARY"
116+
117+
exit 0
118+
fi
119+
120+
echo "Creating PR for CLI version $CLI_VERSION" >> "$GITHUB_STEP_SUMMARY"
121+
95122
git push -u origin "${{ steps.create-branch.outputs.branch_name }}"
96123
gh pr create \
97-
--title "cli: sync docs with docker/cli" \
124+
--title "$PR_TITLE" \
98125
--body "$PR_BODY" \
99126
--base main \
100127
--head "${{ steps.create-branch.outputs.branch_name }}"

0 commit comments

Comments
 (0)