-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (98 loc) · 3.74 KB
/
sync-cli-docs.yml
File metadata and controls
117 lines (98 loc) · 3.74 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
name: Sync CLI Docs to KeeperHub
on:
workflow_dispatch:
release:
types: [published]
permissions:
contents: read
concurrency:
group: cli-docs-sync
cancel-in-progress: true
jobs:
sync:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout CLI repo
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Regenerate CLI docs
run: go generate ./docs/...
- name: Checkout KeeperHub repo
uses: actions/checkout@v4
with:
repository: KeeperHub/keeperhub
token: ${{ secrets.KEEPERHUB_PAT }}
path: keeperhub
ref: staging
- name: Sync docs to KeeperHub
id: sync
run: |
CLI_DOCS="docs"
KH_DOCS="keeperhub/docs/cli"
# Sync command reference files
rm -rf "$KH_DOCS/commands/"kh*.md
cp "$CLI_DOCS/"kh*.md "$KH_DOCS/commands/"
# Sync hand-written guides (add frontmatter for Nextra)
for file in quickstart.md concepts.md; do
TITLE=$(head -1 "$CLI_DOCS/$file" | sed 's/^# //')
# Build the Nextra-compatible version with frontmatter
{
echo "---"
echo "title: \"$TITLE\""
echo "description: \"KeeperHub CLI $TITLE\""
echo "---"
echo ""
cat "$CLI_DOCS/$file"
} > "$KH_DOCS/$file"
done
# Regenerate commands/_meta.ts from the synced files
{
echo "export default {"
for f in "$KH_DOCS/commands/"kh*.md; do
stem=$(basename "$f" .md)
label=$(echo "$stem" | sed 's/_/ /g')
# Quote keys that contain hyphens
if echo "$stem" | grep -q '-'; then
echo " \"$stem\": \"$label\","
else
echo " $stem: \"$label\","
fi
done
echo "};"
} > "$KH_DOCS/commands/_meta.ts"
# Fix internal links in quickstart and concepts for Nextra
sed -i 's|\[Command reference\](kh\.md)|[Command reference](./commands/kh)|g' "$KH_DOCS/quickstart.md"
sed -i 's|\[concepts\.md\](concepts\.md)|[Concepts](./concepts)|g' "$KH_DOCS/quickstart.md"
sed -i 's|\[quickstart\.md\](quickstart\.md)|[Quickstart](./quickstart)|g' "$KH_DOCS/concepts.md"
# Check if anything changed
cd keeperhub
if git diff --quiet && [ -z "$(git ls-files --others --exclude-standard docs/cli/)" ]; then
echo "No changes to sync."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Create PR in KeeperHub
if: steps.sync.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.KEEPERHUB_PAT }}
RELEASE_TAG: ${{ github.event.release.tag_name || 'manual' }}
run: |
cd keeperhub
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Sanitize tag for branch name
SAFE_TAG=$(echo "$RELEASE_TAG" | sed 's/[^a-zA-Z0-9.-]/-/g')
BRANCH="docs/cli-sync-${SAFE_TAG}"
git checkout -b "$BRANCH"
git add docs/cli/
git commit -m "docs: sync CLI reference from ${RELEASE_TAG}"
git push origin "$BRANCH"
gh pr create \
--base staging \
--title "docs: sync CLI reference from ${RELEASE_TAG}" \
--body "Auto-synced CLI command reference from cli@${RELEASE_TAG}. Changes generated by go generate ./docs/... and copied to docs/cli/."