added checkout types https and ssh
This commit is contained in:
parent
934f62af0f
commit
5bd2a3cee1
@ -19,6 +19,9 @@ inputs:
|
|||||||
serverURL:
|
serverURL:
|
||||||
description: 'address of the unique server on which the company`s gitea server is running'
|
description: 'address of the unique server on which the company`s gitea server is running'
|
||||||
required: true
|
required: true
|
||||||
|
checkoutType:
|
||||||
|
description: 'Type of checkout to use. Supported: `https`, `ssh`'
|
||||||
|
required: true
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'go'
|
using: 'go'
|
||||||
|
@ -9,20 +9,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Repository string
|
Repository string
|
||||||
Ref string
|
Ref string
|
||||||
Token string
|
Token string
|
||||||
Path string
|
Path string
|
||||||
ServerURL string
|
ServerURL string
|
||||||
|
CheckoutType CheckoutType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CheckoutType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
HttpsType = "https"
|
||||||
|
SshType = "ssh"
|
||||||
|
)
|
||||||
|
|
||||||
func getConfig() Config {
|
func getConfig() Config {
|
||||||
return Config{
|
return Config{
|
||||||
Repository: os.Getenv("INPUT_REPOSITORY"),
|
Repository: os.Getenv("INPUT_REPOSITORY"),
|
||||||
Ref: os.Getenv("INPUT_REF"),
|
Ref: os.Getenv("INPUT_REF"),
|
||||||
Token: os.Getenv("INPUT_TOKEN"),
|
Token: os.Getenv("INPUT_TOKEN"),
|
||||||
Path: os.Getenv("INPUT_PATH"),
|
Path: os.Getenv("INPUT_PATH"),
|
||||||
ServerURL: os.Getenv("INPUT_SERVERURL"),
|
ServerURL: os.Getenv("INPUT_SERVERURL"),
|
||||||
|
CheckoutType: CheckoutType(os.Getenv("INPUT_CHECKOUTTYPE")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,9 +51,7 @@ func main() {
|
|||||||
log.Fatal("field serverURL is required")
|
log.Fatal("field serverURL is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
cloneURL := fmt.Sprintf("https://x-access-token:%s@%s/%s.git", cfg.Token,
|
cloneURL := cfg.CheckoutType.GenerateCloneURL(cfg)
|
||||||
strings.TrimPrefix(cfg.ServerURL, "https://"), cfg.Repository,
|
|
||||||
)
|
|
||||||
|
|
||||||
fmt.Println("Cloning", cloneURL, "into", cfg.Path)
|
fmt.Println("Cloning", cloneURL, "into", cfg.Path)
|
||||||
run("git", "clone", "--depth=1", cloneURL, cfg.Path)
|
run("git", "clone", "--depth=1", cloneURL, cfg.Path)
|
||||||
@ -64,3 +71,20 @@ func run(name string, args ...string) {
|
|||||||
log.Fatalf("Command failed: %s %s Error: %v", name, strings.Join(args, " "), err)
|
log.Fatalf("Command failed: %s %s Error: %v", name, strings.Join(args, " "), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t CheckoutType) GenerateCloneURL(cfg Config) string {
|
||||||
|
switch t {
|
||||||
|
case HttpsType:
|
||||||
|
return fmt.Sprintf("https://x-access-token:%s@%s/%s.git", cfg.Token,
|
||||||
|
strings.TrimPrefix(cfg.ServerURL, "https://"), cfg.Repository,
|
||||||
|
)
|
||||||
|
case SshType:
|
||||||
|
return fmt.Sprintf("git@%s:%s.git",
|
||||||
|
strings.TrimPrefix(cfg.ServerURL, "git@"),
|
||||||
|
cfg.Repository,
|
||||||
|
)
|
||||||
|
default:
|
||||||
|
log.Fatalf("Unknown checkout type: %s", t)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user