github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/travis/image.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 travis 16 17 import "strings" 18 19 func convertImageMaybe(ctx *context, ok bool) (image string) { 20 if ok { 21 return convertImage(ctx) 22 } else { 23 return 24 } 25 } 26 27 func convertImage(ctx *context) string { 28 switch strings.ToLower(ctx.config.Language) { 29 case "android": 30 // TODO android image 31 return "cimg/android" 32 case "c": 33 return convertImageC(ctx) 34 case "clojure": 35 return convertImageClojure(ctx) 36 case "cpp": 37 return convertImageC(ctx) 38 case "crystal": 39 return convertImageCrystal(ctx) 40 case "csharp": 41 // TODO csharp image 42 case "d": 43 // TODO dlang image 44 case "dart": 45 // TODO dart image 46 return "dart" 47 case "elixir": 48 // TODO elixir image 49 return "elixir" 50 case "elm": 51 // TODO elm image 52 case "erlang": 53 return convertImageErlang(ctx) 54 case "go": 55 return convertImageGo(ctx) 56 case "groovy": 57 // TODO groovy image 58 return "groovy" 59 case "hack": 60 // TODO hack image 61 case "haskell": 62 // TODO haskell image 63 case "haxe": 64 // TODO haxe image 65 return "haxe" 66 case "java": 67 // TODO java image 68 return "java" 69 case "julia": 70 // TODO julia image 71 return "julia" 72 case "nix": 73 // TODO nix image 74 return "nixos/nix" 75 case "node_js": 76 return convertImageNode(ctx) 77 case "objective-c": 78 return "" // no docker image for objective c 79 case "perl": 80 // TODO perl image 81 return "perl" 82 case "perl6": 83 // TODO perl image 84 return "perl" 85 case "php": 86 // TODO php image 87 return "php" 88 case "python": 89 return convertImagePy(ctx) 90 case "r": 91 // TODO r image 92 return "r-base" 93 case "ruby": 94 // TODO ruby image 95 return "ruby" 96 case "rust": 97 return convertImageRust(ctx) 98 case "scala": 99 // TODO scala image 100 case "smalltalk": 101 // TODO smalltalk image 102 case "minimal", "generic", "shell": 103 return "ubuntu" 104 } 105 return "ubuntu" 106 } 107 108 func convertImageC(ctx *context) string { 109 if len(ctx.config.Compiler) == 0 { 110 return "gcc" 111 } 112 if len(ctx.config.Compiler) == 1 { 113 switch ctx.config.Compiler[0] { 114 case "gcc": 115 return "gcc" 116 case "clang": 117 return "silkeh/clang" 118 } 119 } 120 return "gcc" // TODO strategy to convert C matrix to image 121 } 122 123 func convertImageCrystal(ctx *context) string { 124 if len(ctx.config.Crystal) == 0 { 125 return "crystallang/crystal" 126 } 127 if len(ctx.config.Crystal) == 1 { 128 version := ctx.config.Python[0] 129 if version == "nightly" { 130 version = "latest" 131 } 132 return "crystallang/crystal:" + version 133 } 134 return "crystallang/crystal:<+matrix.crystal>" 135 } 136 137 func convertImageClojure(ctx *context) string { 138 // TODO support for jdk version 139 // TODO support for lein version 140 return "clojure" 141 } 142 143 func convertImageErlang(ctx *context) string { 144 if len(ctx.config.ErlangOTP) == 0 { 145 return "erlang" 146 } 147 if len(ctx.config.ErlangOTP) == 1 { 148 version := ctx.config.ErlangOTP[0] 149 version = strings.ReplaceAll(version, ".x", "") 150 return "erlang:" + version 151 } 152 return "golang:<+matrix.otp_release>" 153 } 154 155 func convertImageGo(ctx *context) string { 156 if len(ctx.config.Go) == 0 { 157 return "golang" 158 } 159 if len(ctx.config.Go) == 1 { 160 return "golang:" + strings.ReplaceAll(ctx.config.Go[0], ".x", "") 161 } 162 return "golang:<+matrix.go>" 163 } 164 165 func convertImageNode(ctx *context) string { 166 if len(ctx.config.Node) == 0 { 167 return "node" 168 } 169 if len(ctx.config.Node) == 1 { 170 version := ctx.config.Node[0] 171 switch version { 172 case "lts/*": 173 version = "lts" 174 case "node": 175 version = "latest" 176 } 177 return "node:" + version 178 } 179 return "node:<+matrix.node_js>" 180 } 181 182 func convertImagePy(ctx *context) string { 183 if len(ctx.config.Python) == 0 { 184 return "python" 185 } 186 if len(ctx.config.Python) == 1 { 187 version := ctx.config.Python[0] 188 version = strings.TrimSuffix(version, "-dev") 189 if version == "nightly" { 190 version = "latest" 191 } 192 return "python:" + version 193 } 194 return "python:<+matrix.python>" 195 } 196 197 func convertImageRust(ctx *context) string { 198 if len(ctx.config.Rust) == 0 { 199 return "rust" 200 } 201 if len(ctx.config.Rust) == 1 { 202 version := ctx.config.Rust[0] 203 switch version { 204 case "stable": 205 version = "1" 206 case "beta": 207 version = "latest" 208 case "nightly": 209 version = "latest" 210 } 211 return "rust:" + version 212 } 213 return "rust:<+matrix.rust>" 214 }