mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-04 02:13:10 +00:00
Respect directory
option for steps again (#4319)
This commit is contained in:
@@ -18,10 +18,19 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
func generateScriptWindows(commands []string) string {
|
||||
func generateScriptWindows(commands []string, workDir string) string {
|
||||
var buf bytes.Buffer
|
||||
|
||||
if err := setupScriptWinTmpl.Execute(&buf, map[string]string{
|
||||
"WorkDir": workDir,
|
||||
}); err != nil {
|
||||
// should never happen but well we have an error to trance
|
||||
return fmt.Sprintf("echo 'failed to generate posix script from commands: %s'; exit 1", err.Error())
|
||||
}
|
||||
|
||||
for _, command := range commands {
|
||||
escaped := fmt.Sprintf("%q", command)
|
||||
escaped = strings.ReplaceAll(escaped, "$", `\$`)
|
||||
@@ -31,16 +40,13 @@ func generateScriptWindows(commands []string) string {
|
||||
command,
|
||||
))
|
||||
}
|
||||
script := fmt.Sprintf(
|
||||
setupScriptWin,
|
||||
buf.String(),
|
||||
)
|
||||
return script
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
const setupScriptWin = `
|
||||
const setupScriptWinProto = `
|
||||
$ErrorActionPreference = 'Stop';
|
||||
if ([Environment]::GetEnvironmentVariable('CI_WORKSPACE')) { if (-not (Test-Path "$env:CI_WORKSPACE")) { New-Item -Path "$env:CI_WORKSPACE" -ItemType Directory -Force }};
|
||||
if (-not (Test-Path "{{.WorkDir}}")) { New-Item -Path "{{.WorkDir}}" -ItemType Directory -Force };
|
||||
if (-not [Environment]::GetEnvironmentVariable('HOME')) { [Environment]::SetEnvironmentVariable('HOME', 'c:\root') };
|
||||
if (-not (Test-Path "$env:HOME")) { New-Item -Path "$env:HOME" -ItemType Directory -Force };
|
||||
if ($Env:CI_NETRC_MACHINE) {
|
||||
@@ -51,10 +57,11 @@ $netrc=[string]::Format("{0}\_netrc",$Env:HOME);
|
||||
};
|
||||
[Environment]::SetEnvironmentVariable("CI_NETRC_PASSWORD",$null);
|
||||
[Environment]::SetEnvironmentVariable("CI_SCRIPT",$null);
|
||||
if ([Environment]::GetEnvironmentVariable('CI_WORKSPACE')) { cd "$env:CI_WORKSPACE" };
|
||||
%s
|
||||
cd "{{.WorkDir}}";
|
||||
`
|
||||
|
||||
var setupScriptWinTmpl, _ = template.New("").Parse(setupScriptWinProto)
|
||||
|
||||
// traceScript is a helper script that is added to the step script
|
||||
// to trace a command.
|
||||
const traceScriptWin = `
|
||||
|
Reference in New Issue
Block a user