github.com/q2/git-lfs@v0.5.1-0.20150410234700-03a0d4cec40e/script/release.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"flag"
     6  	"fmt"
     7  	"net/url"
     8  	"os"
     9  	"os/exec"
    10  	"strings"
    11  )
    12  
    13  var (
    14  	ReleaseId    = flag.Int("id", 0, "github/git-lfs Release ID")
    15  	uploadUrlFmt = "https://uploads.github.com/repos/github/git-lfs/releases/%d/assets?%s"
    16  )
    17  
    18  func mainRelease() {
    19  	if *ReleaseId < 1 {
    20  		fmt.Println("Need a valid github/git-lfs release id.")
    21  		fmt.Println("usage: script/release -id")
    22  		os.Exit(1)
    23  	}
    24  
    25  	file, err := os.Open("bin/releases/build_matrix.json")
    26  	if err != nil {
    27  		fmt.Println("Error opening build_matrix.json:", err)
    28  		fmt.Println("Ensure `script/bootstrap -all` has completed successfully")
    29  		os.Exit(1)
    30  	}
    31  
    32  	defer file.Close()
    33  
    34  	buildMatrix := make(map[string]Release)
    35  	if err := json.NewDecoder(file).Decode(&buildMatrix); err != nil {
    36  		fmt.Println("Error reading build_matrix.json:", err)
    37  		os.Exit(1)
    38  	}
    39  
    40  	for _, rel := range buildMatrix {
    41  		release(rel)
    42  		fmt.Println()
    43  	}
    44  }
    45  
    46  func release(rel Release) {
    47  	query := url.Values{}
    48  	query.Add("name", rel.Filename)
    49  	query.Add("label", rel.Label)
    50  
    51  	args := []string{
    52  		"-in",
    53  		"-H", "Content-Type: application/octet-stream",
    54  		"-X", "POST",
    55  		"--data-binary", "@bin/releases/" + rel.Filename,
    56  		fmt.Sprintf(uploadUrlFmt, *ReleaseId, query.Encode()),
    57  	}
    58  
    59  	fmt.Println("curl", strings.Join(args, " "))
    60  
    61  	cmd := exec.Command("curl", args...)
    62  
    63  	by, err := cmd.Output()
    64  	if err != nil {
    65  		fmt.Println("Error running curl:", err)
    66  		os.Exit(1)
    67  	}
    68  
    69  	fmt.Println(string(by))
    70  }