xorpaul/g10k

Transformed environments are removed on each run (v 0.8.5)

mdrobnak opened this issue · 1 comments

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.

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

The fix is even easier: 61333ca

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