// Copyright 2020 the Drone Authors. All rights reserved. // Use of this source code is governed by the Blue Oak Model License // that can be found in the LICENSE file. package plugin import ( "encoding/base64" "encoding/json" "fmt" "io" "os" "os/exec" ) func getLatestGitTag() (string, error) { tag, err := exec.Command("git", "describe", "--tags", "--abbrev=0").Output() if err != nil { return "", fmt.Errorf("error getting git tag %w", err) } return string(tag), err } func writeCard(path, schema string, card interface{}) { data, _ := json.Marshal(map[string]interface{}{ "schema": schema, "data": card, }) switch { case path == "/dev/stdout": writeCardTo(os.Stdout, data) case path == "/dev/stderr": writeCardTo(os.Stderr, data) case path != "": os.WriteFile(path, data, 0644) } } func writeCardTo(out io.Writer, data []byte) { encoded := base64.StdEncoding.EncodeToString(data) io.WriteString(out, "\u001B]1338;") io.WriteString(out, encoded) io.WriteString(out, "\u001B]0m") io.WriteString(out, "\n") }