Skip to content

Commit

Permalink
chore: clean up pug path code
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed May 1, 2024
1 parent 7ad8289 commit 81c27c1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/app/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func cleanupArtefacts(workdir string, opts setupOptions) {
}
if d.IsDir() {
switch d.Name() {
case ".terraform", ".pug":
case ".terraform", internal.PugDirectory:
os.RemoveAll(path)
return fs.SkipDir
}
Expand Down
1 change: 1 addition & 0 deletions internal/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func New(workdir internal.Workdir, path string) *Module {
return mod
}

// FullPath returns the absolute path to the module.
func (m *Module) FullPath() string {
return filepath.Join(m.Workdir.String(), m.Path)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/pug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package internal

// PugDirectory is the name of the directory in which pug artefacts are
// persisted.
const PugDirectory = ".pug"
2 changes: 1 addition & 1 deletion internal/run/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (s *Service) createTask(run *Run, opts task.CreateOptions) (*task.Task, err
if err != nil {
return nil, err
}
opts.Env = []string{workspace.TerraformEnv(ws.Name)}
opts.Env = []string{ws.TerraformEnv()}

mod, err := s.modules.Get(ws.ModuleID())
if err != nil {
Expand Down
15 changes: 5 additions & 10 deletions internal/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"
"path/filepath"

"github.com/leg100/pug/internal"
"github.com/leg100/pug/internal/module"
"github.com/leg100/pug/internal/resource"
)
Expand Down Expand Up @@ -36,23 +37,17 @@ func (ws *Workspace) ModuleID() resource.ID {
}

func (ws *Workspace) TerraformEnv() string {
return TerraformEnv(ws.Name)
return fmt.Sprintf("TF_WORKSPACE=%s", ws.Name)
}

// PugDirectory returns the workspace's pug directory, relative to its module
// directory.
func (ws *Workspace) PugDirectory() string {
return PugDirectory(ws.Name)
return filepath.Join(internal.PugDirectory, ws.Name)
}

func (ws *Workspace) LogValue() slog.Value {
return slog.GroupValue(
slog.String("name", ws.Name),
)
}

func PugDirectory(name string) string {
return filepath.Join(".pug", name)
}

func TerraformEnv(name string) string {
return fmt.Sprintf("TF_WORKSPACE=%s", name)
}

0 comments on commit 81c27c1

Please sign in to comment.