Upgrade to Pro — share decks privately, control downloads, hide ads and more …

go-selfupdate-github で ツールを自己アップデートする

Linda_pp
April 15, 2018

go-selfupdate-github で ツールを自己アップデートする

GoCon 2018 Spring LT

Linda_pp

April 15, 2018
Tweet

More Decks by Linda_pp

Other Decks in Technology

Transcript

  1. GitHub ͷϦϦʔεϖʔδ͔Β࠷ ৽൛Λμ΢ϯϩʔυ͢Δ • ࠷৽ͷ stable ൛ΛೖΕΒΕΔʢϢʔβʣ • gox ΍

    ghr ͳͲͰ؆୯ϦϦʔεʢϝϯςφʣ • खͰμ΢ϯϩʔυͯ͘͠Δͷ͕໘౗ʢϢʔβʣ 
  2. GitHub ͷϦϦʔεϖʔδ͔Β࠷ ৽൛Λμ΢ϯϩʔυ͢Δ • ࠷৽ͷ stable ൛ΛೖΕΒΕΔʢϢʔβʣ • gox ΍

    ghr ͳͲͰ؆୯ϦϦʔεʢϝϯςφʣ • खͰμ΢ϯϩʔυͯ͘͠Δͷ͕໘౗ʢϢʔβʣ  • खͰμ΢ϯϩʔυͯ͘͠Δͷ͕໘౗ʢϢʔβʣ ࣗಈԽͰ͖ΔͷͰ͸ʁ
  3. import ( "log" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" ) const current = "1.2.3"

    func doSelfUpdate() { v := semver.MustParse(current) latest, err := selfupdate.UpdateSelf(v, "myname/myrepo") if err != nil { log.Panicln("Binary update failed:", err) } if latest.Version.Equals(v) { log.Println("Current binary is the latest", current) } else { log.Println( "Updated to", latest.Version, "Release note:\n", latest.ReleaseNotes, ) } }
  4. GitHub ͷϦϦʔεϖʔδ + go-github-selfupdate • ࠷৽ͷ stable ൛ΛೖΕΒΕΔʢϢʔβʣ • gox

    ΍ ghr ͳͲͰ؆୯ϦϦʔεʢϝϯςφʣ • खͰμ΢ϯϩʔυͯ͘͠Δͷ͕໘౗ʢϢʔβʣ • ίϚϯυҰൃͰࣗಈΞοϓσʔτʢϢʔβʣ 
  5. go-github-selfupdate ৄࡉ • ✔ Linux, Windows, macOS Ͱ CI •

    ✔ ϓϥΠϕʔτϦϙδτϦରԠ • ✔ GitHub Enterprise ରԠ • ✔ ࣮ߦϑΝΠϧஔ͖׵ࣦ͑ഊ࣌ͷϩʔϧόοΫ • ✔ ѹॖܗࣜɿzip, tar, gzip, xzip 
  6. ࢀߟϦϯΫ • ϦϙδτϦ: • https://github.com/rhysd/go-github-selfupdate • υΩϡϝϯτ: • https://godoc.org/github.com/rhysd/go-github-selfupdate/ selfupdate

    • ϥούʔϥΠϒϥϦ: • https://github.com/Songmu/ghselfupdate • ϒϩάهࣄ: • https://rhysd.hatenablog.com/entry/2017/12/30/220214  @Linda_pp @rhysd CZ