From f9f2ef02ac56a81953a09c2beef5e028a1685763 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Tue, 16 Jun 2020 20:33:59 -0400 Subject: [PATCH] Edit nightly release instead of replacing --- tools/nightly-release.sh | 9 ++++---- tools/remove-nightly-assets.go | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 tools/remove-nightly-assets.go diff --git a/tools/nightly-release.sh b/tools/nightly-release.sh index 33fe1a5d..3a22c245 100755 --- a/tools/nightly-release.sh +++ b/tools/nightly-release.sh @@ -9,8 +9,7 @@ if [[ $info = *$commitID* ]]; then exit 1 fi -echo "Deleting old release" -hub release delete nightly +go run remove-nightly-assets.go echo "Moving tag" hub push origin :refs/tags/nightly @@ -21,10 +20,12 @@ echo "Cross compiling binaries" ./cross-compile.sh $1 mv ../binaries . +MESSAGE=$'Nightly build\n\nAutogenerated nightly build of micro' + echo "Creating new release" -hub release create nightly \ +hub release edit nightly \ --prerelease \ - --message $'Nightly build\n\nAutogenerated nightly build of micro.' \ + --message "$MESSAGE. Assets uploaded on $(date)" \ --attach "binaries/micro-$1-osx.tar.gz" \ --attach "binaries/micro-$1-linux64.tar.gz" \ --attach "binaries/micro-$1-linux64-static.tar.gz" \ diff --git a/tools/remove-nightly-assets.go b/tools/remove-nightly-assets.go new file mode 100644 index 00000000..0d7fb48e --- /dev/null +++ b/tools/remove-nightly-assets.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "io/ioutil" + "net/http" + "os/exec" + "strings" + + "github.com/zyedidia/json5" +) + +func main() { + resp, err := http.Get("https://api.github.com/repos/zyedidia/micro/releases") + if err != nil { + fmt.Println(err.Error()) + return + } + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + + var data interface{} + + err = json5.Unmarshal(body, &data) + + for _, val := range data.([]interface{}) { + m := val.(map[string]interface{}) + releaseName := m["name"].(string) + assets := m["assets"].([]interface{}) + for _, asset := range assets { + assetInfo := asset.(map[string]interface{}) + url := assetInfo["url"].(string) + if strings.Contains(strings.ToLower(releaseName), "nightly") { + cmd := exec.Command("hub", "api", "-X", "DELETE", url) + cmd.Run() + } + } + } +}