Skip to content

Commit bd3ebd9

Browse files
authored
feat: add warning for dev mode in ci (#7046)
Signed-off-by: Yaroslav Pershin <62902094+iapershin@users.noreply.github.com>
1 parent d623d76 commit bd3ebd9

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎cmd/werf/common/common.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/werf/werf/v2/pkg/storage"
3232
"github.com/werf/werf/v2/pkg/true_git"
3333
"github.com/werf/werf/v2/pkg/werf"
34+
"github.com/werf/werf/v2/pkg/werf/global_warnings"
3435
)
3536

3637
const (
@@ -1320,6 +1321,7 @@ func OpenGitRepo(ctx context.Context, cmdData *CmdData, workingDir, gitWorkTree
13201321
}
13211322

13221323
func GetGiterminismManager(ctx context.Context, cmdData *CmdData) (*giterminism_manager.Manager, error) {
1324+
printGlobalWarningIfDevInCI(ctx, cmdData)
13231325
manager := new(giterminism_manager.Manager)
13241326
if err := logboek.Context(ctx).Info().LogProcess("Initialize giterminism manager").
13251327
DoError(func() error {
@@ -1390,6 +1392,19 @@ func GetGitWorkTree(ctx context.Context, cmdData *CmdData, workingDir string) (s
13901392
return "", &GitWorktreeNotFoundError{}
13911393
}
13921394

1395+
func printGlobalWarningIfDevInCI(ctx context.Context, cmdData *CmdData) {
1396+
const (
1397+
devModeInCIWarning = `The development mode is enabled in CI environment by providing --dev flag or WERF_DEV env variable.
1398+
This mode is intended for local development only and relies on the Git worktree state, including tracked and untracked files, while ignoring changes based on .gitignore and --dev-ignore rules.
1399+
Using development in CI may lead to non-reproducible builds and unexpected results.`
1400+
)
1401+
if cmdData.Dev != nil && *cmdData.Dev {
1402+
if werf.IsRunningInCI() {
1403+
global_warnings.GlobalWarningLn(ctx, devModeInCIWarning)
1404+
}
1405+
}
1406+
}
1407+
13931408
func LookupGitWorkTree(ctx context.Context, workingDir string) (string, error) {
13941409
if found, workTree, err := true_git.UpwardLookupAndVerifyWorkTree(ctx, workingDir); err != nil {
13951410
return "", err

‎integration/suites/build/stapel_image/imports/imports_test.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func werfRunOutput(ctx context.Context, dir string, extraArgs ...string) string
2323
return string(output)
2424
}
2525

26-
func werfRunOutputWithSpecificImage(ctx context.Context, dir string, image string, extraArgs ...string) string {
26+
func werfRunOutputWithSpecificImage(ctx context.Context, dir, image string, extraArgs ...string) string {
2727
output, _ := utils.RunCommandWithOptions(ctx, dir, SuiteData.WerfBinPath, append([]string{"run", image, "--"}, extraArgs...), utils.RunCommandOptions{ShouldSucceed: true})
2828
return string(output)
2929
}
@@ -147,7 +147,6 @@ var _ = Describe("Stapel imports", func() {
147147
output := werfRunOutputWithSpecificImage(ctx, SuiteData.GetProjectWorktree(SuiteData.ProjectName), fmt.Sprintf("test-import-%d", i), "ls", "/etc/test/busybox")
148148
Expect(output).To(ContainSubstring(`/etc/test/busybox`))
149149
}
150-
151150
})
152151
})
153152

‎pkg/werf/main.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"path/filepath"
88
"runtime"
99

10+
"github.com/hofstadter-io/cinful"
11+
1012
"github.com/werf/3p-helm/pkg/chart/loader"
1113
"github.com/werf/common-go/pkg/locker"
1214
"github.com/werf/common-go/pkg/secrets_manager"
@@ -154,3 +156,10 @@ func Init(tmpDirOption, homeDirOption string) error {
154156

155157
return nil
156158
}
159+
160+
func IsRunningInCI() bool {
161+
if ciInfo := cinful.Info(); ciInfo != nil {
162+
return true
163+
}
164+
return false
165+
}

0 commit comments

Comments
 (0)