Add option to set the local repository path to the cli command exec. (#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
~~~
This commit is contained in:
manuelluis 2024-03-21 00:19:48 +01:00 committed by GitHub
parent 5a2a4bd53c
commit 9c684b7a22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 2 deletions

View file

@ -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)
}
@ -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)
}

View file

@ -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",

View file

@ -280,6 +280,8 @@ execute a local pipeline
**--repo-clone-url**="":
**--repo-path**="": path to local repository
**--repo-private**="":
**--repo-remote-id**="":