Skip to content

Commit a51d659

Browse files
authored
Merge branch 'main' into list/DEV-3143-custom-columns
2 parents 566a9a1 + 1895246 commit a51d659

File tree

94 files changed

+1468
-536
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1468
-536
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@
3939
**/cache.*.txt
4040

4141
# Ignore components vendored during tests
42-
tests/fixtures/scenarios/vendor/components/**
4342
examples/demo-vendoring/components/**
43+
tests/fixtures/scenarios/vendor-globs/components/**
44+
tests/fixtures/scenarios/vendor/components/**
4445

4546
# Coverage files
4647
coverage.out
47-
coverage.html
48+
coverage.html

cmd/cmd_utils.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"time"
1111

12+
log "github.com/charmbracelet/log"
1213
"github.com/samber/lo"
1314
"github.com/spf13/cobra"
1415

@@ -19,8 +20,12 @@ import (
1920
"github.com/cloudposse/atmos/pkg/ui/theme"
2021
u "github.com/cloudposse/atmos/pkg/utils"
2122
"github.com/cloudposse/atmos/pkg/version"
23+
"github.com/go-git/go-git/v5"
2224
)
2325

26+
// Define a constant for the dot string that appears multiple times.
27+
const currentDirPath = "."
28+
2429
// ValidateConfig holds configuration options for Atmos validation.
2530
// CheckStack determines whether stack configuration validation should be performed.
2631
type ValidateConfig struct {
@@ -180,7 +185,7 @@ func processCommandAliases(
180185
}
181186

182187
commandToRun := fmt.Sprintf("%s %s %s", os.Args[0], aliasCmd, strings.Join(args, " "))
183-
err = e.ExecuteShell(atmosConfig, commandToRun, commandToRun, ".", nil, false)
188+
err = e.ExecuteShell(atmosConfig, commandToRun, commandToRun, currentDirPath, nil, false)
184189
if err != nil {
185190
u.LogErrorAndExit(err)
186191
}
@@ -400,7 +405,7 @@ func executeCustomCommand(
400405
// If the command to get the value for the ENV var is provided, execute it
401406
if valCommand != "" {
402407
valCommandName := fmt.Sprintf("env-var-%s-valcommand", key)
403-
res, err := e.ExecuteShellAndReturnOutput(atmosConfig, valCommand, valCommandName, ".", nil, false)
408+
res, err := e.ExecuteShellAndReturnOutput(atmosConfig, valCommand, valCommandName, currentDirPath, nil, false)
404409
if err != nil {
405410
u.LogErrorAndExit(err)
406411
}
@@ -436,7 +441,7 @@ func executeCustomCommand(
436441

437442
// Execute the command step
438443
commandName := fmt.Sprintf("%s-step-%d", commandConfig.Name, i)
439-
err = e.ExecuteShell(atmosConfig, commandToRun, commandName, ".", envVarsList, false)
444+
err = e.ExecuteShell(atmosConfig, commandToRun, commandName, currentDirPath, envVarsList, false)
440445
if err != nil {
441446
u.LogErrorAndExit(err)
442447
}
@@ -523,6 +528,9 @@ func printMessageForMissingAtmosConfig(atmosConfig schema.AtmosConfiguration) {
523528
u.LogErrorAndExit(err)
524529
}
525530

531+
// Check if we're in a git repo. Warn if not.
532+
verifyInsideGitRepo()
533+
526534
if atmosConfig.Default {
527535
// If Atmos did not find an `atmos.yaml` config file and is using the default config
528536
u.PrintMessageInColor("atmos.yaml", c1)
@@ -665,6 +673,31 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin
665673
return info
666674
}
667675

676+
// isGitRepository checks if the current directory is within a git repository.
677+
func isGitRepository() bool {
678+
_, err := git.PlainOpenWithOptions(currentDirPath, &git.PlainOpenOptions{
679+
DetectDotGit: true,
680+
})
681+
if err != nil {
682+
if !errors.Is(err, git.ErrRepositoryNotExists) {
683+
log.Debug("git check failed", "error", err)
684+
}
685+
return false
686+
}
687+
688+
return true
689+
}
690+
691+
// verifyInsideGitRepo checks if we're in a git repo.
692+
func verifyInsideGitRepo() bool {
693+
// Check if we're in a git repo
694+
if !isGitRepository() {
695+
log.Warn("You're not inside a git repository. Atmos feels lonely outside - bring it home!\n")
696+
return false
697+
}
698+
return true
699+
}
700+
668701
func showErrorExampleFromMarkdown(cmd *cobra.Command, arg string) {
669702
commandPath := cmd.CommandPath()
670703
suggestions := []string{}

cmd/cmd_utils_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestVerifyInsideGitRepo(t *testing.T) {
11+
// Create a temporary directory for testing
12+
tmpDir, err := os.MkdirTemp("", "git-repo-verify-test-*")
13+
if err != nil {
14+
t.Fatalf("Failed to create temp directory: %v", err)
15+
}
16+
defer os.RemoveAll(tmpDir)
17+
18+
// Save current working directory
19+
currentDir, err := os.Getwd()
20+
if err != nil {
21+
t.Fatalf("Failed to get current directory: %v", err)
22+
}
23+
24+
// Test cases
25+
tests := []struct {
26+
name string
27+
setup func() error
28+
expected bool
29+
}{
30+
{
31+
name: "outside git repository",
32+
setup: func() error {
33+
return os.Chdir(tmpDir)
34+
},
35+
expected: false,
36+
},
37+
{
38+
name: "inside git repository",
39+
setup: func() error {
40+
if err := os.Chdir(currentDir); err != nil {
41+
return err
42+
}
43+
return nil
44+
},
45+
expected: true,
46+
},
47+
}
48+
49+
for _, tt := range tests {
50+
t.Run(tt.name, func(t *testing.T) {
51+
// Setup test environment
52+
if err := tt.setup(); err != nil {
53+
t.Fatalf("Failed to setup test: %v", err)
54+
}
55+
56+
// Run test
57+
result := verifyInsideGitRepo()
58+
59+
// Assert result
60+
assert.Equal(t, tt.expected, result)
61+
})
62+
}
63+
64+
// Restore original working directory
65+
if err := os.Chdir(currentDir); err != nil {
66+
t.Fatalf("Failed to restore working directory: %v", err)
67+
}
68+
}

cmd/terraform_generate_planfile.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
e "github.com/cloudposse/atmos/internal/exec"
7+
u "github.com/cloudposse/atmos/pkg/utils"
8+
)
9+
10+
// terraformGeneratePlanfileCmd generates planfile for a terraform component.
11+
var terraformGeneratePlanfileCmd = &cobra.Command{
12+
Use: "planfile",
13+
Short: "Generate a planfile for a Terraform component",
14+
Long: "This command generates a `planfile` for a specified Atmos Terraform component.",
15+
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
16+
ValidArgsFunction: ComponentsArgCompletion,
17+
Run: func(cmd *cobra.Command, args []string) {
18+
handleHelpRequest(cmd, args)
19+
// Check Atmos configuration
20+
checkAtmosConfig()
21+
22+
err := e.ExecuteTerraformGeneratePlanfileCmd(cmd, args)
23+
if err != nil {
24+
u.PrintErrorMarkdownAndExit("", err, "")
25+
}
26+
},
27+
}
28+
29+
func init() {
30+
terraformGeneratePlanfileCmd.DisableFlagParsing = false
31+
AddStackCompletion(terraformGeneratePlanfileCmd)
32+
33+
terraformGeneratePlanfileCmd.PersistentFlags().StringP("file", "f", "", "Planfile name")
34+
terraformGeneratePlanfileCmd.PersistentFlags().String("format", "json", "Output format (`json` or `yaml`, `json` is default)")
35+
36+
err := terraformGeneratePlanfileCmd.MarkPersistentFlagRequired("stack")
37+
if err != nil {
38+
u.PrintErrorMarkdownAndExit("", err, "")
39+
}
40+
41+
terraformGenerateCmd.AddCommand(terraformGeneratePlanfileCmd)
42+
}

demo/screengrabs/demo-stacks.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ atmos terraform deploy --help
3232
atmos terraform generate --help
3333
atmos terraform generate backend --help
3434
atmos terraform generate backends --help
35+
atmos terraform generate planfile --help
3536
atmos terraform generate varfile --help
3637
atmos terraform generate varfiles --help
3738
atmos terraform shell --help

examples/quick-start-advanced/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ARG GEODESIC_OS=debian
66
# https://atmos.tools/
77
# https://github.com/cloudposse/atmos
88
# https://github.com/cloudposse/atmos/releases
9-
ARG ATMOS_VERSION=1.171.0
9+
ARG ATMOS_VERSION=1.173.0
1010

1111
# Terraform: https://github.com/hashicorp/terraform/releases
1212
ARG TF_VERSION=1.5.7

go.mod

Lines changed: 21 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)