github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/circle/internal/orbs/coveralls/coveralls.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 coveralls 16 17 import ( 18 "bytes" 19 "strings" 20 21 circle "github.com/drone/go-convert/convert/circle/yaml" 22 harness "github.com/drone/spec/dist/go" 23 ) 24 25 // Convert converts an Orb to a Harness step. 26 // https://circleci.com/developer/orbs/orb/coveralls/coveralls 27 func Convert(command string, step *circle.Custom) *harness.Step { 28 switch command { 29 case "upload": 30 return convertUpload(step) 31 default: 32 return nil 33 } 34 } 35 36 func convertUpload(step *circle.Custom) *harness.Step { 37 var buf bytes.Buffer 38 buf.WriteString("./coveralls") 39 40 if b, _ := step.Params["verbose"].(bool); b == true { 41 buf.WriteString(" --debug") 42 } 43 44 if b, _ := step.Params["dry_run"].(bool); b == true { 45 buf.WriteString(" --dry-run") 46 } 47 48 if s, _ := step.Params["base_path"].(string); s != "" { 49 buf.WriteString(" --base-path " + s) 50 } 51 52 if s, _ := step.Params["coverage_format"].(string); s != "" { 53 buf.WriteString(" --format " + s) 54 } 55 56 if s, _ := step.Params["coverage_file"].(string); s != "" { 57 buf.WriteString(" --file " + s) 58 } 59 60 parts := []string{ 61 "curl -sLO https://github.com/coverallsapp/coverage-reporter/releases/latest/download/coveralls-linux.tar.gz", 62 "tar -xzf coveralls-linux.tar.gz", 63 buf.String(), 64 } 65 66 var token string 67 if s, _ := step.Params["token"].(string); s != "" { 68 token = s 69 } 70 71 return &harness.Step{ 72 Name: "coveralls", 73 Type: "script", 74 Spec: &harness.StepExec{ 75 Run: strings.Join(parts, "\n"), 76 Envs: map[string]string{ 77 "COVERALLS_REPO_TOKEN": token, 78 }, 79 }, 80 } 81 }