github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/gitlab/yaml/job.go (about) 1 // Copyright 2022 Harness, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package yaml 16 17 import "errors" 18 19 // Job defines a gitlab job. 20 // https://docs.gitlab.com/ee/ci/yaml/#job-keywords 21 type Job struct { 22 After Stringorslice `yaml:"after_script,omitempty"` 23 Artifacts *Artifacts `yaml:"artifacts,omitempty"` 24 AllowFailure *AllowFailure `yaml:"allow_failure,omitempty"` 25 Before Stringorslice `yaml:"before_script,omitempty"` 26 Cache *Cache `yaml:"cache,omitempty"` 27 Coverage string `yaml:"coverage,omitempty"` 28 DASTConfiguration *DASTConfiguration `yaml:"dast_configuration,omitempty"` 29 Dependencies Stringorslice `yaml:"dependencies,omitempty"` 30 Environment *Environment `yaml:"environment,omitempty"` 31 Except *Conditions `yaml:"except,omitempty"` 32 Extends Stringorslice `yaml:"extends,omitempty"` 33 Hooks map[string]Stringorslice `yaml:"hooks,omitempty"` 34 IDTokens map[string]*IDToken `yaml:"id_tokens,omitempty"` 35 Image *Image `yaml:"image,omitempty"` 36 Inherit *Inherit `yaml:"inherit,omitempty"` 37 Interruptible bool `yaml:"interruptible,omitempty"` 38 Needs *Needs `yaml:"needs,omitempty"` 39 Only *Conditions `yaml:"only,omitempty"` 40 Pages *Job `yaml:"pages,omitempty"` 41 Parallel *Parallel `yaml:"parallel,omitempty"` 42 Publish string `yaml:"publish,omitempty"` 43 Release *Release `yaml:"release,omitempty"` 44 ResourceGroup string `yaml:"resource_group,omitempty"` 45 Retry *Retry `yaml:"retry,omitempty"` 46 Rules []*Rule `yaml:"rules,omitempty"` 47 Script Stringorslice `yaml:"script,omitempty"` 48 Secrets map[string]*Secret `yaml:"secrets,omitempty"` 49 Services []*Image `yaml:"services,omitempty"` 50 Stage string `yaml:"stage,omitempty"` 51 Tags Stringorslice `yaml:"tags,omitempty"` 52 Timeout string `yaml:"timeout,omitempty"` 53 Trigger *Trigger `yaml:"trigger,omitempty"` 54 Variables map[string]*Variable `yaml:"variables,omitempty"` 55 When string `yaml:"when,omitempty"` // on_success, manual, always, on_failure, delayed, never 56 } 57 58 // UnmarshalYAML implements the unmarshal interface. 59 func (v *Job) UnmarshalYAML(unmarshal func(interface{}) error) error { 60 var out1 []string 61 var out2 = struct { 62 After Stringorslice `yaml:"after_script,omitempty"` 63 Artifacts *Artifacts `yaml:"artifacts,omitempty"` 64 AllowFailure *AllowFailure `yaml:"allow_failure,omitempty"` 65 Before Stringorslice `yaml:"before_script,omitempty"` 66 Cache *Cache `yaml:"cache,omitempty"` 67 Coverage string `yaml:"coverage,omitempty"` 68 DASTConfiguration *DASTConfiguration `yaml:"dast_configuration,omitempty"` 69 Dependencies Stringorslice `yaml:"dependencies,omitempty"` 70 Environment *Environment `yaml:"environment,omitempty"` 71 Except *Conditions `yaml:"except,omitempty"` 72 Extends Stringorslice `yaml:"extends,omitempty"` 73 Hooks map[string]Stringorslice `yaml:"hooks,omitempty"` 74 IDTokens map[string]*IDToken `yaml:"id_tokens,omitempty"` 75 Image *Image `yaml:"image,omitempty"` 76 Inherit *Inherit `yaml:"inherit,omitempty"` 77 Interruptible bool `yaml:"interruptible,omitempty"` 78 Needs *Needs `yaml:"needs,omitempty"` 79 Only *Conditions `yaml:"only,omitempty"` 80 Pages *Job `yaml:"pages,omitempty"` 81 Parallel *Parallel `yaml:"parallel,omitempty"` 82 Publish string `yaml:"publish,omitempty"` 83 Release *Release `yaml:"release,omitempty"` 84 ResourceGroup string `yaml:"resource_group,omitempty"` 85 Retry *Retry `yaml:"retry,omitempty"` 86 Rules []*Rule `yaml:"rules,omitempty"` 87 Script Stringorslice `yaml:"script,omitempty"` 88 Secrets map[string]*Secret `yaml:"secrets,omitempty"` 89 Services []*Image `yaml:"services,omitempty"` 90 Stage string `yaml:"stage,omitempty"` 91 Tags Stringorslice `yaml:"tags,omitempty"` 92 Timeout string `yaml:"timeout,omitempty"` 93 Trigger *Trigger `yaml:"trigger,omitempty"` 94 Variables map[string]*Variable `yaml:"variables,omitempty"` 95 When string `yaml:"when,omitempty"` // on_success, manual, always, on_failure, delayed, never 96 }{} 97 98 if err := unmarshal(&out1); err == nil { 99 v.Script = out1 100 return nil 101 } 102 103 if err := unmarshal(&out2); err == nil { 104 *v = out2 105 return nil 106 } 107 108 return errors.New("failed to unmarshal job") 109 } 110 111 type DASTConfiguration struct { 112 SiteProfile string `yaml:"site_profile,omitempty"` 113 ScannerProfile string `yaml:"scanner_profile,omitempty"` 114 } 115 116 type IDToken struct { 117 Aud interface{} `yaml:"aud"` 118 }