Fix cli matrix filter (#311)

Using `when` (Conditional Execution) with `matrix` did not work, fix it.
This commit is contained in:
sam-tang-sw 2021-09-21 11:47:08 +08:00 committed by GitHub
parent 5653577d7e
commit d802fdb26d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,6 @@ import (
"io"
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
"runtime"
@ -318,7 +317,7 @@ func execWithAxis(c *cli.Context, axis matrix.Axis) error {
file = ".drone.yml"
}
metadata := metadataFromContext(c)
metadata := metadataFromContext(c, axis)
environ := metadata.Environ()
secrets := []compiler.Secret{}
for k, v := range metadata.EnvironDrone() {
@ -332,12 +331,6 @@ func execWithAxis(c *cli.Context, axis matrix.Axis) error {
})
}
if len(axis) != 0 {
for k, v := range axis {
environ[k] = v
}
}
droneEnv := make(map[string]string)
for _, env := range c.StringSlice("env") {
envs := strings.SplitN(env, "=", 2)
@ -434,7 +427,7 @@ func execWithAxis(c *cli.Context, axis matrix.Axis) error {
}
// return the metadata from the cli context.
func metadataFromContext(c *cli.Context) frontend.Metadata {
func metadataFromContext(c *cli.Context, axis matrix.Axis) frontend.Metadata {
return frontend.Metadata{
Repo: frontend.Repo{
Name: c.String("repo-name"),
@ -488,7 +481,7 @@ func metadataFromContext(c *cli.Context) frontend.Metadata {
},
Job: frontend.Job{
Number: c.Int("job-number"),
Matrix: availableEnvironment(),
Matrix: axis,
},
Sys: frontend.System{
Name: c.String("system-name"),
@ -498,17 +491,6 @@ func metadataFromContext(c *cli.Context) frontend.Metadata {
}
}
func availableEnvironment() map[string]string {
result := make(map[string]string, 0)
for _, env := range os.Environ() {
pair := strings.SplitN(env, "=", 2)
result[pair[0]] = pair[1]
}
return result
}
func convertPathForWindows(path string) string {
base := filepath.VolumeName(path)
if len(base) == 2 {