Kaynağa Gözat

goreleaser test

Alexander Belanger 5 yıl önce
ebeveyn
işleme
8116a56429
3 değiştirilmiş dosya ile 52 ekleme ve 32 silme
  1. 14 14
      .darwin.goreleaser.yml
  2. 13 13
      .goreleaser.yml
  3. 25 5
      cli/cmd/github/release.go

+ 14 - 14
.darwin.goreleaser.yml

@@ -2,20 +2,20 @@ before:
   hooks:
     - go mod download
 builds:
-  - id: "porter-cli"
-    binary: porter
-    env:
-      - CGO_ENABLED=1
-    dir: cli
-    main: ./main.go
-    goos:
-      - darwin
-    goarch:
-      - amd64
-    flags:
-      - -tags=cli
-    hooks:
-      post: gon gon.cli.hcl
+  # - id: "porter-cli"
+  #   binary: porter
+  #   env:
+  #     - CGO_ENABLED=1
+  #   dir: cli
+  #   main: ./main.go
+  #   goos:
+  #     - darwin
+  #   goarch:
+  #     - amd64
+  #   flags:
+  #     - -tags=cli
+  #   hooks:
+  #     post: gon gon.cli.hcl
   - id: "porter-server"
     binary: portersvr
     env:

+ 13 - 13
.goreleaser.yml

@@ -2,19 +2,19 @@ before:
   hooks:
     - go mod download
 builds:
-  - id: "porter-cli"
-    binary: porter
-    env:
-      - CGO_ENABLED=1
-    dir: cli
-    main: ./main.go
-    goos:
-      - linux
-      - windows
-    goarch:
-      - amd64
-    flags:
-      - -tags=cli
+  # - id: "porter-cli"
+  #   binary: porter
+  #   env:
+  #     - CGO_ENABLED=1
+  #   dir: cli
+  #   main: ./main.go
+  #   goos:
+  #     - linux
+  #     - windows
+  #   goarch:
+  #     - amd64
+  #   flags:
+  #     - -tags=cli
   - id: "porter-server"
     binary: portersvr
     env:

+ 25 - 5
cli/cmd/github/release.go

@@ -15,13 +15,13 @@ import (
 	"github.com/google/go-github/github"
 )
 
-func getLatestReleaseDownloadURL() (string, error) {
+func getLatestReleaseDownloadURL() (string, string, error) {
 	client := github.NewClient(nil)
 
 	rel, _, err := client.Repositories.GetLatestRelease(context.Background(), "porter-dev", "porter")
 
 	if err != nil {
-		return "", err
+		return "", "", err
 	}
 
 	var re *regexp.Regexp
@@ -35,23 +35,27 @@ func getLatestReleaseDownloadURL() (string, error) {
 		fmt.Printf("%s.\n", os)
 	}
 
+	staticRE := regexp.MustCompile(`static_.*\.zip`)
+
 	releaseURL := ""
+	staticReleaseURL := ""
 
 	// iterate through the assets
 	for _, asset := range rel.Assets {
 		if downloadURL := asset.GetBrowserDownloadURL(); re.MatchString(downloadURL) {
 			releaseURL = downloadURL
-			break
+		} else if staticRE.MatchString(downloadURL) {
+			staticReleaseURL = downloadURL
 		}
 	}
 
-	return releaseURL, nil
+	return releaseURL, staticReleaseURL, nil
 }
 
 // DownloadLatestServerRelease retrieves the latest Porter server release from Github, unzips
 // it, and adds the binary to the porter directory
 func DownloadLatestServerRelease(porterDir string) error {
-	releaseURL, err := getLatestReleaseDownloadURL()
+	releaseURL, staticReleaseURL, err := getLatestReleaseDownloadURL()
 	fmt.Println(releaseURL)
 
 	if err != nil {
@@ -68,6 +72,22 @@ func DownloadLatestServerRelease(porterDir string) error {
 
 	err = unzipToDir(zipFile, porterDir)
 
+	if err != nil {
+		return err
+	}
+
+	staticZipFile := filepath.Join(porterDir, "static_latest.zip")
+
+	err = downloadToFile(staticReleaseURL, staticZipFile)
+
+	if err != nil {
+		return err
+	}
+
+	staticDir := filepath.Join(porterDir, "static")
+
+	err = unzipToDir(staticZipFile, staticDir)
+
 	return err
 }