Skip to content

Commit bc3d914

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 bc3d914

File tree

2 files changed

+130
-0
lines changed

2 files changed

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