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>
This commit is contained in:
Paweł Gronowski
2026-01-02 11:28:50 +01:00
parent 91fa58799a
commit 72d3e14405

View File

@@ -65,7 +65,7 @@ jobs:
./hack/sync-cli-docs.sh HEAD cli-source
EXIT_CODE=$?
set -e
if [ $EXIT_CODE -eq 0 ]; then
echo "changes=true" >> "$GITHUB_OUTPUT"
echo "Changes detected - syncing CLI docs" >> "$GITHUB_STEP_SUMMARY"
@@ -87,14 +87,41 @@ jobs:
if: steps.sync.outputs.changes == 'true' && github.event_name != 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
PR_TITLE: "cli: sync docs with cli ${{ steps.get-version.outputs.version }}"
PR_BODY: |
## Summary
Automated sync of CLI documentation from docker/cli repository.
**CLI Version:** ${{ steps.get-version.outputs.version }}
---
> [!IMPORTANT]
> **Reviewer:** Please close and reopen this PR to trigger CI checks.
> See: https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/trigger-a-workflow#triggering-a-workflow-from-a-workflow
run: |
CLI_VERSION="${{ steps.get-version.outputs.version }}"
# Check for existing PR
EXISTING_PR=$(gh pr list --state open --json title,url --jq ".[] | select(.title | contains(\"$PR_TITLE\")) | .url" | head -n 1)
if [ -n "$EXISTING_PR" ]; then
echo "PR already exists for CLI version $CLI_VERSION" >> "$GITHUB_STEP_SUMMARY"
echo "Existing PR: $EXISTING_PR" >> "$GITHUB_STEP_SUMMARY"
# Add a bump comment
gh pr comment "$EXISTING_PR" --body "🔄 @engine PTAL"
echo "Added bump comment to PR" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
echo "Creating PR for CLI version $CLI_VERSION" >> "$GITHUB_STEP_SUMMARY"
git push -u origin "${{ steps.create-branch.outputs.branch_name }}"
gh pr create \
--title "cli: sync docs with docker/cli" \
--title "$PR_TITLE" \
--body "$PR_BODY" \
--base main \
--head "${{ steps.create-branch.outputs.branch_name }}"