Skip to content

Commit fb361a2

Browse files
committed
ci: use create-pull-request action for cli sync
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
1 parent 91fa587 commit fb361a2

2 files changed

Lines changed: 26 additions & 54 deletions

File tree

.github/workflows/sync-cli-docs.yml

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
required: false
1212
default: ""
1313
pull_request:
14+
paths:
15+
- '.github/workflows/sync-cli-docs.yml'
16+
- 'hack/sync-cli-docs.sh'
1417

1518
permissions:
1619
contents: write
@@ -48,53 +51,33 @@ jobs:
4851
path: cli-source
4952
ref: ${{ steps.get-version.outputs.version }}
5053
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-
git config user.name "github-actions[bot]"
59-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
6054
-
6155
name: Run sync script
6256
id: sync
63-
run: |
64-
set +e
65-
./hack/sync-cli-docs.sh HEAD cli-source
66-
EXIT_CODE=$?
67-
set -e
68-
69-
if [ $EXIT_CODE -eq 0 ]; then
70-
echo "changes=true" >> "$GITHUB_OUTPUT"
71-
echo "Changes detected - syncing CLI docs" >> "$GITHUB_STEP_SUMMARY"
72-
elif [ $EXIT_CODE -eq 100 ]; then
73-
echo "changes=false" >> "$GITHUB_OUTPUT"
74-
echo "No changes to sync - CLI docs are up to date" >> "$GITHUB_STEP_SUMMARY"
75-
else
76-
echo "::error::Script failed with exit code $EXIT_CODE"
77-
exit $EXIT_CODE
78-
fi
79-
80-
-
81-
name: Show PR
82-
if: steps.sync.outputs.changes == 'true'
83-
run: |
84-
git show "${{ steps.create-branch.outputs.branch_name }}"
57+
run: ./hack/sync-cli-docs.sh HEAD cli-source
8558
-
8659
name: Create Pull Request
87-
if: steps.sync.outputs.changes == 'true' && github.event_name != 'pull_request'
88-
env:
89-
GH_TOKEN: ${{ github.token }}
90-
PR_BODY: |
60+
id: cpr
61+
uses: peter-evans/create-pull-request@v7
62+
with:
63+
branch: bot/sync-cli-docs-${{ steps.get-version.outputs.version }}
64+
base: main
65+
delete-branch: true
66+
add-paths: |
67+
data/engine-cli/*.yaml
68+
commit-message: "cli: sync docs with docker/cli ${{ steps.sync.outputs.git_ref }}"
69+
title: "cli: sync docs with docker/cli"
70+
body: |
9171
## Summary
9272
9373
Automated sync of CLI documentation from docker/cli repository.
74+
75+
**CLI version**: ${{ steps.get-version.outputs.version }}
76+
**Git ref**: ${{ steps.sync.outputs.git_ref }}
77+
reviewers: "@engine"
78+
-
79+
name: Check outputs
80+
if: ${{ steps.cpr.outputs.pull-request-number }}
9481
run: |
95-
git push -u origin "${{ steps.create-branch.outputs.branch_name }}"
96-
gh pr create \
97-
--title "cli: sync docs with docker/cli" \
98-
--body "$PR_BODY" \
99-
--base main \
100-
--head "${{ steps.create-branch.outputs.branch_name }}"
82+
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
83+
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"

hack/sync-cli-docs.sh

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,10 @@ main() {
1717
(set -e; cd "$worktree_dir"; make -f docker.Makefile yamldocs || { printf "::error::Failed to generate YAML docs!\n"; exit 1; }) || return $?
1818
cp "$worktree_dir"/docs/yaml/*.yaml ./data/engine-cli/
1919

20-
if git diff --quiet "./data/engine-cli/*.yaml"; then
21-
printf "\e[32m✅ Already up to date\e[0m\n"
22-
return 100
23-
fi
24-
25-
echo -e "ℹ️ Changes detected:"
26-
git diff --stat "./data/engine-cli/*.yaml" || true
27-
2820
NICE_GIT_REF=$(cd "$worktree_dir" && git describe --always --dirty) || return $?
21+
echo "git_ref=$NICE_GIT_REF" >> "${GITHUB_OUTPUT:-/dev/stdout}"
2922

30-
git add "./data/engine-cli/*.yaml"
31-
32-
git commit -m "cli: sync docs with docker/cli $NICE_GIT_REF"
33-
34-
printf "\e[32m✅ Committed changes\e[0m\n"
23+
printf "\e[32m✅ Synced CLI docs from %s\e[0m\n" "$NICE_GIT_REF"
3524
return 0
3625
}
3726

0 commit comments

Comments
 (0)