Repository navigation
155 lines (141 loc) · 5.6 KB
/
Copy pathsync-cli-docs.yml
File metadata and controls
155 lines (141 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: sync-cli-docs
on:
schedule:
# Run daily at 02:00 UTC
- cron: '0 2 * * *'
workflow_dispatch:
inputs:
version:
description: "(optional) Docker version - defaults to docker_ce_version in hugo.yaml"
required: false
default: ""
pull_request:
paths:
- '.github/workflows/sync-cli-docs.yml'
- 'hack/sync-cli-docs.sh'
permissions:
contents: write
pull-requests: write
env:
BRANCH_NAME: "bot/sync-cli-docs"
MOBY_MODULE: "github.com/moby/moby/v2"
jobs:
sync-cli-docs:
runs-on: ubuntu-24.04
steps:
-
name: Checkout docs repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
with:
fetch-depth: 0
-
name: Get version from hugo.yaml
id: get-version
run: |
if [ -n "${{ inputs.version }}" ]; then
VERSION="${{ inputs.version }}"
else
VERSION=v$(grep "docker_ce_version:" hugo.yaml | awk '{print $2}' | tr -d '"')
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Docker CLI version: **$VERSION**" | tee -a "$GITHUB_STEP_SUMMARY"
-
name: Checkout docker/cli repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
with:
repository: docker/cli
path: cli-source
ref: ${{ steps.get-version.outputs.version }}
fetch-depth: 0
-
name: Create update branch
id: create-branch
env:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
run: |
git checkout -b "$BRANCH_NAME"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
echo "base=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
-
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: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
-
name: Sync moby/moby docs
id: moby
env:
VERSION: ${{ steps.get-version.outputs.version }}
run: |
TARGET=$(go list -m -f '{{ .Version }}' "${MOBY_MODULE}@docker-${VERSION}")
go mod edit -require "${MOBY_MODULE}@${TARGET}"
make vendor
if [ -z "$(git status --porcelain -- go.mod go.sum _vendor)" ]; then
echo "changes=false" >> "$GITHUB_OUTPUT"
echo "No changes to sync - moby/moby docs are up to date" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
git add go.mod go.sum _vendor
git commit -m "vendor: ${MOBY_MODULE} ${TARGET} (docker-${VERSION})"
echo "changes=true" >> "$GITHUB_OUTPUT"
echo "Changes detected - syncing moby/moby docs" >> "$GITHUB_STEP_SUMMARY"
-
name: Show PR
if: steps.sync.outputs.changes == 'true' || steps.moby.outputs.changes == 'true'
run: |
git log -p "${{ steps.create-branch.outputs.base }}..${{ env.BRANCH_NAME }}"
-
name: Create or update Pull Request
if: (steps.sync.outputs.changes == 'true' || steps.moby.outputs.changes == 'true') && github.event_name != 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
BRANCH_NAME: ${{ env.BRANCH_NAME }}
PR_TITLE: "cli: sync docs with cli ${{ steps.get-version.outputs.version }}"
PR_BODY: |
## Summary
Automated sync of CLI documentation from the docker/cli repository and Engine documentation from the moby/moby repository.
**Docker 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: |
# Check for existing open PR from this branch
EXISTING_PR=$(gh pr list --state open --head "$BRANCH_NAME" --json url --jq ".[0].url // empty")
if [ -n "$EXISTING_PR" ]; then
echo "Updating existing PR: $EXISTING_PR" >> "$GITHUB_STEP_SUMMARY"
git push -u origin "$BRANCH_NAME" --force
gh pr edit "$EXISTING_PR" --title "$PR_TITLE" --body "$PR_BODY"
else
# Check if a closed PR with the same title already exists
CLOSED_PR=$(gh pr list --state closed --search "$PR_TITLE in:title" --json url --jq ".[0].url // empty")
if [ -n "$CLOSED_PR" ]; then
echo "A closed PR already exists for this version: $CLOSED_PR" >> "$GITHUB_STEP_SUMMARY"
echo "Skipping PR creation."
exit 0
fi
echo "Creating new PR" >> "$GITHUB_STEP_SUMMARY"
git push -u origin "$BRANCH_NAME"
gh pr create \
--title "$PR_TITLE" \
--body "$PR_BODY" \
--base main \
--head "$BRANCH_NAME"
fi