mirror of
https://github.com/thegeeklab/drone-yaml.git
synced 2024-11-24 11:00:39 +00:00
convert legacy branch syntax to ref trigger
This commit is contained in:
parent
daa7e18674
commit
e8b24d482c
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## Unreleased
|
||||
### Added
|
||||
- Convert legacy branch filter to ref trigger, by [@bradrydzewski](https://github.com/bradrydzewski).
|
||||
|
||||
## [1.2.1] - 2019-07-17
|
||||
### Added
|
||||
- Pull if-not-exists when converting legacy yaml files, by [@bradrydzewski](https://github.com/bradrydzewski).
|
||||
|
@ -67,7 +67,7 @@ func Convert(d []byte, remote string) ([]byte, error) {
|
||||
pipeline.Workspace.Path = ""
|
||||
}
|
||||
|
||||
if os.Getenv("DRONE_CONVERT_YAML_DEFAULT_WORKSPACE") == "true" {
|
||||
if remote != "" {
|
||||
if pipeline.Workspace.Base == "" {
|
||||
pipeline.Workspace.Base = "/drone"
|
||||
}
|
||||
@ -109,6 +109,24 @@ func Convert(d []byte, remote string) ([]byte, error) {
|
||||
pipeline.Trigger.Branch.Include = from.Branches.Include
|
||||
pipeline.Trigger.Branch.Exclude = from.Branches.Exclude
|
||||
|
||||
// if the user specifies branch conditions, we need to make
|
||||
// sure they are still able to execute tag events.
|
||||
if len(from.Branches.Include) > 0 && len(from.Branches.Exclude) == 0 {
|
||||
pipeline.Trigger.Branch.Include = nil
|
||||
pipeline.Trigger.Ref.Include = []string{
|
||||
"refs/tags/**",
|
||||
"refs/pull/**", // github
|
||||
"refs/pull-requests/**", // bitbucket
|
||||
"refs/merge-requests/**", // gitlab
|
||||
}
|
||||
for _, branch := range from.Branches.Include {
|
||||
pipeline.Trigger.Ref.Include = append(
|
||||
pipeline.Trigger.Ref.Include,
|
||||
"refs/heads/"+branch,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// registry credentials need to be emulated in 0.8. The
|
||||
// migration utility automatically creates a secret named
|
||||
// .dockerconfigjson for the registry credentials, which
|
||||
|
@ -20,6 +20,10 @@ func TestConvert(t *testing.T) {
|
||||
before: "testdata/simple.yml",
|
||||
after: "testdata/simple.yml.golden",
|
||||
},
|
||||
{
|
||||
before: "testdata/branches.yml",
|
||||
after: "testdata/branches.yml.golden",
|
||||
},
|
||||
{
|
||||
before: "testdata/vault_1.yml",
|
||||
after: "testdata/vault_1.yml.golden",
|
||||
|
8
yaml/converter/legacy/internal/testdata/branches.yml
vendored
Normal file
8
yaml/converter/legacy/internal/testdata/branches.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
branches:
|
||||
- master
|
||||
|
||||
pipeline:
|
||||
greeting:
|
||||
image: alpine
|
||||
commands:
|
||||
- echo hello
|
24
yaml/converter/legacy/internal/testdata/branches.yml.golden
vendored
Normal file
24
yaml/converter/legacy/internal/testdata/branches.yml.golden
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
steps:
|
||||
- name: greeting
|
||||
pull: if-not-exists
|
||||
image: alpine
|
||||
commands:
|
||||
- echo hello
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/tags/**
|
||||
- refs/pull/**
|
||||
- refs/pull-requests/**
|
||||
- refs/merge-requests/**
|
||||
- refs/heads/master
|
||||
|
||||
...
|
@ -70,7 +70,11 @@ volumes:
|
||||
path: /tmp/go
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- master
|
||||
ref:
|
||||
- refs/tags/**
|
||||
- refs/pull/**
|
||||
- refs/pull-requests/**
|
||||
- refs/merge-requests/**
|
||||
- refs/heads/master
|
||||
|
||||
...
|
||||
|
Loading…
Reference in New Issue
Block a user