github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/circle/internal/orbs/codecov/codecov.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 codecov
    16  
    17  import (
    18  	"fmt"
    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  func Convert(command string, step *circle.Custom) *harness.Step {
    27  	switch command {
    28  	case "upload":
    29  		return convertUpload(step)
    30  	default:
    31  		return nil
    32  	}
    33  }
    34  
    35  func convertUpload(step *circle.Custom) *harness.Step {
    36  	token := ""
    37  	if s, _ := step.Params["token"].(string); s != "" {
    38  		token = s
    39  	}
    40  	name := "$DRONE_BUILD_NUMBER"
    41  	if s, _ := step.Params["upload_name"].(string); s != "" {
    42  		name = s
    43  	}
    44  
    45  	parts := []string{
    46  		"curl -Os https://uploader.codecov.io/latest/linux/codecov",
    47  		"chmod +x codecov",
    48  		fmt.Sprintf("./codecov -t %s -n %s", token, name),
    49  	}
    50  
    51  	return &harness.Step{
    52  		Name: "codecov",
    53  		Type: "script",
    54  		Spec: &harness.StepExec{
    55  			Run: strings.Join(parts, "\n"),
    56  		},
    57  	}
    58  }