-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tiltfile+cli: embed api stub files and add
tilt dump api-stubs
(#5574)
* tiltfile: import and go:embed api stubs * cli: add `tilt dump api-stubs` command * tiltfile: extract DumpApiStubs * cli: rename to `tilt dump api-docs` For consistency with `tilt dump cli-docs`. * scripts: `tilt dump api-docs` into docs repo on release * tiltfile: wildcard api directories Co-authored-by: Matt Landis <landism@users.noreply.github.com> * cli: dump api-docs prepends a header to each file Includes instructions for making modifications to each file. * scripts: pass version/date to tilt dump commands Co-authored-by: Matt Landis <landism@users.noreply.github.com>
- Loading branch information
1 parent
da81540
commit e9fd744
Showing
10 changed files
with
2,768 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package tiltfile | ||
|
||
import ( | ||
"bytes" | ||
"embed" | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/tilt-dev/tilt/pkg/model" | ||
) | ||
|
||
//go:embed api/*.py api/*/*.py | ||
var api embed.FS | ||
|
||
const autoGeneratedHeader = `### AUTO-GENERATED ### | ||
# This file was auto-generated by 'tilt dump api-docs' as part of a Tilt release. | ||
# To make changes, modify the following file in the Tilt repository: | ||
# internal/tiltfile/%s | ||
# Generated by Tilt version %s | ||
### AUTO-GENERATED ### | ||
` | ||
|
||
func ApiStubs() fs.FS { | ||
return api | ||
} | ||
|
||
func WalkApiStubs(fn fs.WalkDirFunc) error { | ||
return fs.WalkDir(ApiStubs(), "api", fn) | ||
} | ||
|
||
func DumpApiStubs(dir string, info model.TiltBuild, callback func(string, error)) error { | ||
return WalkApiStubs(func(path string, d fs.DirEntry, e error) error { | ||
if e != nil { | ||
return e | ||
} | ||
var err error | ||
dest := filepath.Join(dir, path) | ||
if d.IsDir() { | ||
err = os.MkdirAll(dest, 0755) | ||
} else { | ||
buf := bytes.NewBufferString(fmt.Sprintf(autoGeneratedHeader, path, info.HumanBuildStamp())) | ||
var bytes []byte | ||
bytes, err = api.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
buf.Write(bytes) | ||
err = os.WriteFile(dest, buf.Bytes(), 0644) | ||
} | ||
callback(path, err) | ||
return err | ||
}) | ||
} |
Oops, something went wrong.