Skip to content

Commit

Permalink
Merge branch 'main' into pipeline-config_version
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 committed Nov 4, 2023
2 parents 57cb25d + a0f2ee9 commit adc5aad
Show file tree
Hide file tree
Showing 22 changed files with 358 additions and 86 deletions.
13 changes: 9 additions & 4 deletions .woodpecker/docs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: 1

when:
- event: tag
- event: pull_request
- event: push
path: &when_path
Expand Down Expand Up @@ -61,22 +62,26 @@ steps:
secrets:
- BOT_PRIVATE_KEY
commands:
- apk add openssh-client git rsync
- apk add openssh-client git rsync jq
- mkdir -p $HOME/.ssh
- ssh-keyscan -t rsa github.com >> $HOME/.ssh/known_hosts
- echo "$BOT_PRIVATE_KEY" > $HOME/.ssh/id_rsa
- chmod 0600 $HOME/.ssh/id_rsa
- git config --global user.email "woodpecker-bot@obermui.de"
- git config --global user.name "woodpecker-bot"
- git clone --depth 1 --single-branch git@github.com:woodpecker-ci/woodpecker-ci.github.io.git /repo
# update latest and next version
- if [ "$CI_PIPELINE_EVENT" == "tag" ] ; then jq '.latest = ${CI_COMMIT_TAG}' repo/version.json > repo/version.json.tmp && mv repo/version.json.tmp repo/version.json ; fi
- if [ "$CI_PIPELINE_EVENT" == "push" ] ; then jq "next-" '.next = ${CI_COMMIT_SHA:0:10}' repo/version.json > repo/version.json.tmp && mv repo/version.json.tmp repo/version.json ; fi
# copy all docs files and delete all old ones, but leave CNAME and index.yaml untouched
- rsync -r --exclude .git --exclude CNAME --exclude index.yaml --exclude README.md --delete docs/build/ /repo
- rsync -r --exclude .git --exclude CNAME --exclude index.yaml --exclude README.md --exclude version.json --delete docs/build/ /repo
- cd /repo
- git add .
# exit successfully if nothing changed
- test -n "$(git status --porcelain)" || exit 0
- git commit -m "Deploy website - based on ${CI_COMMIT_SHA}"
- git push
when:
event: [push, cron]
path: *when_path
- event: [push, cron]
path: *when_path
- event: tag
6 changes: 5 additions & 1 deletion cli/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ func execWithAxis(c *cli.Context, file, repoPath string, axis matrix.Axis) error
}

// lint the yaml file
if lerr := linter.New(linter.WithTrusted(true)).Lint(confstr, conf); lerr != nil {
if lerr := linter.New(linter.WithTrusted(true)).Lint([]*linter.WorkflowConfig{{
File: path.Base(file),
RawConfig: confstr,
Workflow: conf,
}}); lerr != nil {
return lerr
}

Expand Down
11 changes: 9 additions & 2 deletions cli/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,16 @@ func lintFile(_ *cli.Context, file string) error {
return err
}

err = linter.New(linter.WithTrusted(true)).Lint(string(buf), c)
config := &linter.WorkflowConfig{
File: path.Base(file),
RawConfig: rawConfig,
Workflow: c,
}

// TODO: lint multiple files at once to allow checks for sth like "depends_on" to work
err = linter.New(linter.WithTrusted(true)).Lint([]*linter.WorkflowConfig{config})
if err != nil {
fmt.Printf("🔥 %s has errors:\n", output.String(path.Base(file)).Underline())
fmt.Printf("🔥 %s has errors:\n", output.String(config.File).Underline())

hasErrors := true
for _, err := range pipeline_errors.GetPipelineErrors(err) {
Expand Down
4 changes: 2 additions & 2 deletions pipeline/backend/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (e *kube) SetupWorkflow(ctx context.Context, conf *types.Config, taskUUID s
return err
}
log.Trace().Str("pod-name", stepName).Msgf("Creating service: %s", step.Name)
svc, err := Service(e.config.Namespace, step.Name, step.Alias, step.Ports)
svc, err := Service(e.config.Namespace, step.Name, step.Ports)
if err != nil {
return err
}
Expand Down Expand Up @@ -391,7 +391,7 @@ func (e *kube) DestroyWorkflow(_ context.Context, conf *types.Config, taskUUID s
if stage.Alias == "services" {
for _, step := range stage.Steps {
log.Trace().Msgf("Deleting service: %s", step.Name)
svc, err := Service(e.config.Namespace, step.Name, step.Alias, step.Ports)
svc, err := Service(e.config.Namespace, step.Name, step.Ports)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pipeline/backend/kubernetes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)

func Service(namespace, name, podName string, ports []uint16) (*v1.Service, error) {
func Service(namespace, name string, ports []uint16) (*v1.Service, error) {
var svcPorts []v1.ServicePort
for _, port := range ports {
svcPorts = append(svcPorts, v1.ServicePort{
Expand All @@ -42,7 +42,7 @@ func Service(namespace, name, podName string, ports []uint16) (*v1.Service, erro
Spec: v1.ServiceSpec{
Type: v1.ServiceTypeClusterIP,
Selector: map[string]string{
"step": podName,
"step": dnsName,
},
Ports: svcPorts,
},
Expand Down
4 changes: 2 additions & 2 deletions pipeline/backend/kubernetes/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestService(t *testing.T) {
}
],
"selector": {
"step": "baz"
"step": "bar"
},
"type": "ClusterIP"
},
Expand All @@ -54,7 +54,7 @@ func TestService(t *testing.T) {
}
}`

s, _ := Service("foo", "bar", "baz", []uint16{1, 2, 3})
s, _ := Service("foo", "bar", []uint16{1, 2, 3})
j, err := json.Marshal(s)
assert.NoError(t, err)
assert.JSONEq(t, expected, string(j))
Expand Down
7 changes: 7 additions & 0 deletions pipeline/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ type PipelineError struct {
}

type LinterErrorData struct {
File string `json:"file"`
Field string `json:"field"`
}

type DeprecationErrorData struct {
File string `json:"file"`
Field string `json:"field"`
Docs string `json:"docs"`
}

func (e *PipelineError) Error() string {
return fmt.Sprintf("[%s] %s", e.Type, e.Message)
}
Expand Down
4 changes: 2 additions & 2 deletions pipeline/frontend/yaml/linter/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"github.com/woodpecker-ci/woodpecker/pipeline/errors"
)

func newLinterError(message, field string, isWarning bool) *errors.PipelineError {
func newLinterError(message, file, field string, isWarning bool) *errors.PipelineError {
return &errors.PipelineError{
Type: errors.PipelineErrorTypeLinter,
Message: message,
Data: &errors.LinterErrorData{Field: field},
Data: &errors.LinterErrorData{File: file, Field: field},
IsWarning: isWarning,
}
}
Loading

0 comments on commit adc5aad

Please sign in to comment.