xorpaul / g10k

my r10k fork in Go
Apache License 2.0
125 stars 50 forks source link

Transformed environments are removed on each run (v 0.8.5) #154

Closed mdrobnak closed 4 years ago

mdrobnak commented 4 years ago

We have an issue where if you have an environment with an invalid character in it (like -), it is removed on every run. My debugging of the code has come down to the allEnvironments map is populated with the un-transformed name, and thus does not match when going through the purge routine.

I'm not sure if this is the right way to fix, but this seems to solve the issue for me:

$ git diff
diff --git a/puppetfile.go b/puppetfile.go
index 8b0cdae..b438e32 100644
--- a/puppetfile.go
+++ b/puppetfile.go
@@ -78,13 +78,17 @@ func resolvePuppetEnvironment(tags bool, outputNameTag string) {
                                                Warnf("Ignoring branch " + branch + ", because it contains invalid characters")
                                                continue
                                        }
+                                       renamedBranch := branch
+                                        if sa.AutoCorrectEnvironmentNames == "correct" || sa.AutoCorrectEnvironmentNames == "correct_and_warn" {
+                                                                renamedBranch = reInvalidCharacters.ReplaceAllString(branch, "_")
+                                        }
                                        // XXX: maybe make this user configurable (either with dedicated file or as YAML array in g10k config)
                                        if strings.Contains(branch, ";") || strings.Contains(branch, "&") || strings.Contains(branch, "|") || strings.HasPrefix(branch, "tmp/") && strings.HasSuffix(branch, "/head") {
                                                Debugf("Skipping branch " + branch + " of source " + source + ", because of invalid character(s) inside the branch name")
                                                continue
                                        }
                                        mutex.Lock()
-                                       allEnvironments[prefix+branch] = true
+                                       allEnvironments[prefix+renamedBranch] = true
                                        mutex.Unlock()
                                        if len(branchParam) > 0 {
                                                if branch == branchParam {

I'm not sure how long this has been the case - I attempted to upgrade from 0.6.0 to fix another issue.

Thanks for looking into this.

xorpaul commented 4 years ago

Sorry, I've missed the notification of this issue.

The fix is even easier: https://github.com/xorpaul/g10k/commit/61333cad249d55832f8e2e72b90ab9cc5744ed4e

Please test https://github.com/xorpaul/g10k/releases/tag/v0.8.6