-
Notifications
You must be signed in to change notification settings - Fork 8
124 lines (110 loc) · 4.17 KB
/
cli-docs.yml
File metadata and controls
124 lines (110 loc) · 4.17 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
name: Generate CLI Docs and PR to genlayer-docs
on:
workflow_dispatch:
release:
types: [published]
jobs:
generate-and-sync:
# Skip for pre-releases (tags containing '-') unless manually dispatched
if: github.event_name != 'release' || !contains(github.event.release.tag_name, '-')
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout CLI repo
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Determine version for docs
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
echo "value=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
else
# Prefer package.json version when not a release event
echo "value=$(node -p 'require("./package.json").version')" >> $GITHUB_OUTPUT
fi
- name: Generate CLI docs (MDX)
env:
DOCS_CLEAN: 'true'
DOCS_VERSION: ${{ steps.version.outputs.value }}
run: node scripts/generate-cli-docs.mjs | cat
- name: Set up Git (for committing to CLI repo)
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit and push docs back to CLI repo (non-beta releases)
if: github.event_name == 'release' && !contains(github.event.release.tag_name, '-')
run: |
set -euo pipefail
if [ -n "$(git status --porcelain docs/api-references || true)" ]; then
git add docs/api-references
VERSION=${{ steps.version.outputs.value }}
git commit -m "docs(cli): update API reference for ${VERSION}"
git push
else
echo "No docs changes to commit"
fi
- name: Generate docs repo token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.DOCS_SYNC_APP_ID }}
private-key: ${{ secrets.DOCS_SYNC_APP_KEY }}
repositories: genlayer-docs
- name: Checkout docs repo
uses: actions/checkout@v4
with:
repository: genlayerlabs/genlayer-docs
token: ${{ steps.app-token.outputs.token }}
path: docs-repo
fetch-depth: 0
- name: Sync and push docs
working-directory: docs-repo
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
rm -rf pages/api-references/genlayer-cli
mkdir -p pages/api-references/genlayer-cli
rsync -a "${{ github.workspace }}/docs/api-references/" pages/api-references/genlayer-cli/
# Copy README as sibling file (strip badges/emojis)
sed -E '/^\[!\[.*\]\(https:\/\/(img\.shields\.io|dcbadge|badge\.fury)/d' "${{ github.workspace }}/README.md" > pages/api-references/genlayer-cli.mdx
# Write _meta.json
cat > pages/api-references/genlayer-cli/_meta.json << 'METAEOF'
{
"init": "init",
"up": "up",
"stop": "stop",
"new": "new",
"config": "config",
"network": "network",
"deploy": "deploy",
"call": "call",
"write": "write",
"schema": "schema",
"code": "code",
"receipt": "receipt",
"trace": "trace",
"appeal": "appeal",
"appeal-bond": "appeal-bond",
"account": "account",
"staking": "staking",
"localnet": "localnet",
"update": "update"
}
METAEOF
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to commit"
exit 0
fi
git add pages/api-references/genlayer-cli pages/api-references/genlayer-cli.mdx
git commit -m "docs(cli): sync API reference ${{ steps.version.outputs.value }}"
git push