mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 02:11:01 +00:00
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,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)
|
artifact = compress(f, s.Artifacts)
|
||||||
} else if len(s.Artifacts) == 1 {
|
} else if len(s.Artifacts) == 1 {
|
||||||
f.WriteCmdSilent(fmt.Sprintf("ARTIFACT=%s", s.Artifacts[0]))
|
f.WriteEnv("ARTIFACT", s.Artifacts[0])
|
||||||
artifact = true
|
artifact = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if artifact {
|
if artifact {
|
||||||
scpCmd := "scp -o StrictHostKeyChecking=no -P %s ${ARTIFACT} %s"
|
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 {
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue