Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix same branch name different sources #222

Merged
merged 9 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: setup go environment 1.19.3
- name: setup go environment stable
uses: actions/setup-go@v3
with:
go-version: '1.19.3'
Expand Down
83 changes: 63 additions & 20 deletions g10k_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2153,14 +2153,14 @@ func TestPurgeStaleDeploymentOnly(t *testing.T) {

expectedLines := []string{
"DEBUG purgeUnmanagedContent(): Glob'ing with path /tmp/full/full_*",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: full_another",
"DEBUG purgeUnmanagedContent(): Not purging environment full_another",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: full_master",
"DEBUG purgeUnmanagedContent(): Not purging environment full_master",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: full_qa",
"DEBUG purgeUnmanagedContent(): Not purging environment full_qa",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: full_stale",
"Removing unmanaged environment full_stale",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: /tmp/full/full_another",
"DEBUG purgeUnmanagedContent(): Not purging environment /tmp/full/full_another",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: /tmp/full/full_master",
"DEBUG purgeUnmanagedContent(): Not purging environment /tmp/full/full_master",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: /tmp/full/full_qa",
"DEBUG purgeUnmanagedContent(): Not purging environment /tmp/full/full_qa",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: /tmp/full/full_stale",
"Removing unmanaged environment /tmp/full/full_stale",
}

for _, expectedLine := range expectedLines {
Expand Down Expand Up @@ -2221,14 +2221,14 @@ func TestPurgeStaleDeploymentOnlyWithAllowList(t *testing.T) {

expectedLines := []string{
"DEBUG purgeUnmanagedContent(): Glob'ing with path /tmp/full/full_*",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: full_another",
"DEBUG purgeUnmanagedContent(): Not purging environment full_another",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: full_master",
"DEBUG purgeUnmanagedContent(): Not purging environment full_master",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: full_qa",
"DEBUG purgeUnmanagedContent(): Not purging environment full_qa",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: full_stale",
"Removing unmanaged environment full_stale",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: /tmp/full/full_another",
"DEBUG purgeUnmanagedContent(): Not purging environment /tmp/full/full_another",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: /tmp/full/full_master",
"DEBUG purgeUnmanagedContent(): Not purging environment /tmp/full/full_master",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: /tmp/full/full_qa",
"DEBUG purgeUnmanagedContent(): Not purging environment /tmp/full/full_qa",
"DEBUG purgeUnmanagedContent(): Checking if environment should exist: /tmp/full/full_stale",
"Removing unmanaged environment /tmp/full/full_stale",
}

for _, expectedLine := range expectedLines {
Expand Down Expand Up @@ -2882,7 +2882,7 @@ func TestResolvePuppetfileUseSSHAgent(t *testing.T) {
if exitCode != 1 {
t.Errorf("terminated with %v, but we expected exit status %v Output: %s", exitCode, 1, string(out))
}
//fmt.Println(string(out))
// fmt.Println(string(out))

sshAddCmd := "ssh-add"
if runtime.GOOS == "darwin" {
Expand All @@ -2891,11 +2891,11 @@ func TestResolvePuppetfileUseSSHAgent(t *testing.T) {

expectedLines := []string{
"DEBUG git repo url [email protected]:foo/git_module_with_ssh_agent.git with loaded SSH keys from ssh-agent",
"DEBUG git repo url [email protected]:foobar/github_module_without_ssh_add.git with SSH key tests/TestConfigUseSSHAgent.yaml",
"DEBUG git repo url [email protected]:bar/git_module_with_ssh_add.git with SSH key tests/TestConfigUseSSHAgent.yaml",
"DEBUG git repo url [email protected]:foobar/github_module_without_ssh_add.git with SSH key tests/test-fake-key",
"DEBUG git repo url [email protected]:bar/git_module_with_ssh_add.git with SSH key tests/test-fake-key",
"DEBUG executeCommand(): Executing git clone --mirror [email protected]:foo/git_module_with_ssh_agent.git /tmp/g10k/modules/[email protected]_git_module_with_ssh_agent.git",
"DEBUG executeCommand(): Executing git clone --mirror [email protected]:foobar/github_module_without_ssh_add.git /tmp/g10k/modules/[email protected]_github_module_without_ssh_add.git",
"DEBUG executeCommand(): Executing ssh-agent bash -c '" + sshAddCmd + " tests/TestConfigUseSSHAgent.yaml; git clone --mirror [email protected]:bar/git_module_with_ssh_add.git /tmp/g10k/modules/[email protected]_git_module_with_ssh_add.git'",
"DEBUG executeCommand(): Executing ssh-agent bash -c '" + sshAddCmd + " tests/test-fake-key; git clone --mirror [email protected]:bar/git_module_with_ssh_add.git /tmp/g10k/modules/[email protected]_git_module_with_ssh_add.git'",
}

for _, expectedLine := range expectedLines {
Expand Down Expand Up @@ -3262,3 +3262,46 @@ func TestNoProxy(t *testing.T) {
}
}
}

func TestMultipleSourcesWithSameBrancheName(t *testing.T) {
funcName := strings.Split(funcName(), ".")[len(strings.Split(funcName(), "."))-1]
config = readConfigfile(filepath.Join("tests", "TestConfig2SourcesSameBranchNameDiffBaseDir.yaml"))
if os.Getenv("TEST_FOR_CRASH_"+funcName) == "1" {
debug = true
info = true
resolvePuppetEnvironment(false, "")
return
}
purgeDir("/tmp/example/", funcName)
purgeDir("/tmp/out/", funcName)
purgeDir("/tmp/out-clone/", funcName)

cmd := exec.Command(os.Args[0], "-test.run="+funcName+"$")
cmd.Env = append(os.Environ(), "TEST_FOR_CRASH_"+funcName+"=1")
_, err := cmd.CombinedOutput()

exitCode := 0
if msg, ok := err.(*exec.ExitError); ok { // there is error code
exitCode = msg.Sys().(syscall.WaitStatus).ExitStatus()
}

expectedExitCode := 0
if exitCode != expectedExitCode {
t.Errorf("terminated with %v, but we expected exit status %v", exitCode, expectedExitCode)
}
// fmt.Println(string(out))

expectedFiles := []string{
"/tmp/out-clone/another/Puppetfile",
"/tmp/out-clone/master/.g10k-deploy.json",
"/tmp/out/master/Puppetfile",
"/tmp/out/ref/uuui/d0",
}

for _, expectedFile := range expectedFiles {
if !fileExists(expectedFile) {
t.Errorf("files and/or directory missing that should be there! " + expectedFile)
}
}

}
6 changes: 1 addition & 5 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
}
}

func executeCommand(command string, commandDir string, timeout int, allowFail bool, disableHttpProxy bool) ExecResult {

Check failure on line 173 in helper.go

View workflow job for this annotation

GitHub Actions / Test on go version and ubuntu-latest

func parameter disableHttpProxy should be disableHTTPProxy

Check failure on line 173 in helper.go

View workflow job for this annotation

GitHub Actions / Test on go version and macOS-latest

func parameter disableHttpProxy should be disableHTTPProxy

Check failure on line 173 in helper.go

View workflow job for this annotation

GitHub Actions / Test on go version and ubuntu-latest

func parameter disableHttpProxy should be disableHTTPProxy

Check failure on line 173 in helper.go

View workflow job for this annotation

GitHub Actions / Test on go version and macOS-latest

func parameter disableHttpProxy should be disableHTTPProxy
if len(commandDir) > 0 {
Debugf("Executing " + command + " in cwd " + commandDir)
} else {
Expand Down Expand Up @@ -201,12 +201,8 @@
os.Unsetenv("https_proxy")
os.Unsetenv("HTTP_PROXY")
os.Unsetenv("HTTPS_PROXY")
execCommand.Env = os.Environ()
Debugf("exec OS env:" + strings.Join(execCommand.Env, ",") + " for command " + command)
} else {
execCommand.Env = os.Environ()
Debugf("exec OS env:" + strings.Join(execCommand.Env, ",") + " for command " + command)
}
execCommand.Env = os.Environ()
out, err := execCommand.CombinedOutput()
duration := time.Since(before).Seconds()
er := ExecResult{0, string(out)}
Expand Down Expand Up @@ -350,7 +346,7 @@
func stripComponent(component string, env string) string {
if regexp.MustCompile(`^/.*/$`).MatchString(component) {
return regexp.MustCompile(component[1:len(component)-1]).ReplaceAllString(env, "")
} else {

Check failure on line 349 in helper.go

View workflow job for this annotation

GitHub Actions / Test on go version and ubuntu-latest

if block ends with a return statement, so drop this else and outdent its block

Check failure on line 349 in helper.go

View workflow job for this annotation

GitHub Actions / Test on go version and macOS-latest

if block ends with a return statement, so drop this else and outdent its block

Check failure on line 349 in helper.go

View workflow job for this annotation

GitHub Actions / Test on go version and ubuntu-latest

if block ends with a return statement, so drop this else and outdent its block

Check failure on line 349 in helper.go

View workflow job for this annotation

GitHub Actions / Test on go version and macOS-latest

if block ends with a return statement, so drop this else and outdent its block
return strings.TrimPrefix(env, component)
}
}
Expand Down
4 changes: 2 additions & 2 deletions puppetfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func resolvePuppetEnvironment(tags bool, outputNameTag string) {
}

mutex.Lock()
if _, ok := allEnvironments[prefix+renamedBranch]; !ok {
allEnvironments[prefix+renamedBranch] = true
if _, ok := allEnvironments[filepath.Join(sa.Basedir, prefix+renamedBranch)]; !ok {
allEnvironments[filepath.Join(sa.Basedir, prefix+renamedBranch)] = true
} else {
Fatalf("Renamed environment naming conflict detected with renamed environment " + prefix + renamedBranch)
}
Expand Down
14 changes: 7 additions & 7 deletions stale.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ func purgeUnmanagedContent(allBasedirs map[string]bool, allEnvironments map[stri
}
}
if stringSliceContains(config.PurgeLevels, "deployment") {
Debugf("Checking if environment should exist: " + envName)
if allEnvironments[envName] {
Debugf("Not purging environment " + envName)
} else if stringSliceContains(allowlistEnvironments, filepath.Join(basedir, envName)) {
Debugf("Not purging environment " + envName + " due to deployment_purge_allowlist match")
Debugf("Checking if environment should exist: " + env)
if allEnvironments[env] {
Debugf("Not purging environment " + env)
} else if stringSliceContains(allowlistEnvironments, env) {
Debugf("Not purging environment " + env + " due to deployment_purge_allowlist match")
} else {
Infof("Removing unmanaged environment " + envName)
Infof("Removing unmanaged environment " + env)
if !dryRun {
purgeDir(filepath.Join(basedir, envName), "purgeStaleContent()")
purgeDir(env, "purgeStaleContent()")
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/TestConfig2SourcesSameBranchNameDiffBaseDir.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
cachedir: '/tmp/g10k'

sources:
example:
remote: 'https://github.com/xorpaul/g10k-fullworking-env-clone.git'
basedir: '/tmp/out/'
full:
remote: 'https://github.com/xorpaul/g10k-fullworking-env.git'
basedir: '/tmp/out-clone/'
8 changes: 4 additions & 4 deletions tests/TestConfigUseSSHAgent.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
:cachedir: '/tmp/g10k'
:cachedir: "/tmp/g10k"

sources:
example:
remote: 'https://github.com/xorpaul/g10k-environment.git'
basedir: '/tmp/example/'
private_key: 'tests/TestConfigUseSSHAgent.yaml' # just some existing file, we just want to check if the ssh-add command isn't used
remote: "https://github.com/xorpaul/g10k-environment.git"
basedir: "/tmp/example/"
private_key: "tests/test-fake-key" # just some existing file, we just want to check if the ssh-add command isn't used
38 changes: 38 additions & 0 deletions tests/test-fake-key
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEA2Bk3OVSuVcP0Wdw57JzKMxKbf3qwBPHZHrMN8MJ7S/qZ11zAUzAY
57Y4e6sE8dd+nC1hK2E8vBZcyib/W+mWJw3JzUHsGTJgZCi+kRieXwZmztwNC4+sUDwDf6
lT8K95kXV36r5IYoo16Fh5/yxYON+HBtDAY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