added with out hardcode depth
This commit is contained in:
parent
5bd2a3cee1
commit
25266560d2
@ -22,6 +22,10 @@ inputs:
|
||||
checkoutType:
|
||||
description: 'Type of checkout to use. Supported: `https`, `ssh`'
|
||||
required: true
|
||||
fetchDepth:
|
||||
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
|
||||
required: false
|
||||
default: 1
|
||||
|
||||
runs:
|
||||
using: 'go'
|
||||
|
@ -15,6 +15,7 @@ type Config struct {
|
||||
Path string
|
||||
ServerURL string
|
||||
CheckoutType CheckoutType
|
||||
FetchDepth string
|
||||
}
|
||||
|
||||
type CheckoutType string
|
||||
@ -25,6 +26,10 @@ const (
|
||||
)
|
||||
|
||||
func getConfig() Config {
|
||||
fetchDepth := os.Getenv("INPUT_FETCHDEPTH")
|
||||
if fetchDepth == "" || fetchDepth == "0" {
|
||||
fetchDepth = "1"
|
||||
}
|
||||
return Config{
|
||||
Repository: os.Getenv("INPUT_REPOSITORY"),
|
||||
Ref: os.Getenv("INPUT_REF"),
|
||||
@ -32,6 +37,7 @@ func getConfig() Config {
|
||||
Path: os.Getenv("INPUT_PATH"),
|
||||
ServerURL: os.Getenv("INPUT_SERVERURL"),
|
||||
CheckoutType: CheckoutType(os.Getenv("INPUT_CHECKOUTTYPE")),
|
||||
FetchDepth: fetchDepth,
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,11 +60,11 @@ func main() {
|
||||
cloneURL := cfg.CheckoutType.GenerateCloneURL(cfg)
|
||||
|
||||
fmt.Println("Cloning", cloneURL, "into", cfg.Path)
|
||||
run("git", "clone", "--depth=1", cloneURL, cfg.Path)
|
||||
run("git", "clone", fmt.Sprintf("--depth=%s", cfg.FetchDepth), cloneURL, cfg.Path)
|
||||
|
||||
if cfg.Ref != "" {
|
||||
fmt.Println("Checking out", cfg.Ref)
|
||||
run("git", "-C", cfg.Path, "fetch", "--depth=1", "origin", cfg.Ref)
|
||||
run("git", "-C", cfg.Path, "fetch", fmt.Sprintf("--depth=%s", cfg.FetchDepth), "origin", cfg.Ref)
|
||||
run("git", "-C", cfg.Path, "checkout", "FETCH_HEAD")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user