Skip to content

Commit b995d78

Browse files
added zed docs with github workflow
Signed-off-by: Kartikay <[email protected]>
1 parent 753fe21 commit b995d78

File tree

5 files changed

+136
-3
lines changed

5 files changed

+136
-3
lines changed

.github/workflows/docs.yaml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
name: "Sync Generated Docs"
3+
on: # yamllint disable-line rule:truthy
4+
push:
5+
branches:
6+
- "main"
7+
8+
env:
9+
DOCS_REPO: "authzed/docs"
10+
DOCS_BRANCH: "main"
11+
GENERATED_DOCS_DIR: "docs"
12+
TARGET_DOCS_DIR: "pages/zed"
13+
14+
permissions:
15+
contents: "write"
16+
pull-requests: "write"
17+
18+
jobs:
19+
generate-and-sync-docs:
20+
runs-on: "ubuntu-latest"
21+
steps:
22+
- name: "Checkout source repository"
23+
uses: "actions/checkout@v3"
24+
with:
25+
fetch-depth: 1
26+
27+
- name: "Set up Go"
28+
uses: "actions/setup-go@v4"
29+
with:
30+
go-version: 1.20
31+
32+
- name: "Generate documentation"
33+
run: |
34+
cd magefiles
35+
if ! mage GenerateDocs; then
36+
echo "Documentation generation failed"
37+
exit 1
38+
fi
39+
40+
- name: "Clone docs repository"
41+
run: |
42+
git clone --depth 1 --branch $DOCS_BRANCH https://github.com/$DOCS_REPO.git docs-repo || {
43+
echo "Failed to clone docs repository"
44+
exit 1
45+
}
46+
47+
- name: "Compare generated docs with target docs"
48+
id: "compare"
49+
run: |
50+
rsync -r --delete $GENERATED_DOCS_DIR/ docs-repo/$TARGET_DOCS_DIR
51+
cd docs-repo
52+
if git diff --exit-code; then
53+
echo "No changes detected in docs."
54+
echo "changes_detected=false" >> $GITHUB_ENV
55+
else
56+
echo "Changes detected in docs."
57+
echo "changes_detected=true" >> $GITHUB_ENV
58+
fi
59+
60+
- name: "Configure Git"
61+
if: "env.changes_detected == true"
62+
run: |
63+
cd docs-repo
64+
git config user.name "GitHub Actions"
65+
git config user.email "[email protected]"
66+
67+
- name: "Commit and push changes if any"
68+
if: "env.changes_detected == true"
69+
run: |
70+
cd docs-repo
71+
git add $TARGET_DOCS_DIR
72+
git commit -m "Update generated docs"
73+
git push origin $DOCS_BRANCH
74+
75+
- name: "Create a pull request"
76+
if: "env.changes_detected == true"
77+
uses: "peter-evans/create-pull-request@v5"
78+
with:
79+
token: "${{ secrets.GITHUB_TOKEN }}"
80+
commit-message: "Update generated docs"
81+
branch: "update-generated-docs"
82+
title: "Sync generated docs"
83+
body: |
84+
This PR updates the generated documentation files in `$TARGET_DOCS_DIR` with the latest version from the main repository.
85+
base: "$DOCS_BRANCH"

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require (
2020
github.com/hamba/avro/v2 v2.27.0
2121
github.com/jzelinskie/cobrautil/v2 v2.0.0-20240819150235-f7fe73942d0f
2222
github.com/jzelinskie/stringz v0.0.3
23+
github.com/magefile/mage v1.15.0
2324
github.com/mattn/go-isatty v0.0.20
2425
github.com/mitchellh/go-homedir v1.1.0
2526
github.com/muesli/termenv v0.15.2
@@ -95,6 +96,7 @@ require (
9596
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
9697
github.com/containerd/cgroups/v3 v3.0.1 // indirect
9798
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
99+
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
98100
github.com/creasty/defaults v1.8.0 // indirect
99101
github.com/dalzilio/rudd v1.1.1-0.20230806153452-9e08a6ea8170 // indirect
100102
github.com/danieljoos/wincred v1.2.1 // indirect
@@ -200,6 +202,7 @@ require (
200202
github.com/rivo/uniseg v0.4.7 // indirect
201203
github.com/rs/cors v1.11.1 // indirect
202204
github.com/rs/xid v1.6.0 // indirect
205+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
203206
github.com/sagikazarmark/locafero v0.4.0 // indirect
204207
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
205208
github.com/samber/slog-common v0.18.0 // indirect

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ github.com/containerd/continuity v0.4.3 h1:6HVkalIp+2u1ZLH1J/pYX2oBVXlJZvh1X1A7b
779779
github.com/containerd/continuity v0.4.3/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ=
780780
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
781781
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
782+
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
782783
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
783784
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
784785
github.com/creasty/defaults v1.8.0 h1:z27FJxCAa0JKt3utc0sCImAEb+spPucmKoOdLHvHYKk=
@@ -1156,6 +1157,8 @@ github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i
11561157
github.com/lyft/protoc-gen-star v0.6.0/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA=
11571158
github.com/lyft/protoc-gen-star v0.6.1/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA=
11581159
github.com/lyft/protoc-gen-star/v2 v2.0.1/go.mod h1:RcCdONR2ScXaYnQC5tUzxzlpA3WVYF7/opLeUgcQs/o=
1160+
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
1161+
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
11591162
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
11601163
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
11611164
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
@@ -1306,6 +1309,7 @@ github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
13061309
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
13071310
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
13081311
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
1312+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
13091313
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
13101314
github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w=
13111315
github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZKsJ8yyVxGRWYNEm9oFB8ieLgKFnamEyDmSA0BRk=

internal/cmd/cmd.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ func init() {
4242
log.Logger = l
4343
}
4444

45-
func Run() {
46-
zl := cobrazerolog.New(cobrazerolog.WithPreRunLevel(zerolog.DebugLevel))
47-
45+
// This function is utilised to generate docs for zed
46+
func InitialiseRootCmd(zl *cobrazerolog.Builder) *cobra.Command {
4847
rootCmd := &cobra.Command{
4948
Use: "zed",
5049
Short: "SpiceDB client, by AuthZed",
@@ -113,6 +112,14 @@ func Run() {
113112
schemaCmd := commands.RegisterSchemaCmd(rootCmd)
114113
registerAdditionalSchemaCmds(schemaCmd)
115114

115+
return rootCmd
116+
}
117+
118+
func Run() {
119+
zl := cobrazerolog.New(cobrazerolog.WithPreRunLevel(zerolog.DebugLevel))
120+
121+
rootCmd := InitialiseRootCmd(zl)
122+
116123
ctx, cancel := context.WithCancel(context.Background())
117124
defer cancel()
118125

magefiles/magefile.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//go:build mage
2+
// +build mage
3+
4+
package main
5+
6+
import (
7+
"os"
8+
9+
"github.com/authzed/zed/internal/cmd"
10+
"github.com/jzelinskie/cobrautil/v2/cobrazerolog"
11+
"github.com/magefile/mage/mg"
12+
"github.com/spf13/cobra/doc"
13+
)
14+
15+
type Gen mg.Namespace
16+
17+
// All Run all generators in parallel
18+
func (g Gen) All() error {
19+
mg.Deps(g.Docs)
20+
return nil
21+
}
22+
23+
// Generate markdown files for zed
24+
func (Gen) Docs() error {
25+
targetDir := "../docs"
26+
27+
err := os.MkdirAll("../docs", os.ModePerm)
28+
if err != nil {
29+
return err
30+
}
31+
32+
rootCmd := cmd.InitialiseRootCmd(cobrazerolog.New())
33+
return doc.GenMarkdownTree(rootCmd, targetDir)
34+
}

0 commit comments

Comments
 (0)