Skip to content

Commit

Permalink
Fix INPUT_* handling
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
  • Loading branch information
ArangoGutierrez committed Aug 1, 2024
1 parent 4bff1d0 commit 8728ee6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
38 changes: 38 additions & 0 deletions cmd/action/ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ const (
func Run(log *logger.FunLogger) error {
log.Info("Holodeck Settting up test environment")

// Get GitHub Actions INPUT_* vars
err := readInputs()
if err != nil {
return err
}

if _, err := os.Stat(cachedir); err == nil {
if err := cleanup(log); err != nil {
return err
Expand All @@ -54,6 +60,38 @@ func Run(log *logger.FunLogger) error {
return nil
}

// readInputs reads GitHub Actions Inputs
// INPUT_* vars are optional since v0.2 of the action
// Users can set the variables on self hosted runners.
func readInputs() error {
// Get INPUT_AWS_SSH_KEY to set AWS_SSH_KEY
sshKey := os.Getenv("INPUT_AWS_SSH_KEY")
if sshKey != "" {
err := os.Setenv("AWS_SSH_KEY", sshKey)
if err != nil {
return fmt.Errorf("failed to set AWS_SSH_KEY: %v", err)
}
}
// Map INPUT_AWS_ACCESS_KEY_ID and INPUT_AWS_SECRET_ACCESS_KEY
// to AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
accessKeyID := os.Getenv("INPUT_AWS_ACCESS_KEY_ID")
if accessKeyID != "" {
err := os.Setenv("AWS_ACCESS_KEY_ID", accessKeyID)
if err != nil {
return fmt.Errorf("failed to set AWS_ACCESS_KEY_ID: %v", err)
}
}
secretAccessKey := os.Getenv("INPUT_AWS_SECRET_ACCESS_KEY")
if secretAccessKey != "" {
err := os.Setenv("AWS_SECRET_ACCESS_KEY", secretAccessKey)
if err != nil {
return fmt.Errorf("failed to set AWS_SECRET_ACCESS_KEY: %v", err)
}
}

return nil
}

func setCfgName(cfg *v1alpha1.Environment) {
sha := os.Getenv("GITHUB_SHA")
attempt := os.Getenv("GITHUB_RUN_ATTEMPT")
Expand Down
28 changes: 0 additions & 28 deletions cmd/action/ci/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,6 @@ func entrypoint(log *logger.FunLogger) error {
// Set default values for the environment
setCfgName(&cfg)

// Read Inputs
// INPUT_* vars are optional since v0.2 of the action
// Users can set the variables on self hosted runners.
// Get INPUT_AWS_SSH_KEY to set AWS_SSH_KEY
sshKey := os.Getenv("INPUT_AWS_SSH_KEY")
if sshKey != "" {
err := os.Setenv("AWS_SSH_KEY", sshKey)
if err != nil {
return fmt.Errorf("failed to set AWS_SSH_KEY: %v", err)
}
}
// Map INPUT_AWS_ACCESS_KEY_ID and INPUT_AWS_SECRET_ACCESS_KEY
// to AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
accessKeyID := os.Getenv("INPUT_AWS_ACCESS_KEY_ID")
if accessKeyID != "" {
err := os.Setenv("AWS_ACCESS_KEY_ID", accessKeyID)
if err != nil {
return fmt.Errorf("failed to set AWS_ACCESS_KEY_ID: %v", err)
}
}
secretAccessKey := os.Getenv("INPUT_AWS_SECRET_ACCESS_KEY")
if secretAccessKey != "" {
err := os.Setenv("AWS_SECRET_ACCESS_KEY", secretAccessKey)
if err != nil {
return fmt.Errorf("failed to set AWS_SECRET_ACCESS_KEY: %v", err)
}
}

provider, err := newProvider(log, &cfg)
if err != nil {
return fmt.Errorf("failed to create provider: %v", err)
Expand Down

0 comments on commit 8728ee6

Please sign in to comment.