Skip to content

Commit 52ff683

Browse files
committed
ci: Add automated CLI documentation sync workflow
This adds a GitHub Actions workflow and supporting script to automatically sync CLI documentation from the docker/cli repository on a daily schedule. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 86fdcb4 commit 52ff683

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: sync-cli-docs
2+
3+
on:
4+
schedule:
5+
# Run daily at 02:00 UTC
6+
- cron: '0 2 * * *'
7+
workflow_dispatch:
8+
pull_request:
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
sync-cli-docs:
16+
runs-on: ubuntu-24.04
17+
steps:
18+
-
19+
name: Checkout docs repo
20+
uses: actions/checkout@v5
21+
with:
22+
fetch-depth: 0
23+
-
24+
name: Get version from hugo.yaml
25+
id: get-version
26+
run: |
27+
VERSION=$(grep "docker_ce_version:" hugo.yaml | awk '{print $2}' | tr -d '"')
28+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
29+
-
30+
name: Checkout docker/cli repo
31+
uses: actions/checkout@v5
32+
with:
33+
repository: docker/cli
34+
path: cli-source
35+
ref: v"${{ steps.get-version.outputs.version }}"
36+
fetch-depth: 0
37+
-
38+
name: Add upstream remote for docker/cli
39+
run: |
40+
cd cli-source
41+
git remote add upstream https://github.com/docker/cli.git
42+
git fetch upstream
43+
-
44+
name: Create update branch
45+
id: create-branch
46+
run: |
47+
BRANCH_NAME="bot/sync-cli-docs-$(date +%Y%m%d-%H%M%S)"
48+
git checkout -b "$BRANCH_NAME"
49+
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
50+
-
51+
name: Run sync script
52+
id: sync
53+
run: |
54+
if ./hack/sync-cli-docs.sh HEAD cli-source; then
55+
echo "changes=true" >> "$GITHUB_OUTPUT"
56+
echo "Changes detected - syncing CLI docs" >> "$GITHUB_STEP_SUMMARY"
57+
else
58+
echo "changes=false" >> "$GITHUB_OUTPUT"
59+
echo "No changes to sync - CLI docs are up to date" >> "$GITHUB_STEP_SUMMARY"
60+
fi
61+
62+
-
63+
name: Show PR
64+
if: steps.sync.outputs.changes == 'true'
65+
run: |
66+
git show "${{ steps.create-branch.outputs.branch_name }}"
67+
-
68+
name: Create Pull Request
69+
if: steps.sync.outputs.changes == 'true' && github.event_name != 'pull_request'
70+
env:
71+
GH_TOKEN: ${{ github.token }}
72+
PR_BODY: |
73+
## Summary
74+
75+
Automated sync of CLI documentation from docker/cli repository.
76+
run: |
77+
git push origin "${{ steps.create-branch.outputs.branch_name }}"
78+
gh pr create \
79+
--title "cli: sync docs with docker/cli" \
80+
--body "$PR_BODY" \
81+
--base main \
82+
--head "${{ steps.create-branch.outputs.branch_name }}"

hack/sync-cli-docs.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
5+
main() {
6+
local branch_name="${1:-upstream/master}"
7+
local cli_source="${2:-$HOME/src/cli}"
8+
local worktree_dir="./internal-update-cli-docs"
9+
10+
(
11+
GIT_DIR="$cli_source/.git"
12+
GIT_DIR="$GIT_DIR" git fetch upstream
13+
GIT_DIR="$GIT_DIR" git worktree add "$worktree_dir" "$branch_name"
14+
) || return $?
15+
trap "GIT_DIR=\"$cli_source/.git\" git worktree remove \"$worktree_dir\" --force" EXIT
16+
17+
(cd "$worktree_dir"; make -f docker.Makefile yamldocs) || return $?
18+
cp "$worktree_dir"/docs/yaml/*.yaml ./data/engine-cli/
19+
20+
if git diff --quiet "./data/engine-cli/*.yaml"; then
21+
printf "\e[32m✅ Already up to date\e[0m\n"
22+
return 1
23+
fi
24+
25+
echo -e "ℹ️ Changes detected:"
26+
git diff --stat "./data/engine-cli/*.yaml" || true
27+
28+
NICE_GIT_REF=$(cd "$worktree_dir" && git describe --always --dirty) || return $?
29+
30+
git add "./data/engine-cli/*.yaml"
31+
git commit -s -S -m "cli: sync docs with docker/cli $NICE_GIT_REF"
32+
33+
printf "\e[32m✅ Committed changes\e[0m\n"
34+
return 0
35+
}
36+
37+
main "$@"

0 commit comments

Comments
 (0)