Fix ARTIFACT env-var being replaced if only one entry is listed.

Also, use WriteEnv.
This commit is contained in:
Nurahmadie 2014-03-11 13:49:10 +07:00
parent d406aab849
commit 1dbef76780
2 changed files with 14 additions and 8 deletions

View file

@ -63,12 +63,14 @@ func (s *SSH) Write(f *buildfile.Buildfile) {
}
}
if len(s.Artifacts) > 1 && !artifact {
if !artifact {
if len(s.Artifacts) > 1 {
artifact = compress(f, s.Artifacts)
} else if len(s.Artifacts) == 1 {
f.WriteCmdSilent(fmt.Sprintf("ARTIFACT=%s", s.Artifacts[0]))
f.WriteEnv("ARTIFACT", s.Artifacts[0])
artifact = true
}
}
if artifact {
scpCmd := "scp -o StrictHostKeyChecking=no -P %s ${ARTIFACT} %s"
@ -82,15 +84,15 @@ func (s *SSH) Write(f *buildfile.Buildfile) {
}
func createGitArchive(f *buildfile.Buildfile) bool {
f.WriteCmdSilent("COMMIT=$(git rev-parse HEAD)")
f.WriteCmdSilent("ARTIFACT=${PWD##*/}-${COMMIT}.tar.gz")
f.WriteEnv("COMMIT", "$(git rev-parse HEAD)")
f.WriteEnv("ARTIFACT", "${PWD##*/}-${COMMIT}.tar.gz")
f.WriteCmdSilent("git archive --format=tar.gz --prefix=${PWD##*/}/ ${COMMIT} > ${ARTIFACT}")
return true
}
func compress(f *buildfile.Buildfile, files []string) bool {
cmd := "tar -cf ${ARTIFACT} %s"
f.WriteCmdSilent("ARTIFACT=${PWD##*/}.tar.gz")
f.WriteEnv("ARTIFACT", "${PWD##*/}.tar.gz")
f.WriteCmdSilent(fmt.Sprintf(cmd, strings.Join(files, " ")))
return true
}

View file

@ -119,6 +119,10 @@ func TestSSHGitArchive(t *testing.T) {
t.Errorf("Expect script to contains artifact")
}
if strings.Contains(bscr, "=GITARCHIVE") {
t.Errorf("Doesn't expect script to contains GITARCHIVE literals")
}
if !strings.Contains(bscr, "git archive --format=tar.gz --prefix=${PWD##*/}/ ${COMMIT} > ${ARTIFACT}") {
t.Errorf("Expect script to run git archive")
}