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

Dea1add99f4cf942792c0f185aa2f2fd?s=47 Linda_pp
April 15, 2018

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

GoCon 2018 Spring LT

Dea1add99f4cf942792c0f185aa2f2fd?s=128

Linda_pp

April 15, 2018
Tweet

Transcript

  1. 5.

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

    ghr ͳͲͰ؆୯ϦϦʔεʢϝϯςφʣ • खͰμ΢ϯϩʔυͯ͘͠Δͷ͕໘౗ʢϢʔβʣ 
  2. 7.

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

    ghr ͳͲͰ؆୯ϦϦʔεʢϝϯςφʣ • खͰμ΢ϯϩʔυͯ͘͠Δͷ͕໘౗ʢϢʔβʣ  • खͰμ΢ϯϩʔυͯ͘͠Δͷ͕໘౗ʢϢʔβʣ ࣗಈԽͰ͖ΔͷͰ͸ʁ
  3. 10.

    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. 11.

    GitHub ͷϦϦʔεϖʔδ + go-github-selfupdate • ࠷৽ͷ stable ൛ΛೖΕΒΕΔʢϢʔβʣ • gox

    ΍ ghr ͳͲͰ؆୯ϦϦʔεʢϝϯςφʣ • खͰμ΢ϯϩʔυͯ͘͠Δͷ͕໘౗ʢϢʔβʣ • ίϚϯυҰൃͰࣗಈΞοϓσʔτʢϢʔβʣ 
  5. 12.

    go-github-selfupdate ৄࡉ • ✔ Linux, Windows, macOS Ͱ CI •

    ✔ ϓϥΠϕʔτϦϙδτϦରԠ • ✔ GitHub Enterprise ରԠ • ✔ ࣮ߦϑΝΠϧஔ͖׵ࣦ͑ഊ࣌ͷϩʔϧόοΫ • ✔ ѹॖܗࣜɿzip, tar, gzip, xzip 
  6. 13.

    ࢀߟϦϯΫ • ϦϙδτϦ: • 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