@@ -45,6 +45,7 @@ func (g gitRemote) Push(repo *git.Repository, o *git.PushOptions) error {
4545
4646// GitopsDeployer is a deployer that deploys projects to a GitOps repository.
4747type GitopsDeployer struct {
48+ dryrun bool
4849 fs billy.Filesystem
4950 repo * git.Repository
5051 kcl KCLRunner
@@ -108,21 +109,29 @@ func (g *GitopsDeployer) Deploy() error {
108109 }
109110 }
110111
111- changes , err := g .hasChanges ()
112- if err != nil {
113- return fmt .Errorf ("could not check if worktree has changes: %w" , err )
114- } else if ! changes {
115- return ErrNoChanges
116- }
112+ if ! g .dryrun {
113+ changes , err := g .hasChanges ()
114+ if err != nil {
115+ return fmt .Errorf ("could not check if worktree has changes: %w" , err )
116+ } else if ! changes {
117+ return ErrNoChanges
118+ }
117119
118- g .logger .Info ("Committing changes" , "path" , bundlePath )
119- if err := g .commit (); err != nil {
120- return fmt .Errorf ("could not commit changes: %w" , err )
121- }
120+ g .logger .Info ("Committing changes" , "path" , bundlePath )
121+ if err := g .commit (); err != nil {
122+ return fmt .Errorf ("could not commit changes: %w" , err )
123+ }
122124
123- g .logger .Info ("Pushing changes" )
124- if err := g .push (); err != nil {
125- return fmt .Errorf ("could not push changes: %w" , err )
125+ g .logger .Info ("Pushing changes" )
126+ if err := g .push (); err != nil {
127+ return fmt .Errorf ("could not push changes: %w" , err )
128+ }
129+ } else {
130+ g .logger .Info ("Dry-run: not committing or pushing changes" )
131+ g .logger .Info ("Dumping manifests" )
132+ for _ , r := range result {
133+ fmt .Print (r .Manifests )
134+ }
126135 }
127136
128137 return nil
@@ -245,12 +254,14 @@ func NewGitopsDeployer(
245254 project * project.Project ,
246255 store * secrets.SecretStore ,
247256 logger * slog.Logger ,
257+ dryrun bool ,
248258) GitopsDeployer {
249259 if logger == nil {
250260 logger = slog .New (slog .NewTextHandler (io .Discard , nil ))
251261 }
252262
253263 return GitopsDeployer {
264+ dryrun : dryrun ,
254265 fs : memfs .New (),
255266 kcl : NewKCLRunner (logger ),
256267 logger : logger ,
0 commit comments