mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-21 05:36:18 +00:00
parent
de53b906e8
commit
c75068920c
2 changed files with 15 additions and 12 deletions
|
@ -23,7 +23,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
@ -55,10 +54,10 @@ func (e *local) setupClone(state *workflowState) error {
|
||||||
|
|
||||||
log.Info().Msg("no global 'plugin-git' installed, try to download for current workflow")
|
log.Info().Msg("no global 'plugin-git' installed, try to download for current workflow")
|
||||||
state.pluginGitBinary = filepath.Join(state.homeDir, "plugin-git")
|
state.pluginGitBinary = filepath.Join(state.homeDir, "plugin-git")
|
||||||
if runtime.GOOS == "windows" {
|
if e.os == "windows" {
|
||||||
state.pluginGitBinary += ".exe"
|
state.pluginGitBinary += ".exe"
|
||||||
}
|
}
|
||||||
return downloadLatestGitPluginBinary(state.pluginGitBinary)
|
return e.downloadLatestGitPluginBinary(state.pluginGitBinary)
|
||||||
}
|
}
|
||||||
|
|
||||||
// execClone executes a clone-step locally
|
// execClone executes a clone-step locally
|
||||||
|
@ -79,7 +78,7 @@ func (e *local) execClone(ctx context.Context, step *types.Step, state *workflow
|
||||||
log.Warn().Msgf("clone step image '%s' does not match default git clone image. We ignore it and use our plugin-git anyway.", step.Image)
|
log.Warn().Msgf("clone step image '%s' does not match default git clone image. We ignore it and use our plugin-git anyway.", step.Image)
|
||||||
}
|
}
|
||||||
|
|
||||||
rmCmd, err := writeNetRC(step, state)
|
rmCmd, err := e.writeNetRC(step, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -88,7 +87,7 @@ func (e *local) execClone(ctx context.Context, step *types.Step, state *workflow
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
if rmCmd != "" {
|
if rmCmd != "" {
|
||||||
// if we have a netrc injected we have to make sure it's deleted in any case after clone was attempted
|
// if we have a netrc injected we have to make sure it's deleted in any case after clone was attempted
|
||||||
if runtime.GOOS == "windows" {
|
if e.os == "windows" {
|
||||||
pwsh, err := exec.LookPath("powershell.exe")
|
pwsh, err := exec.LookPath("powershell.exe")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -114,7 +113,7 @@ func (e *local) execClone(ctx context.Context, step *types.Step, state *workflow
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeNetRC write a netrc file into the home dir of a given workflow state
|
// writeNetRC write a netrc file into the home dir of a given workflow state
|
||||||
func writeNetRC(step *types.Step, state *workflowState) (string, error) {
|
func (e *local) writeNetRC(step *types.Step, state *workflowState) (string, error) {
|
||||||
if step.Environment["CI_NETRC_MACHINE"] == "" {
|
if step.Environment["CI_NETRC_MACHINE"] == "" {
|
||||||
log.Trace().Msg("no netrc to write")
|
log.Trace().Msg("no netrc to write")
|
||||||
return "", nil
|
return "", nil
|
||||||
|
@ -122,7 +121,7 @@ func writeNetRC(step *types.Step, state *workflowState) (string, error) {
|
||||||
|
|
||||||
file := filepath.Join(state.homeDir, ".netrc")
|
file := filepath.Join(state.homeDir, ".netrc")
|
||||||
rmCmd := fmt.Sprintf("rm \"%s\"", file)
|
rmCmd := fmt.Sprintf("rm \"%s\"", file)
|
||||||
if runtime.GOOS == "windows" {
|
if e.os == "windows" {
|
||||||
file = filepath.Join(state.homeDir, "_netrc")
|
file = filepath.Join(state.homeDir, "_netrc")
|
||||||
rmCmd = fmt.Sprintf("del \"%s\"", file)
|
rmCmd = fmt.Sprintf("del \"%s\"", file)
|
||||||
}
|
}
|
||||||
|
@ -133,7 +132,7 @@ func writeNetRC(step *types.Step, state *workflowState) (string, error) {
|
||||||
|
|
||||||
// downloadLatestGitPluginBinary download the latest plugin-git binary based on runtime OS and Arch
|
// downloadLatestGitPluginBinary download the latest plugin-git binary based on runtime OS and Arch
|
||||||
// and saves it to dest
|
// and saves it to dest
|
||||||
func downloadLatestGitPluginBinary(dest string) error {
|
func (e *local) downloadLatestGitPluginBinary(dest string) error {
|
||||||
type asset struct {
|
type asset struct {
|
||||||
Name string
|
Name string
|
||||||
BrowserDownloadURL string `json:"browser_download_url"`
|
BrowserDownloadURL string `json:"browser_download_url"`
|
||||||
|
@ -159,7 +158,7 @@ func downloadLatestGitPluginBinary(dest string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, at := range rel.Assets {
|
for _, at := range rel.Assets {
|
||||||
if strings.Contains(at.Name, runtime.GOOS) && strings.Contains(at.Name, runtime.GOARCH) {
|
if strings.Contains(at.Name, e.os) && strings.Contains(at.Name, e.arch) {
|
||||||
resp2, err := http.Get(at.BrowserDownloadURL)
|
resp2, err := http.Get(at.BrowserDownloadURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not download plugin-git: %w", err)
|
return fmt.Errorf("could not download plugin-git: %w", err)
|
||||||
|
|
|
@ -45,11 +45,15 @@ type local struct {
|
||||||
workflows sync.Map
|
workflows sync.Map
|
||||||
output io.ReadCloser
|
output io.ReadCloser
|
||||||
pluginGitBinary string
|
pluginGitBinary string
|
||||||
|
os, arch string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new local Engine.
|
// New returns a new local Engine.
|
||||||
func New() types.Engine {
|
func New() types.Engine {
|
||||||
return &local{}
|
return &local{
|
||||||
|
os: runtime.GOOS,
|
||||||
|
arch: runtime.GOARCH,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *local) Name() string {
|
func (e *local) Name() string {
|
||||||
|
@ -64,7 +68,7 @@ func (e *local) Load(context.Context) (*types.EngineInfo, error) {
|
||||||
e.loadClone()
|
e.loadClone()
|
||||||
|
|
||||||
return &types.EngineInfo{
|
return &types.EngineInfo{
|
||||||
Platform: runtime.GOOS + "/" + runtime.GOARCH,
|
Platform: e.os + "/" + e.arch,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +153,7 @@ func (e *local) execCommands(ctx context.Context, step *types.Step, state *workf
|
||||||
e.output, _ = cmd.StdoutPipe()
|
e.output, _ = cmd.StdoutPipe()
|
||||||
cmd.Stderr = cmd.Stdout
|
cmd.Stderr = cmd.Stdout
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if e.os == "windows" {
|
||||||
// we get non utf8 output from windows so just sanitize it
|
// we get non utf8 output from windows so just sanitize it
|
||||||
// TODO: remove hack
|
// TODO: remove hack
|
||||||
e.output = io.NopCloser(transform.NewReader(e.output, unicode.UTF8.NewDecoder().Transformer))
|
e.output = io.NopCloser(transform.NewReader(e.output, unicode.UTF8.NewDecoder().Transformer))
|
||||||
|
|
Loading…
Reference in a new issue