Skip to content

Commit

Permalink
Merge pull request #30 from NVIDIA/ghaction
Browse files Browse the repository at this point in the history
Fix key handling again
  • Loading branch information
ArangoGutierrez authored Mar 5, 2024
2 parents f28386e + d5228d8 commit 49a69cc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 3 additions & 5 deletions cmd/action/ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ const (
cachedir = "/github/workspace/.cache"
cacheFile = "/github/workspace/.cache/holodeck.yaml"
kubeconfig = "/github/workspace/kubeconfig"
sshKeyFile = "/github/workspace/.cache/key"
sshKeyFile = "/github/workspace/.cache/key.pem"
// Default EC2 instance UserName for ubuntu AMI's
username = "ubuntu"
)

func Run(log *logger.FunLogger) error {
log.Info("Running Holodeck function")
// Check if .cache folder exists in the /github/workspace directory and if it does, call cleanup function
// If it doesn't, call entrypoint function
// If the entrypoint function returns an error, call cleanup function
log.Info("Holodeck Settting up test environment")

if _, err := os.Stat(cachedir); err == nil {
if err := cleanup(log); err != nil {
return err
Expand Down
13 changes: 9 additions & 4 deletions cmd/action/ci/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ func cleanup(log *logger.FunLogger) error {
}

// Delete the cache kubeconfig and ssh key
if err := os.Remove(kubeconfig); err != nil {
log.Error(fmt.Errorf("error deleting kubeconfig: %s", err))
// if kubeconfig exists, delete it
if _, err := os.Stat(kubeconfig); err == nil {
if err := os.Remove(kubeconfig); err != nil {
log.Error(fmt.Errorf("error deleting kubeconfig: %s", err))
}
}

if err := os.Remove(sshKeyFile); err != nil {
log.Error(fmt.Errorf("error deleting ssh key: %s", err))
if _, err := os.Stat(sshKeyFile); err == nil {
if err := os.Remove(sshKeyFile); err != nil {
log.Error(fmt.Errorf("error deleting ssh key: %s", err))
}
}

if err := os.RemoveAll(cachedir); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions cmd/action/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ func main() {
os.Exit(1)
}

// Exit with success
// https://docs.github.com/en/actions/creating-actions/setting-exit-codes-for-actions
os.Exit(0)
}

0 comments on commit 49a69cc

Please sign in to comment.