Skip to content

Commit e902fc6

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 <pawel.gronowski@docker.com>
1 parent 86fdcb4 commit e902fc6

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
# TODO(vvoland): Remove this after 29.2.0 is released
38+
# VERSION=v${VERSION}
39+
VERSION=60f06cb2df3df36ddfb531c1dae8c6fa96e5f9e7
40+
41+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
42+
echo "Docker CLI version: **$VERSION**" | tee -a "$GITHUB_STEP_SUMMARY"
43+
-
44+
name: Checkout docker/cli repo
45+
uses: actions/checkout@v5
46+
with:
47+
repository: docker/cli
48+
path: cli-source
49+
ref: ${{ steps.get-version.outputs.version }}
50+
fetch-depth: 0
51+
-
52+
name: Create update branch
53+
id: create-branch
54+
run: |
55+
BRANCH_NAME="bot/sync-cli-docs-$(date +%Y%m%d-%H%M%S)"
56+
git checkout -b "$BRANCH_NAME"
57+
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
58+
-
59+
name: Run sync script
60+
id: sync
61+
run: |
62+
set +e
63+
./hack/sync-cli-docs.sh HEAD cli-source
64+
EXIT_CODE=$?
65+
set -e
66+
67+
if [ $EXIT_CODE -eq 0 ]; then
68+
echo "changes=true" >> "$GITHUB_OUTPUT"
69+
echo "Changes detected - syncing CLI docs" >> "$GITHUB_STEP_SUMMARY"
70+
elif [ $EXIT_CODE -eq 100 ]; then
71+
echo "changes=false" >> "$GITHUB_OUTPUT"
72+
echo "No changes to sync - CLI docs are up to date" >> "$GITHUB_STEP_SUMMARY"
73+
else
74+
echo "::error::Script failed with exit code $EXIT_CODE"
75+
exit $EXIT_CODE
76+
fi
77+
78+
-
79+
name: Show PR
80+
if: steps.sync.outputs.changes == 'true'
81+
run: |
82+
git show "${{ steps.create-branch.outputs.branch_name }}"
83+
-
84+
name: Create Pull Request
85+
if: steps.sync.outputs.changes == 'true' && github.event_name != 'pull_request'
86+
env:
87+
GH_TOKEN: ${{ github.token }}
88+
PR_BODY: |
89+
## Summary
90+
91+
Automated sync of CLI documentation from docker/cli repository.
92+
run: |
93+
git push origin "${{ steps.create-branch.outputs.branch_name }}"
94+
gh pr create \
95+
--title "cli: sync docs with docker/cli" \
96+
--body "$PR_BODY" \
97+
--base main \
98+
--head "${{ steps.create-branch.outputs.branch_name }}"

hack/sync-cli-docs.sh

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

0 commit comments

Comments
 (0)