Skip to content

Commit

Permalink
Add option to set the local repository path to the cli command exec. (#…
Browse files Browse the repository at this point in the history
…3524)

The cli command exec not handle in a coherent way the repository path
when a directory or filename is given for the pipeline.

` woodpecker-cli exec [command options] [path/to/.woodpecker.yaml]`

If the path to the pipeline is a file in the `.woodpecker` directory,
for example: `.woodpecker/pipeline.yaml`,
the repository path will be: `.woodpecker`

If the path to the pipeline yaml is a directory with more than one
level, for example `ci/woodpecker/`,
the repository path will be:  `ci`

In order not to break the old behavior we added a new option to put the
root directory of the repository:
~~~
woodpecker-cli exec --local --repo-path . --pipeline-event manual
.woodpecker/build.yml
~~~
  • Loading branch information
manuelluis authored Mar 20, 2024
1 parent 5a2a4bd commit 9c684b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cli/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ func run(c *cli.Context) error {

func execDir(c *cli.Context, dir string) error {
// TODO: respect pipeline dependency
repoPath, _ := filepath.Abs(filepath.Dir(dir))
repoPath := c.String("repo-path")
if repoPath != "" {
repoPath, _ = filepath.Abs(repoPath)
} else {
repoPath, _ = filepath.Abs(filepath.Dir(dir))
}
if runtime.GOOS == "windows" {
repoPath = convertPathForWindows(repoPath)
}
Expand All @@ -79,7 +84,12 @@ func execDir(c *cli.Context, dir string) error {
}

func execFile(c *cli.Context, file string) error {
repoPath, _ := filepath.Abs(filepath.Dir(file))
repoPath := c.String("repo-path")
if repoPath != "" {
repoPath, _ = filepath.Abs(repoPath)
} else {
repoPath, _ = filepath.Abs(filepath.Dir(file))
}
if runtime.GOOS == "windows" {
repoPath = convertPathForWindows(repoPath)
}
Expand Down
5 changes: 5 additions & 0 deletions cli/exec/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ var flags = []cli.Flag{
Usage: "run from local directory",
Value: true,
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_REPO_PATH"},
Name: "repo-path",
Usage: "path to local repository",
},
&cli.DurationFlag{
EnvVars: []string{"WOODPECKER_TIMEOUT"},
Name: "timeout",
Expand Down
2 changes: 2 additions & 0 deletions docs/versioned_docs/version-2.4/40-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ execute a local pipeline

**--repo-clone-url**="":

**--repo-path**="": path to local repository

**--repo-private**="":

**--repo-remote-id**="":
Expand Down

0 comments on commit 9c684b7

Please sign in to comment.