Skip to content

Commit 37bef10

Browse files
authored
--dry_run flag (#115)
* --dry_run flag * more info on dry run * doc
1 parent 066b469 commit 37bef10

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ As a result of the setup above the `create_gitops_prs` tool will open up to 2 po
461461

462462
The GitOps pull request is only created (or new commits added) if the `gitops` target changes the state for the target deployment branch. The source pull request will remain open (and keep accumulation GitOps results) until the pull request is merged and source branch is deleted.
463463

464+
`--dry_run` parameter can be used to test the tool without creating any pull requests. The tool will print the list of the potential pull requests. It is recommended to run the tool in the dry run mode as a part of the CI test suite to verify that the tool is configured correctly.
465+
464466
<a name="multiple-release-branches-gitops-workflow"></a>
465467
## Multiple Release Branches GitOps Workflow
466468

gitops/prer/create_gitops_prs.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ var (
6868
gitopsKind SliceFlags
6969
gitopsRuleName SliceFlags
7070
gitopsRuleAttr SliceFlags
71+
dryRun = flag.Bool("dry_run", false, "Do not create PRs, just print what would be done")
7172
)
7273

7374
func init() {
@@ -236,9 +237,18 @@ func main() {
236237
close(targetsCh)
237238
wg.Wait()
238239

239-
workdir.Push(updatedGitopsBranches)
240+
if *dryRun {
241+
log.Println("dry-run: updated gitops branches: ", updatedGitopsBranches)
242+
log.Println("dry-run: skipping push")
243+
} else {
244+
workdir.Push(updatedGitopsBranches)
245+
}
240246

241247
for _, branch := range updatedGitopsBranches {
248+
if *dryRun {
249+
log.Println("dry-run: skipping PR creation: branch ", branch, "into ", *prInto)
250+
continue
251+
}
242252
err := gitServer.CreatePR(branch, *prInto, fmt.Sprintf("GitOps deployment %s", branch))
243253
if err != nil {
244254
log.Fatal("unable to create PR: ", err)

0 commit comments

Comments
 (0)