1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-11-29 21:48:14 +02:00

Resolve built-in variables for global when filter (#1790)

addresses
bd461477bd

close  #1244, close #1580

---------

Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
6543
2023-06-05 00:15:07 +02:00
committed by GitHub
parent c919f32e0b
commit ea895baf83
25 changed files with 990 additions and 581 deletions

View File

@@ -2,10 +2,11 @@ package compiler
import (
"fmt"
"path"
"strings"
backend "github.com/woodpecker-ci/woodpecker/pipeline/backend/types"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/metadata"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml"
"github.com/woodpecker-ci/woodpecker/shared/constant"
)
@@ -75,7 +76,7 @@ type Compiler struct {
cloneEnv map[string]string
base string
path string
metadata frontend.Metadata
metadata metadata.Metadata
registries []Registry
secrets secretMap
cacher Cacher
@@ -156,7 +157,7 @@ func (c *Compiler) Compile(conf *yaml.Config) (*backend.Config, error) {
// add default clone step
if !c.local && len(conf.Clone.Containers) == 0 && !conf.SkipClone {
cloneSettings := map[string]interface{}{"depth": "0"}
if c.metadata.Curr.Event == frontend.EventTag {
if c.metadata.Curr.Event == metadata.EventTag {
cloneSettings["tags"] = "true"
}
container := &yaml.Container{
@@ -263,7 +264,7 @@ func (c *Compiler) setupCache(conf *yaml.Config, ir *backend.Config) {
return
}
container := c.cacher.Restore(c.metadata.Repo.Name, c.metadata.Curr.Commit.Branch, conf.Cache)
container := c.cacher.Restore(path.Join(c.metadata.Repo.Owner, c.metadata.Repo.Name), c.metadata.Curr.Commit.Branch, conf.Cache)
name := fmt.Sprintf("%s_restore_cache", c.prefix)
step := c.createProcess(name, container, "cache")
@@ -276,10 +277,10 @@ func (c *Compiler) setupCache(conf *yaml.Config, ir *backend.Config) {
}
func (c *Compiler) setupCacheRebuild(conf *yaml.Config, ir *backend.Config) {
if c.local || len(conf.Cache) == 0 || c.metadata.Curr.Event != frontend.EventPush || c.cacher == nil {
if c.local || len(conf.Cache) == 0 || c.metadata.Curr.Event != metadata.EventPush || c.cacher == nil {
return
}
container := c.cacher.Rebuild(c.metadata.Repo.Name, c.metadata.Curr.Commit.Branch, conf.Cache)
container := c.cacher.Rebuild(path.Join(c.metadata.Repo.Owner, c.metadata.Repo.Name), c.metadata.Curr.Commit.Branch, conf.Cache)
name := fmt.Sprintf("%s_rebuild_cache", c.prefix)
step := c.createProcess(name, container, "cache")

View File

@@ -9,7 +9,7 @@ import (
"github.com/rs/zerolog/log"
backend "github.com/woodpecker-ci/woodpecker/pipeline/backend/types"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/metadata"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/compiler/settings"
)
@@ -152,7 +152,7 @@ func (c *Compiler) createProcess(name string, container *yaml.Container, section
failure := container.Failure
if container.Failure == "" {
failure = frontend.FailureFail
failure = metadata.FailureFail
}
return &backend.Step{

View File

@@ -20,7 +20,7 @@ import (
"path/filepath"
"strings"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/metadata"
)
// Option configures a compiler option.
@@ -67,7 +67,7 @@ func WithSecret(secrets ...Secret) Option {
// and system metadata. The metadata is used to remove steps from
// the compiled pipeline configuration that should be skipped. The
// metadata is also added to each container as environment variables.
func WithMetadata(metadata frontend.Metadata) Option {
func WithMetadata(metadata metadata.Metadata) Option {
return func(compiler *Compiler) {
compiler.metadata = metadata

View File

@@ -3,10 +3,9 @@ package compiler
import (
"os"
"reflect"
"strings"
"testing"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/metadata"
)
func TestWithWorkspace(t *testing.T) {
@@ -98,9 +97,10 @@ func TestWithPrefix(t *testing.T) {
}
func TestWithMetadata(t *testing.T) {
metadata := frontend.Metadata{
Repo: frontend.Repo{
Name: "octocat/hello-world",
metadata := metadata.Metadata{
Repo: metadata.Repo{
Owner: "octacat",
Name: "hello-world",
Private: true,
Link: "https://github.com/octocat/hello-world",
CloneURL: "https://github.com/octocat/hello-world.git",
@@ -113,7 +113,7 @@ func TestWithMetadata(t *testing.T) {
t.Errorf("WithMetadata must set compiler the metadata")
}
if compiler.env["CI_REPO_NAME"] != strings.Split(metadata.Repo.Name, "/")[1] {
if compiler.env["CI_REPO_NAME"] != metadata.Repo.Name {
t.Errorf("WithMetadata must set CI_REPO_NAME")
}
if compiler.env["CI_REPO_URL"] != metadata.Repo.Link {