-
Notifications
You must be signed in to change notification settings - Fork 9
121 lines (104 loc) · 4.31 KB
/
cli-docs.yml
File metadata and controls
121 lines (104 loc) · 4.31 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
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@v6
- 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: Checkout docs repo
uses: actions/checkout@v6
with:
repository: genlayerlabs/genlayer-docs
token: ${{ secrets.DOCS_REPO_TOKEN || secrets.GITHUB_TOKEN }}
path: docs-repo
fetch-depth: 0
- name: Prepare branch
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"
BRANCH="docs/cli/${{ github.repository }}-${{ github.ref_name }}-${{ github.run_id }}"
git switch -c "$BRANCH" || git switch "$BRANCH"
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
- name: Sync CLI docs into docs repo
run: |
set -euo pipefail
mkdir -p docs-repo/pages/api-references/genlayer-cli
rsync -a --delete "${{ github.workspace }}/docs/api-references/" docs-repo/pages/api-references/genlayer-cli/
echo "Synced files:" && ls -la docs-repo/pages/api-references/genlayer-cli | cat
- name: Commit changes
working-directory: docs-repo
run: |
set -euo pipefail
if [ -n "$(git status --porcelain)" ]; then
git add pages/api-references/genlayer-cli
git commit -m "docs(cli): sync API reference ${VERSION:-${{ env.VERSION }}}"
git push --set-upstream origin "$BRANCH"
echo "HAS_CHANGES=true" >> $GITHUB_ENV
else
echo "No changes to commit"
echo "HAS_CHANGES=false" >> $GITHUB_ENV
fi
- name: Create PR in docs repo
if: env.HAS_CHANGES == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.DOCS_REPO_TOKEN || secrets.GITHUB_TOKEN }}
path: docs-repo
commit-message: "docs(cli): sync API reference ${{ steps.version.outputs.value }}"
branch: ${{ env.BRANCH }}
title: "docs(cli): sync CLI API reference ${{ steps.version.outputs.value }}"
body: |
This PR updates the GenlayerCLI API Reference generated automatically from `${{ github.repository }}`.
- Version: `${{ steps.version.outputs.value }}`
- Source commit: `${{ github.sha }}`
- Trigger: `${{ github.event_name }}`
labels: documentation, cli