11package main
22
33import (
4- "context"
5- "fmt"
6-
74 "github.com/openmeterio/openmeter/.dagger/internal/dagger"
85)
96
@@ -19,51 +16,6 @@ type Generate struct {
1916 Source * dagger.Directory
2017}
2118
22- // Generate OpenAPI from TypeSpec.
23- func (m * Generate ) Openapi () * dagger.File {
24- file := typespecBase (m .Source .Directory ("api/spec" )).
25- WithExec ([]string {"pnpm" , "compile" }).
26- File ("/work/output/openapi.OpenMeter.yaml" ).
27- WithName ("openapi.yaml" )
28-
29- // https://github.com/microsoft/typespec/issues/2154
30- file = dag .Container ().
31- From ("alpine" ).
32- WithFile ("/work/openapi.yaml" , file ).
33- WithWorkdir ("/work" ).
34- File ("/work/openapi.yaml" )
35-
36- return file
37- }
38-
39- // Generate OpenAPI from TypeSpec.
40- func (m * Generate ) Openapicloud () * dagger.File {
41- file := typespecBase (m .Source .Directory ("api/spec" )).
42- WithExec ([]string {"pnpm" , "compile" }).
43- File ("/work/output/openapi.OpenMeterCloud.yaml" ).
44- WithName ("openapi.cloud.yaml" )
45-
46- // https://github.com/microsoft/typespec/issues/2154
47- file = dag .Container ().
48- From ("alpine" ).
49- WithFile ("/work/openapi.cloud.yaml" , file ).
50- WithWorkdir ("/work" ).
51- File ("/work/openapi.cloud.yaml" )
52-
53- return file
54- }
55-
56- func typespecBase (source * dagger.Directory ) * dagger.Container {
57- return dag .Container ().
58- From (NODEJS_CONTAINER_IMAGE ).
59- WithEnvVariable ("CI" , "true" ).
60- WithExec ([]string {"npm" , "install" , "-g" , fmt .Sprintf ("corepack@v%s" , COREPACK_VERSION )}).
61- WithExec ([]string {"corepack" , "enable" }).
62- WithDirectory ("/work" , source ).
63- WithWorkdir ("/work" ).
64- WithExec ([]string {"pnpm" , "install" , "--frozen-lockfile" })
65- }
66-
6719// Generate the Python SDK.
6820func (m * Generate ) PythonSdk () * dagger.Directory {
6921 // We build our image as the official autorest Dockerfile is outdated
@@ -83,59 +35,3 @@ func (m *Generate) PythonSdk() *dagger.Directory {
8335 WithExec ([]string {"autorest" , "config.yaml" }).
8436 Directory ("/work/client/python" )
8537}
86-
87- // Generate the JavaScript SDK.
88- func (m * Generate ) JavascriptSdk () * dagger.Directory {
89- return dag .Container ().
90- From (NODEJS_CONTAINER_IMAGE ).
91- WithExec ([]string {"npm" , "install" , "-g" , fmt .Sprintf ("corepack@v%s" , COREPACK_VERSION )}).
92- WithExec ([]string {"corepack" , "enable" }).
93- WithDirectory ("/work" , m .Source .Directory ("api" )).
94- WithWorkdir ("/work/client/javascript" ).
95- WithExec ([]string {"pnpm" , "install" , "--frozen-lockfile" }).
96- WithExec ([]string {"pnpm" , "run" , "generate" }).
97- WithExec ([]string {"pnpm" , "build" }).
98- WithExec ([]string {"pnpm" , "test" }).
99- Directory ("/work/client/javascript" ).
100- WithoutDirectory ("node_modules" )
101- }
102-
103- func (m * Generate ) Server () * dagger.Directory {
104- openapi := m .Openapi ()
105- cloud := m .Openapicloud ()
106-
107- source := m .Source .
108- WithFile ("api/openapi.yaml" , openapi ).
109- WithFile ("api/openapi.cloud.yaml" , cloud )
110-
111- return goModule ().
112- WithSource (source ).
113- Exec ([]string {"go" , "generate" , "-x" , "./api" }).
114- Directory ("/work/src/api" )
115- }
116-
117- func (m * Generate ) Check (ctx context.Context ) error {
118- result := goModuleCross ("" ).
119- WithSource (m .Source ).
120- WithEnvVariable ("GOFLAGS" , "-tags=musl" ).
121- Exec ([]string {"go" , "generate" , "-x" , "./..." }).
122- Directory ("" )
123-
124- err := diff (ctx , m .Source , result )
125- if err != nil {
126- return fmt .Errorf ("go generate wasn't run: %w" , err )
127- }
128-
129- return nil
130- }
131-
132- func diff (ctx context.Context , d1 , d2 * dagger.Directory ) error {
133- _ , err := dag .Container (dagger.ContainerOpts {Platform : "" }).
134- From (alpineBaseImage ).
135- WithDirectory ("src" , d1 ).
136- WithDirectory ("res" , d2 ).
137- WithExec ([]string {"diff" , "-u" , "-r" , "-q" , "src" , "res" }).
138- Sync (ctx )
139-
140- return err
141- }
0 commit comments