-
Notifications
You must be signed in to change notification settings - Fork 557
/
docs.go
146 lines (123 loc) · 3.63 KB
/
docs.go
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"context"
"golang.org/x/sync/errgroup"
"github.com/dagger/dagger/ci/internal/dagger"
"github.com/dagger/dagger/ci/util"
)
type Docs struct {
Dagger *Dagger // +private
}
const (
generatedSchemaPath = "docs/docs-graphql/schema.graphqls"
generatedCliZenPath = "docs/current_docs/reference/979596-cli.mdx"
)
const cliZenFrontmatter = `---
slug: /reference/979596/cli/
pagination_next: null
pagination_prev: null
---
# CLI Reference
`
// Build the docs website
func (d Docs) Site() *Directory {
return dag.
Docusaurus(
d.Dagger.Source,
DocusaurusOpts{Dir: "/src/docs", DisableCache: true},
).
Build()
}
// Build the docs server
func (d Docs) Server() *Container {
nginxConfig := dag.CurrentModule().Source().File("docs-nginx.conf")
return dag.
Container().
From("nginx").
WithoutEntrypoint().
WithFile("/etc/nginx/conf.d/default.conf", nginxConfig).
WithDefaultArgs([]string{"nginx", "-g", "daemon off;"}).
WithDirectory("/var/www", d.Site()).
WithExposedPort(8000)
}
// Lint documentation files
func (d Docs) Lint(ctx context.Context) error {
eg, ctx := errgroup.WithContext(ctx)
// Markdown
eg.Go(func() error {
_, err := dag.Container().
From("tmknom/markdownlint:0.31.1").
WithMountedDirectory("/src", d.Dagger.Source).
WithMountedFile("/src/.markdownlint.yaml", d.Dagger.Source.File(".markdownlint.yaml")).
WithWorkdir("/src").
WithExec([]string{
"-c",
".markdownlint.yaml",
"--",
"./docs",
"README.md",
}).
Sync(ctx)
return err
})
eg.Go(func() error {
return util.DiffDirectoryF(ctx, d.Dagger.Source, d.Generate, generatedSchemaPath, generatedCliZenPath)
})
eg.Go(func() error {
return util.DiffDirectoryF(ctx, d.Dagger.Source, func(ctx context.Context) (*dagger.Directory, error) {
return dag.Container().
From("ghcr.io/miniscruff/changie").
WithMountedDirectory("/src", d.Dagger.Source).
WithWorkdir("/src").
WithExec([]string{"merge"}).
Directory("/src"), nil
}, "CHANGELOG.md")
})
// Go is already linted by engine:lint
// Python is already linted by sdk:python:lint
// TypeScript is already linted at sdk:typescript:lint
return eg.Wait()
}
// Regenerate the API schema and CLI reference docs
func (d Docs) Generate(ctx context.Context) (*dagger.Directory, error) {
eg, ctx := errgroup.WithContext(ctx)
_ = ctx
var sdl *dagger.Directory
eg.Go(func() error {
sdl = d.GenerateSdl()
return nil
})
var cli *dagger.Directory
eg.Go(func() error {
cli = d.GenerateCli()
return nil
})
if err := eg.Wait(); err != nil {
return nil, err
}
return sdl.WithDirectory("/", cli), nil
}
// Regenerate the API schema
func (d Docs) GenerateSdl() *Directory {
introspectionJSON :=
util.GoBase(d.Dagger.Source).
WithExec([]string{"go", "run", "./cmd/introspect"}, dagger.ContainerWithExecOpts{
RedirectStdout: "introspection.json",
}).
File("introspection.json")
generated := dag.Container().
From("node:16-alpine").
WithExec([]string{"npm", "install", "-g", "graphql-json-to-sdl"}).
WithMountedFile("/src/schema.json", introspectionJSON).
WithExec([]string{"graphql-json-to-sdl", "/src/schema.json", "/src/schema.graphql"}).
File("/src/schema.graphql")
return dag.Directory().WithFile(generatedSchemaPath, generated)
}
// Regenerate the CLI reference docs
func (d Docs) GenerateCli() *Directory {
// Should we keep `--include-experimental`?
generated := util.GoBase(d.Dagger.Source).
WithExec([]string{"go", "run", "./cmd/dagger", "gen", "--frontmatter=" + cliZenFrontmatter, "--output=cli.mdx", "--include-experimental"}).
File("cli.mdx")
return dag.Directory().WithFile(generatedCliZenPath, generated)
}