Skip to content

Commit f670dd3

Browse files
authored
fix: fmt not respecting .tmskip file. (#1958)
## What this PR does / why we need it: Fixes the `terramate fmt` command not respecting the `.tmskip`. ## Which issue(s) this PR fixes: Fixes #1952 ## Special notes for your reviewer: ## Does this PR introduce a user-facing change? ``` yes, fixes a bug. ```
2 parents 5cb436c + 5b4928c commit f670dd3

File tree

17 files changed

+97
-36
lines changed

17 files changed

+97
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Given a version number `MAJOR.MINOR.PATCH`, we increment the:
2929
### Fixed
3030

3131
- Nested `map` blocks not rendered if the `value` block contain no attributes.
32+
- Fix `terramate fmt` not respecting the `.tmskip` file.
3233

3334
## v0.11.1
3435

config/config.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ import (
3131
"github.com/zclconf/go-cty/cty"
3232
)
3333

34-
const (
35-
// DefaultFilename is the name of the default Terramate configuration file.
36-
DefaultFilename = "terramate.tm.hcl"
37-
38-
// SkipFilename is the name of Terramate skip file.
39-
SkipFilename = ".tmskip"
40-
)
41-
4234
const (
4335
// ErrSchema indicates that the configuration has an invalid schema.
4436
ErrSchema errors.Kind = "config has an invalid schema"
@@ -456,7 +448,7 @@ func loadTree(parentTree *Tree, cfgdir string, rootcfg *hcl.Config) (_ *Tree, er
456448
}
457449

458450
for _, fname := range otherFiles {
459-
if fname == SkipFilename {
451+
if fname == terramate.SkipFilename {
460452
logger.Debug().Msg("skip file found: skipping whole subtree")
461453
return newSkippedTree(cfgdir), nil
462454
}

config/config_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/madlambda/spells/assert"
1212
"github.com/rs/zerolog"
13+
"github.com/terramate-io/terramate"
1314
"github.com/terramate-io/terramate/config"
1415
"github.com/terramate-io/terramate/errors"
1516
"github.com/terramate-io/terramate/project"
@@ -306,7 +307,7 @@ func TestConfigSkipdir(t *testing.T) {
306307
s.BuildTree([]string{
307308
"s:/stack",
308309
"s:/stack-2",
309-
"f:/stack/" + config.SkipFilename,
310+
"f:/stack/" + terramate.SkipFilename,
310311
"f:/stack/ignored.tm:not valid hcl but wont be parsed",
311312
"f:/stack/subdir/ignored.tm:not valid hcl but wont be parsed",
312313
})

constants.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2024 Terramate GmbH
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package terramate
5+
6+
const (
7+
// DefaultFilename is the name of the default Terramate configuration file.
8+
DefaultFilename = "terramate.tm.hcl"
9+
10+
// SkipFilename is the name of Terramate skip file.
11+
SkipFilename = ".tmskip"
12+
)

e2etests/core/fmt_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ name = "name"
4949
sprintf("f:stacks/globals.tm:%s", unformattedHCL),
5050
sprintf("f:stacks/stack-1/globals.tm:%s", unformattedHCL),
5151
sprintf("f:stacks/stack-2/globals.tm:%s", unformattedHCL),
52+
53+
// dir below must always be ignored
54+
`f:skipped-dir/.tmskip:`,
55+
sprintf("f:skipped-dir/globals.tm:%s", unformattedHCL),
5256
})
5357
}
5458

e2etests/core/generate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"path/filepath"
99
"testing"
1010

11-
"github.com/terramate-io/terramate/config"
11+
"github.com/terramate-io/terramate"
1212
"github.com/terramate-io/terramate/generate"
1313
"github.com/terramate-io/terramate/modvendor"
1414
"github.com/terramate-io/terramate/project"
@@ -568,7 +568,7 @@ func TestE2EGenerateRespectsWorkingDirectory(t *testing.T) {
568568
})
569569

570570
s.RootEntry().CreateFile(
571-
config.DefaultFilename,
571+
terramate.DefaultFilename,
572572
configStr,
573573
)
574574

generate/generate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
"github.com/rs/zerolog"
1919
"github.com/rs/zerolog/log"
20+
"github.com/terramate-io/terramate"
2021
"github.com/terramate-io/terramate/config"
2122
"github.com/terramate-io/terramate/errors"
2223
"github.com/terramate-io/terramate/event"
@@ -540,7 +541,7 @@ processSubdirs:
540541

541542
// We need to skip all other files/dirs if we find a config.SkipFilename
542543
for _, entry := range entries {
543-
if entry.Name() == config.SkipFilename {
544+
if entry.Name() == terramate.SkipFilename {
544545
continue processSubdirs
545546
}
546547
}

generate/generate_hcl_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313

1414
"github.com/madlambda/spells/assert"
15+
"github.com/terramate-io/terramate"
1516
"github.com/terramate-io/terramate/config"
1617
"github.com/terramate-io/terramate/errors"
1718
"github.com/terramate-io/terramate/generate"
@@ -824,7 +825,7 @@ func TestGenerateHCL(t *testing.T) {
824825
path: "/stacks/stack-1",
825826
add: Doc(
826827
Import(
827-
Str("source", fmt.Sprintf("/common/%s", config.DefaultFilename)),
828+
Str("source", fmt.Sprintf("/common/%s", terramate.DefaultFilename)),
828829
),
829830
Globals(
830831
Str("local_a", "stack-1-local"),
@@ -842,7 +843,7 @@ func TestGenerateHCL(t *testing.T) {
842843
path: "/stacks/stack-2",
843844
add: Doc(
844845
Import(
845-
Str("source", fmt.Sprintf("/common/%s", config.DefaultFilename)),
846+
Str("source", fmt.Sprintf("/common/%s", terramate.DefaultFilename)),
846847
),
847848
Globals(
848849
Str("local_a", "stack-2-local"),
@@ -1122,7 +1123,7 @@ func TestGenerateHCL(t *testing.T) {
11221123
{
11231124
path: "/stacks/stack",
11241125
add: Import(
1125-
Str("source", fmt.Sprintf("/other/%s", config.DefaultFilename)),
1126+
Str("source", fmt.Sprintf("/other/%s", terramate.DefaultFilename)),
11261127
),
11271128
},
11281129
},
@@ -2102,7 +2103,7 @@ func TestWontOverwriteManuallyDefinedTerraform(t *testing.T) {
21022103

21032104
s := sandbox.NoGit(t, true)
21042105
s.BuildTree([]string{
2105-
fmt.Sprintf("f:%s:%s", config.DefaultFilename, generateHCLConfig.String()),
2106+
fmt.Sprintf("f:%s:%s", terramate.DefaultFilename, generateHCLConfig.String()),
21062107
"s:stack",
21072108
fmt.Sprintf("f:stack/%s:%s", genFilename, manualTfCode),
21082109
})

generate/generate_list_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"testing"
1111

1212
"github.com/madlambda/spells/assert"
13-
"github.com/terramate-io/terramate/config"
13+
"github.com/terramate-io/terramate"
1414
"github.com/terramate-io/terramate/generate"
1515
"github.com/terramate-io/terramate/generate/genhcl"
1616
. "github.com/terramate-io/terramate/test/hclwrite/hclutils"
@@ -131,7 +131,7 @@ func TestGeneratedFilesListing(t *testing.T) {
131131
layout: []string{
132132
genfile("genfiles/1.tf"),
133133
genfile("genfiles/2.tf"),
134-
genfile("genfiles/" + config.SkipFilename),
134+
genfile("genfiles/" + terramate.SkipFilename),
135135
genfile("genfiles/subdir/1.tf"),
136136
genfile("genfiles2/1.tf"),
137137
},
@@ -145,7 +145,7 @@ func TestGeneratedFilesListing(t *testing.T) {
145145
layout: []string{
146146
"s:stack",
147147
genfile("stack/1.tf"),
148-
genfile("stack/dir/" + config.SkipFilename),
148+
genfile("stack/dir/" + terramate.SkipFilename),
149149
genfile("stack/dir/1.tf"),
150150
},
151151
want: []string{

generate/generate_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
"github.com/madlambda/spells/assert"
1616
"github.com/rs/zerolog"
17-
"github.com/terramate-io/terramate/config"
17+
"github.com/terramate-io/terramate"
1818
"github.com/terramate-io/terramate/errors"
1919
"github.com/terramate-io/terramate/generate"
2020
"github.com/terramate-io/terramate/generate/genhcl"
@@ -61,8 +61,8 @@ func TestGenerateIgnore(t *testing.T) {
6161
layout: []string{
6262
"s:stacks/stack",
6363
"s:stacks/stack-2",
64-
"f:stacks/stack-2/" + config.SkipFilename,
65-
"f:not-a-stack/" + config.SkipFilename,
64+
"f:stacks/stack-2/" + terramate.SkipFilename,
65+
"f:not-a-stack/" + terramate.SkipFilename,
6666
},
6767
configs: []hclconfig{
6868
{
@@ -1159,7 +1159,7 @@ func testCodeGeneration(t *testing.T, tcases []testcase) {
11591159
path := filepath.Join(s.RootDir(), cfg.path)
11601160
filename := cfg.filename
11611161
if filename == "" {
1162-
filename = config.DefaultFilename
1162+
filename = terramate.DefaultFilename
11631163
}
11641164
configurationFiles[filepath.Join(path, filename)] = struct{}{}
11651165
test.AppendFile(t, path, filename, cfg.add.String())
@@ -1255,7 +1255,7 @@ func testCodeGeneration(t *testing.T, tcases []testcase) {
12551255
return nil
12561256
}
12571257

1258-
if d.Name() == config.DefaultFilename ||
1258+
if d.Name() == terramate.DefaultFilename ||
12591259
d.Name() == stackpkg.DefaultFilename ||
12601260
d.Name() == "root.config.tm" {
12611261
return nil

0 commit comments

Comments
 (0)