Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 24 additions & 41 deletions .github/workflows/sync-cli-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
required: false
default: ""
pull_request:
paths:
- '.github/workflows/sync-cli-docs.yml'
- 'hack/sync-cli-docs.sh'

permissions:
contents: write
Expand Down Expand Up @@ -48,53 +51,33 @@ jobs:
path: cli-source
ref: ${{ steps.get-version.outputs.version }}
fetch-depth: 0
-
name: Create update branch
id: create-branch
run: |
BRANCH_NAME="bot/sync-cli-docs-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
-
name: Run sync script
id: sync
run: |
set +e
./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"
elif [ $EXIT_CODE -eq 100 ]; then
echo "changes=false" >> "$GITHUB_OUTPUT"
echo "No changes to sync - CLI docs are up to date" >> "$GITHUB_STEP_SUMMARY"
else
echo "::error::Script failed with exit code $EXIT_CODE"
exit $EXIT_CODE
fi

-
name: Show PR
if: steps.sync.outputs.changes == 'true'
run: |
git show "${{ steps.create-branch.outputs.branch_name }}"
run: ./hack/sync-cli-docs.sh HEAD cli-source
-
name: Create Pull Request
if: steps.sync.outputs.changes == 'true' && github.event_name != 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
PR_BODY: |
id: cpr
uses: peter-evans/create-pull-request@v7
with:
branch: bot/sync-cli-docs-${{ steps.get-version.outputs.version }}
base: main
delete-branch: true
add-paths: |
data/engine-cli/*.yaml
commit-message: "cli: sync docs with docker/cli ${{ steps.sync.outputs.git_ref }}"
title: "cli: sync docs with docker/cli"
body: |
## Summary

Automated sync of CLI documentation from docker/cli repository.

**CLI version**: ${{ steps.get-version.outputs.version }}
**Git ref**: ${{ steps.sync.outputs.git_ref }}
reviewers: "@engine"
-
name: Check outputs
if: ${{ steps.cpr.outputs.pull-request-number }}
run: |
git push -u origin "${{ steps.create-branch.outputs.branch_name }}"
gh pr create \
--title "cli: sync docs with docker/cli" \
--body "$PR_BODY" \
--base main \
--head "${{ steps.create-branch.outputs.branch_name }}"
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
15 changes: 2 additions & 13 deletions hack/sync-cli-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,10 @@ main() {
(set -e; cd "$worktree_dir"; make -f docker.Makefile yamldocs || { printf "::error::Failed to generate YAML docs!\n"; exit 1; }) || return $?
cp "$worktree_dir"/docs/yaml/*.yaml ./data/engine-cli/

if git diff --quiet "./data/engine-cli/*.yaml"; then
printf "\e[32m✅ Already up to date\e[0m\n"
return 100
fi

echo -e "ℹ️ Changes detected:"
git diff --stat "./data/engine-cli/*.yaml" || true

NICE_GIT_REF=$(cd "$worktree_dir" && git describe --always --dirty) || return $?
echo "git_ref=$NICE_GIT_REF" >> "${GITHUB_OUTPUT:-/dev/stdout}"

git add "./data/engine-cli/*.yaml"

git commit -m "cli: sync docs with docker/cli $NICE_GIT_REF"

printf "\e[32m✅ Committed changes\e[0m\n"
printf "\e[32m✅ Synced CLI docs from %s\e[0m\n" "$NICE_GIT_REF"
return 0
}

Expand Down
Loading