Pro Yearly is on sale from $80 to $50! »

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. go-selfupdate-github Ͱ πʔϧΛࣗݾΞοϓσʔτ͢Δ Go Con 2018 Spring LT @Linda_pp @rhysd

  2. GoͷCLIπʔϧͷΞοϓσʔτͲ ͏ͯ͠·͔͢ʁ • go get -u • γεςϜͷύοέʔδϚωʔδϟʢbrew ͳ ͲʣΛ࢖͏

    • GitHub ͷϦϦʔεϖʔδ͔Β࠷৽൛Λμ΢ϯ ϩʔυ͢Δ 
  3. go get -u • ϦϦʔε͢Δඞཁͳָͯ͘ʢϝϯςφʣ • ৗʹϦϙδτϦͷ HEAD ΛϏϧυ͢ΔͷͰ unstableʢϢʔβʣ

    • Go ͷ։ൃ؀ڥͷΠϯετʔϧ͕ඞཁʢϢʔ βʣ 
  4. γεςϜͷύοέʔδϚωʔδϟ ʢbrewͳͲʣΛ࢖͏ • ࠷৽ͷ stable ൛ΛָʹೖΕΒΕΔʢϢʔβʣ • OSʹΑͬͯ΍Γํ͕ҧ͏ʢϢʔβ&ϝϯς φʣ •

    ύοέʔδొ࿥͕େมʢϝϯςφʣ 
  5. GitHub ͷϦϦʔεϖʔδ͔Β࠷ ৽൛Λμ΢ϯϩʔυ͢Δ • ࠷৽ͷ stable ൛ΛೖΕΒΕΔʢϢʔβʣ • gox ΍

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

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

    ghr ͳͲͰ؆୯ϦϦʔεʢϝϯςφʣ • खͰμ΢ϯϩʔυͯ͘͠Δͷ͕໘౗ʢϢʔβʣ  • खͰμ΢ϯϩʔυͯ͘͠Δͷ͕໘౗ʢϢʔβʣ ࣗಈԽͰ͖ΔͷͰ͸ʁ
  8. go-github-selfupdate όΠφϦΛࣗݾΞοϓσʔτ͢Δ࢓૊ΈΛఏڙ ͢ΔϥΠϒϥϦ https://github.com/rhysd/go-github-selfupdate 

  9. go-github-selfupdate • GitHub ͷϦϦʔεϖʔδ͔Β࠷৽൛ͷόΠφ ϦΛࣗಈݕग़ʢsemver Λ૝ఆʣ • ϦϦʔεϖʔδ͔ΒόΠφϦΛࣗಈμ΢ϯϩʔ υʢ+ղౚʣ •

    ࣮ߦϑΝΠϧΛࣗಈஔ͖׵͑ 
  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, ) } }
  11. GitHub ͷϦϦʔεϖʔδ + go-github-selfupdate • ࠷৽ͷ stable ൛ΛೖΕΒΕΔʢϢʔβʣ • gox

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

    ✔ ϓϥΠϕʔτϦϙδτϦରԠ • ✔ GitHub Enterprise ରԠ • ✔ ࣮ߦϑΝΠϧஔ͖׵ࣦ͑ഊ࣌ͷϩʔϧόοΫ • ✔ ѹॖܗࣜɿzip, tar, gzip, xzip 
  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