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

View file

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