Skip to content

Commit

Permalink
feat: Changing "service" code/file references to "project" (#9)
Browse files Browse the repository at this point in the history
This includes changing the default manifest file from service.yaml to stencil.yaml
Also adding readme update for rtx
  • Loading branch information
deregtd committed Dec 21, 2023
1 parent 122f951 commit bbac52b
Show file tree
Hide file tree
Showing 21 changed files with 147 additions and 149 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/rgst-io/stencil)


A modern repository templating engine

**Note**: This has been forked from [getoutreach/stencil](https://github.com/getoutreach/stencil) and is currently
Expand All @@ -15,8 +14,7 @@ under construction.
**Note**: If you opt to not use `rtx`, please install all dependencies
from `.tool-versions` manually.

- [rtx](https://github.com/jdx/rtx)

- [rtx](https://github.com/jdx/rtx?tab=readme-ov-file#quickstart) - Ensure that you add the appropriate activations to your shell rc/profiles (details in the rtx README)

Install the dependencies:

Expand Down
22 changes: 11 additions & 11 deletions cmd/stencil/configure_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func NewConfigureModuleCmd() *cli.Command {
},
},
Action: func(c *cli.Context) error {
// Call readAndMergeServiceYaml to update the service yaml to add or remove the native-extension fields.
if err := readAndMergeServiceYaml("service.yaml", c.Bool("remove-native-extension"), "foo"); err != nil {
// Call readAndMergeStencilYaml to update the stencil.yaml to add or remove the native-extension fields.
if err := readAndMergeStencilYaml("stencil.yaml", c.Bool("remove-native-extension"), "foo"); err != nil {
if err.Error() == "no action" {
return nil
}
Expand All @@ -48,17 +48,17 @@ func NewConfigureModuleCmd() *cli.Command {
}
}

// readAndMergeServiceYaml takes a path and a bool and updates the service.yaml to create/remove fields
// readAndMergeStencilYaml takes a path and a bool and updates the stencil.yaml to create/remove fields
// associated with native-extensions.
func readAndMergeServiceYaml(path string, removeNativeExtension bool, input string) error {
func readAndMergeStencilYaml(path string, removeNativeExtension bool, input string) error {
log := logrus.New()
if path == "" {
path = "service.yaml"
path = "stencil.yaml"
}
var tm = &configuration.ServiceManifest{}
var tm = &configuration.Manifest{}

if _, err := os.Stat(path); err != nil {
return errors.Wrap(err, "service.yaml must exist")
return errors.Wrap(err, path+" must exist")
}

b, err := os.ReadFile(path)
Expand All @@ -76,7 +76,7 @@ func readAndMergeServiceYaml(path string, removeNativeExtension bool, input stri

if !removeNativeExtension {
// Note that for any additions to the configure command this line may need to be updated/removed.
// This section avoids removing any comments in the service.yaml file by overwriting it if there's no action to be taken.
// This section avoids removing any comments in the stencil.yaml file by overwriting it if there's no action to be taken.
if tm.Arguments["plugin"] == true && releaseOpts["force"] == true {
log.Info("The module is already a native extension, no action taken.")
return errors.New("no action")
Expand All @@ -85,7 +85,7 @@ func readAndMergeServiceYaml(path string, removeNativeExtension bool, input stri
releaseOpts["force"] = true
} else {
// Note that for any additions to the configure command this line may need to be updated/removed.
// This section avoids removing any comments in the service.yaml file by overwriting it if there's no action to be taken.
// This section avoids removing any comments in the stencil.yaml file by overwriting it if there's no action to be taken.
_, ok := tm.Arguments["plugin"]
if !ok {
log.Info("The module is already not a native extension, no action taken.")
Expand All @@ -97,10 +97,10 @@ func readAndMergeServiceYaml(path string, removeNativeExtension bool, input stri

if input != "" {
reader := bufio.NewReader(os.Stdin)
log.Info("This will remove any comments in your service.yaml, are you sure you want to proceed? y/N")
log.Info("This will remove any comments in your stencil.yaml, are you sure you want to proceed? y/N")
text, err := reader.ReadString('\n')
if err != nil {
return errors.Wrap(err, "failed to get user input for overwriting service.yaml")
return errors.Wrap(err, "failed to get user input for overwriting stencil.yaml")
}
if strings.TrimSpace(text) != "y" {
log.Info("No action taken")
Expand Down
36 changes: 18 additions & 18 deletions cmd/stencil/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ func TestConfigureModule(t *testing.T) {
tt := []struct {
Name string
RemoveNativeExtensionFlag bool
Given configuration.ServiceManifest
Expected configuration.ServiceManifest
Given configuration.Manifest
Expected configuration.Manifest
ShouldError bool
}{
{
Name: "EnsureServiceNoChangeWithoutFlag",
Name: "EnsureProjectNoChangeWithoutFlag",
RemoveNativeExtensionFlag: true,
Given: configuration.ServiceManifest{
Given: configuration.Manifest{
Name: "test",
Modules: []*configuration.TemplateRepository{
{
Expand All @@ -36,7 +36,7 @@ func TestConfigureModule(t *testing.T) {
"reportingTeam": "test_name",
},
},
Expected: configuration.ServiceManifest{
Expected: configuration.Manifest{
Name: "test",
Modules: []*configuration.TemplateRepository{
{
Expand All @@ -55,7 +55,7 @@ func TestConfigureModule(t *testing.T) {
}, {
Name: "EnsureNativeExtensionAddition",
RemoveNativeExtensionFlag: false,
Given: configuration.ServiceManifest{
Given: configuration.Manifest{
Name: "test",
Modules: []*configuration.TemplateRepository{
{
Expand All @@ -70,7 +70,7 @@ func TestConfigureModule(t *testing.T) {
"reportingTeam": "test_name",
},
},
Expected: configuration.ServiceManifest{
Expected: configuration.Manifest{
Name: "test",
Modules: []*configuration.TemplateRepository{
{
Expand All @@ -91,7 +91,7 @@ func TestConfigureModule(t *testing.T) {
}, {
Name: "EnsureNativeExtensionReversion",
RemoveNativeExtensionFlag: true,
Given: configuration.ServiceManifest{
Given: configuration.Manifest{
Name: "test",
Modules: []*configuration.TemplateRepository{
{
Expand All @@ -108,7 +108,7 @@ func TestConfigureModule(t *testing.T) {
"reportingTeam": "test_name",
},
},
Expected: configuration.ServiceManifest{
Expected: configuration.Manifest{
Name: "test",
Modules: []*configuration.TemplateRepository{
{
Expand All @@ -131,11 +131,11 @@ func TestConfigureModule(t *testing.T) {
test := test

t.Run(test.Name, func(t *testing.T) {
var tm = &configuration.ServiceManifest{}
var comp = &configuration.ServiceManifest{}
var tm = &configuration.Manifest{}
var comp = &configuration.Manifest{}

// Create temporary service.yaml with valid values
tempFile := filepath.Join(t.TempDir(), "service.yaml")
// Create temporary stencil.yaml with valid values
tempFile := filepath.Join(t.TempDir(), "stencil.yaml")
b, err := yaml.Marshal(test.Given)
assert.NilError(t, err, "failed to marshal given yaml")
assert.NilError(t, os.WriteFile(tempFile, b, 0o777), "failed to write file")
Expand All @@ -146,19 +146,19 @@ func TestConfigureModule(t *testing.T) {
err = yaml.Unmarshal(b, tm)
assert.NilError(t, err, "failed to unmarshal expected yaml")

// configure the service.yaml and compare to expected
err = readAndMergeServiceYaml(tempFile, test.RemoveNativeExtensionFlag, "")
// configure the stencil.yaml and compare to expected
err = readAndMergeStencilYaml(tempFile, test.RemoveNativeExtensionFlag, "")
if test.ShouldError == true {
assert.Error(t, err, "no action")
} else {
assert.NilError(t, err, "failed to read and configure service.yaml")
assert.NilError(t, err, "failed to read and configure stencil.yaml")
}

b, err = os.ReadFile(tempFile)
assert.NilError(t, err, "failed to read service.yaml")
assert.NilError(t, err, "failed to read stencil.yaml")

err = yaml.Unmarshal(b, comp)
assert.NilError(t, err, "failed to unmarshal service.yaml")
assert.NilError(t, err, "failed to unmarshal stencil.yaml")

assert.DeepEqual(t, tm, comp)
})
Expand Down
4 changes: 2 additions & 2 deletions cmd/stencil/create_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewCreateModule() *cli.Command {
},
},
Action: func(c *cli.Context) error {
var manifestFileName = "service.yaml"
var manifestFileName = "stencil.yaml"

// ensure we have a name
if c.NArg() != 1 {
Expand Down Expand Up @@ -78,7 +78,7 @@ func NewCreateModule() *cli.Command {
"enablePrereleases": true,
}

tm := &configuration.ServiceManifest{
tm := &configuration.Manifest{
Name: path.Base(c.Args().Get(0)),
Modules: []*configuration.TemplateRepository{{
Name: "github.com/rgst-io/stencil-template-base",
Expand Down
8 changes: 4 additions & 4 deletions cmd/stencil/stencil.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {
app := cli.App{
Version: version.Version,
Name: "stencil",
Description: "a smart templating engine for service development",
Description: "a smart templating engine for project development",
Action: func(c *cli.Context) error {
log.Infof("stencil %s", c.App.Version)

Expand All @@ -49,12 +49,12 @@ func main() {
log.Debug("Debug logging enabled")
}

serviceManifest, err := configuration.NewDefaultServiceManifest()
manifest, err := configuration.NewDefaultManifest()
if err != nil {
return errors.Wrap(err, "failed to parse service.yaml")
return errors.Wrap(err, "failed to parse stencil.yaml")
}

cmd := stencil.NewCommand(log, serviceManifest, c.Bool("dry-run"),
cmd := stencil.NewCommand(log, manifest, c.Bool("dry-run"),
c.Bool("frozen-lockfile"), c.Bool("allow-major-version-upgrades"))
return errors.Wrap(cmd.Run(ctx), "run codegen")
},
Expand Down
20 changes: 10 additions & 10 deletions internal/cmd/stencil/stencil.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ type Command struct {
// lock is the current stencil lockfile at command creation time
lock *stencil.Lockfile

// manifest is the service manifest that is being used
// manifest is the project manifest that is being used
// for this template render
manifest *configuration.ServiceManifest
manifest *configuration.Manifest

// log is the logger used for logging output
log logrus.FieldLogger
Expand All @@ -58,7 +58,7 @@ type Command struct {
}

// NewCommand creates a new stencil command
func NewCommand(log logrus.FieldLogger, s *configuration.ServiceManifest,
func NewCommand(log logrus.FieldLogger, s *configuration.Manifest,
dryRun, frozen, allowMajorVersionUpgrades bool) *Command {
l, err := stencil.LoadLockfile("")
if err != nil && !errors.Is(err, os.ErrNotExist) {
Expand Down Expand Up @@ -92,10 +92,10 @@ func (c *Command) Run(ctx context.Context) error {
}

c.log.Info("Fetching dependencies")
mods, err := modules.GetModulesForService(ctx, &modules.ModuleResolveOptions{
ServiceManifest: c.manifest,
Token: c.token,
Log: c.log,
mods, err := modules.GetModulesForProject(ctx, &modules.ModuleResolveOptions{
Manifest: c.manifest,
Token: c.token,
Log: c.log,
})
if err != nil {
return errors.Wrap(err, "failed to process modules list")
Expand Down Expand Up @@ -138,7 +138,7 @@ func (c *Command) Run(ctx context.Context) error {

// useModulesFromLock uses the modules from the lockfile instead
// of the latest versions, or manually supplied versions in the
// service manifest.
// project manifest.
func (c *Command) useModulesFromLock() error {
if c.lock == nil {
return fmt.Errorf("frozen lockfile requires a lockfile to exist")
Expand All @@ -164,13 +164,13 @@ func (c *Command) useModulesFromLock() error {
if _, ok := lockfileModulesHM[m.Name]; !ok {
outOfSync = true
outOfSyncReasons = append(outOfSyncReasons,
fmt.Sprintf("module %s requested by service.yaml but is not in the lockfile", m.Name))
fmt.Sprintf("module %s requested by stencil.yaml but is not in the lockfile", m.Name))
}
}

if outOfSync {
c.log.WithField("reasons", outOfSyncReasons).Debug("lockfile out of sync reasons")
c.log.Error("Unable to use frozen lockfile, the lockfile is out of sync with the service.yaml")
c.log.Error("Unable to use frozen lockfile, the lockfile is out of sync with the stencil.yaml")
return fmt.Errorf("lockfile out of sync")
}

Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/stencil/stencil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func TestCommand_useModulesFromLock(t *testing.T) {
type fields struct {
lock *stencil.Lockfile
manifest *configuration.ServiceManifest
manifest *configuration.Manifest
dryRun bool
allowMajorVersionUpgrades bool
}
Expand All @@ -33,7 +33,7 @@ func TestCommand_useModulesFromLock(t *testing.T) {
name: "should fail if lockfile is nil",
fields: fields{
lock: nil,
manifest: &configuration.ServiceManifest{
manifest: &configuration.Manifest{
Modules: []*configuration.TemplateRepository{
{
Name: "testing",
Expand All @@ -54,7 +54,7 @@ func TestCommand_useModulesFromLock(t *testing.T) {
},
},
},
manifest: &configuration.ServiceManifest{
manifest: &configuration.Manifest{
Modules: []*configuration.TemplateRepository{
{
Name: "testing",
Expand All @@ -81,7 +81,7 @@ func TestCommand_useModulesFromLock(t *testing.T) {
},
},
},
manifest: &configuration.ServiceManifest{
manifest: &configuration.Manifest{
Modules: []*configuration.TemplateRepository{},
},
},
Expand All @@ -99,7 +99,7 @@ func TestCommand_useModulesFromLock(t *testing.T) {
lock: &stencil.Lockfile{
Modules: []*stencil.LockfileModuleEntry{},
},
manifest: &configuration.ServiceManifest{
manifest: &configuration.Manifest{
Modules: []*configuration.TemplateRepository{
{
Name: "testing",
Expand All @@ -120,7 +120,7 @@ func TestCommand_useModulesFromLock(t *testing.T) {
},
},
},
manifest: &configuration.ServiceManifest{
manifest: &configuration.Manifest{
Modules: []*configuration.TemplateRepository{
{
Name: "testing",
Expand Down
8 changes: 4 additions & 4 deletions internal/codegen/stencil.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

// NewStencil creates a new, fully initialized Stencil renderer function
func NewStencil(m *configuration.ServiceManifest, mods []*modules.Module, log logrus.FieldLogger) *Stencil {
func NewStencil(m *configuration.Manifest, mods []*modules.Module, log logrus.FieldLogger) *Stencil {
return &Stencil{
log: log,
m: m,
Expand All @@ -40,7 +40,7 @@ func NewStencil(m *configuration.ServiceManifest, mods []*modules.Module, log lo
// stencil templates
type Stencil struct {
log logrus.FieldLogger
m *configuration.ServiceManifest
m *configuration.Manifest

ext *extensions.Host
extCaller *extensions.ExtensionCaller
Expand Down Expand Up @@ -182,7 +182,7 @@ func (s *Stencil) sortModuleHooks() {
}
}

// Render renders all templates using the ServiceManifest that was
// Render renders all templates using the Manifest that was
// provided to stencil at creation time, returned is the templates
// that were produced and their associated files.
func (s *Stencil) Render(ctx context.Context, log logrus.FieldLogger) ([]*Template, error) {
Expand Down Expand Up @@ -238,7 +238,7 @@ func (s *Stencil) Render(ctx context.Context, log logrus.FieldLogger) ([]*Templa
}

// PostRun runs all post run commands specified in the modules that
// this service depends on
// this project depends on
func (s *Stencil) PostRun(ctx context.Context, log logrus.FieldLogger) error {
log.Info("Running post-run command(s)")
for _, m := range s.modules {
Expand Down
Loading

0 comments on commit bbac52b

Please sign in to comment.