Fix ARTIFACT env-var being replaced if only one entry is listed.
Also, use WriteEnv.
This commit is contained in:
parent
d406aab849
commit
1dbef76780
2 changed files with 14 additions and 8 deletions
|
@ -63,11 +63,13 @@ func (s *SSH) Write(f *buildfile.Buildfile) {
|
|||
}
|
||||
}
|
||||
|
||||
if len(s.Artifacts) > 1 && !artifact {
|
||||
artifact = compress(f, s.Artifacts)
|
||||
} else if len(s.Artifacts) == 1 {
|
||||
f.WriteCmdSilent(fmt.Sprintf("ARTIFACT=%s", s.Artifacts[0]))
|
||||
artifact = true
|
||||
if !artifact {
|
||||
if len(s.Artifacts) > 1 {
|
||||
artifact = compress(f, s.Artifacts)
|
||||
} else if len(s.Artifacts) == 1 {
|
||||
f.WriteEnv("ARTIFACT", s.Artifacts[0])
|
||||
artifact = true
|
||||
}
|
||||
}
|
||||
|
||||
if artifact {
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue