-
-
Notifications
You must be signed in to change notification settings - Fork 5
129 lines (126 loc) · 4.19 KB
/
Copy pathdocs-cli-next.yml
File metadata and controls
129 lines (126 loc) · 4.19 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
name: Build and publish CLI docs
on:
workflow_call:
inputs:
arg:
description: Optional single argument passed before the output directory.
required: false
type: string
default: ""
docs-branch:
description: Branch in ory/docs to update.
required: false
type: string
default: master
output-dir:
description: Relative directory in ory/docs to replace.
required: true
type: string
secrets:
token:
description: Token used only to push the generated documentation.
required: true
jobs:
build:
name: Build CLI docs
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6
with:
go-version-file: go.mod
- name: Generate CLI docs
env:
CLI_DOC_ARG: ${{ inputs.arg }}
run: |
set -euo pipefail
make .bin/clidoc
args=()
if [[ -n "$CLI_DOC_ARG" ]]; then
args+=("$CLI_DOC_ARG")
fi
.bin/clidoc "${args[@]}" cli-docs
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: cli-docs
path: cli-docs
if-no-files-found: error
retention-days: 1
publish:
name: Publish CLI docs
if: ${{ github.ref_name == 'master' || github.ref_type == 'tag' }}
needs: build
runs-on: ubuntu-latest
permissions: {}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: ory/docs
ref: ${{ inputs.docs-branch }}
path: docs
fetch-depth: 0
persist-credentials: false
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
with:
name: cli-docs
path: cli-docs
- name: Validate generated CLI docs
env:
OUTPUT_DIR: ${{ inputs.output-dir }}
run: |
set -euo pipefail
if [[ ! "$OUTPUT_DIR" =~ ^[A-Za-z0-9._/-]+$ ]] ||
[[ "$OUTPUT_DIR" == /* ]] || [[ "/$OUTPUT_DIR/" == */../* ]]; then
echo "output-dir must be a relative path without parent traversal"
exit 1
fi
if find cli-docs -type l | grep -q .; then
echo "generated documentation contains symlinks"
exit 1
fi
if find cli-docs -type f ! -name '*.md' | grep -q .; then
echo "generated documentation contains non-Markdown files"
exit 1
fi
if [[ -z "$(find cli-docs -type f -name '*.md' -print -quit)" ]]; then
echo "generated documentation is empty"
exit 1
fi
rm -rf "docs/$OUTPUT_DIR"
mkdir -p "docs/$OUTPUT_DIR"
cp -R cli-docs/. "docs/$OUTPUT_DIR/"
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: "24"
- uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4
with:
version: 10.34.5
- name: Format generated CLI docs
env:
OUTPUT_DIR: ${{ inputs.output-dir }}
working-directory: docs
run: pnpm dlx prettier@3.8.2 --write "$OUTPUT_DIR"
- name: Push docs
working-directory: docs
env:
DOCS_BRANCH: ${{ inputs.docs-branch }}
ORY_BOT_PAT: ${{ secrets.token }}
run: |
set -euo pipefail
if [[ -z "$(git status --porcelain)" ]]; then
echo "Nothing to commit"
exit 0
fi
git config --local user.email "60093411+ory-bot@users.noreply.github.com"
git config --local user.name "ory-bot"
git add -A
git stash --include-untracked
git pull --rebase origin "$DOCS_BRANCH"
git stash pop
git add -A
git commit -m "autogen(docs): generate cli docs"
git push "https://ory-bot:${ORY_BOT_PAT}@github.com/ory/docs.git" "HEAD:$DOCS_BRANCH"