mirror of
https://github.com/drone-plugins/github-actions
synced 2026-12-02 10:33:13 +01:00
When uses: is a full commit SHA, the action.yml clone treated it as a branch/tag and failed, leaving the Output tab empty even though the action ran. Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
// Copyright 2022 Harness Inc. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cloner
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// regular expressions to test whether or not a string is
|
|
// a sha1 or sha256 commit hash.
|
|
var (
|
|
sha1 = regexp.MustCompile("^([a-f0-9]{40})$")
|
|
sha256 = regexp.MustCompile("^([a-f0-9]{64})$")
|
|
semver = regexp.MustCompile(`^v?((([0-9]+)(?:\.([0-9]+))?(?:\.([0-9]+))?(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$`)
|
|
)
|
|
|
|
// IsHash returns true if the string is a sha1 or sha256 commit hash.
|
|
func IsHash(s string) bool {
|
|
return sha1.MatchString(s) || sha256.MatchString(s)
|
|
}
|
|
|
|
// helper function returns the branch name expanded to the
|
|
// fully qualified reference path (e.g refs/heads/master).
|
|
func expandRef(name string) string {
|
|
if strings.HasPrefix(name, "refs/") {
|
|
return name
|
|
}
|
|
if semver.MatchString(name) {
|
|
return "refs/tags/" + name
|
|
}
|
|
return "refs/heads/" + name
|
|
}
|