Skip to content

Commit

Permalink
feat: Update download and installation process for Copilot
Browse files Browse the repository at this point in the history
  • Loading branch information
rluisr committed Oct 20, 2023
1 parent a7f013f commit 1989551
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cenv
.copilot-version
21 changes: 6 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func readVersionFile() (string, error) {
}

func downloadAndInstallCopilot(version string, local bool) error {
url := fmt.Sprintf("https://github.com/aws/copilot-cli/releases/download/v%s/copilot-%s-%s", version, runtime.GOOS, runtime.GOARCH)
url := fmt.Sprintf("https://github.com/aws/copilot-cli/releases/download/v%s/copilot-%s-%s-v%s", version, runtime.GOOS, runtime.GOARCH, version)

resp, err := http.Get(url)
if err != nil {
Expand All @@ -57,12 +57,12 @@ func downloadAndInstallCopilot(version string, local bool) error {
if err != nil {
return err
}
installPath = fmt.Sprintf("%s/copilot", currentDir)
installPath = fmt.Sprintf("%s/copilot-%s", currentDir, runtime.GOOS)
} else {
installPath = "/usr/local/bin/copilot"
installPath = fmt.Sprintf("/usr/local/bin/copilot-%s", runtime.GOOS)
}

out, err := os.Create(installPath)
out, err := os.OpenFile(installPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0755)
if err != nil {
return err
}
Expand All @@ -73,24 +73,15 @@ func downloadAndInstallCopilot(version string, local bool) error {
return err
}

err = os.Chmod(installPath, 0755)
if err != nil {
return err
}

var cmd *exec.Cmd
if local {
cmd = exec.Command("./copilot", "-v")
} else {
cmd = exec.Command("copilot", "-v")
}
cmd := exec.Command(installPath, "-v")

output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to verify copilot installation: %w\nOutput: %s", err, output)
}

fmt.Println(string(output))
fmt.Printf("Copilot installed successfully to %s\n", installPath)

return nil
}

0 comments on commit 1989551

Please # to comment.