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

    View full-size slide

  2. GoͷCLIπʔϧͷΞοϓσʔτͲ
    ͏ͯ͠·͔͢ʁ
    • go get -u
    • γεςϜͷύοέʔδϚωʔδϟʢbrew ͳ
    ͲʣΛ࢖͏
    • GitHub ͷϦϦʔεϖʔδ͔Β࠷৽൛Λμ΢ϯ
    ϩʔυ͢Δ

    View full-size slide

  3. go get -u

    ϦϦʔε͢Δඞཁͳָͯ͘ʢϝϯςφʣ
    • ৗʹϦϙδτϦͷ HEAD ΛϏϧυ͢ΔͷͰ
    unstableʢϢʔβʣ
    • Go ͷ։ൃ؀ڥͷΠϯετʔϧ͕ඞཁʢϢʔ
    βʣ

    View full-size slide

  4. γεςϜͷύοέʔδϚωʔδϟ
    ʢbrewͳͲʣΛ࢖͏

    ࠷৽ͷ stable ൛ΛָʹೖΕΒΕΔʢϢʔβʣ
    • OSʹΑͬͯ΍Γํ͕ҧ͏ʢϢʔβ&ϝϯς
    φʣ
    • ύοέʔδొ࿥͕େมʢϝϯςφʣ

    View full-size slide

  5. GitHub ͷϦϦʔεϖʔδ͔Β࠷
    ৽൛Λμ΢ϯϩʔυ͢Δ

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

    View full-size slide

  6. ͲΕ΋Ұ௕Ұ୹

    View full-size slide

  7. GitHub ͷϦϦʔεϖʔδ͔Β࠷
    ৽൛Λμ΢ϯϩʔυ͢Δ

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


    खͰμ΢ϯϩʔυͯ͘͠Δͷ͕໘౗ʢϢʔβʣ
    ࣗಈԽͰ͖ΔͷͰ͸ʁ

    View full-size slide

  8. go-github-selfupdate
    όΠφϦΛࣗݾΞοϓσʔτ͢Δ࢓૊ΈΛఏڙ
    ͢ΔϥΠϒϥϦ
    https://github.com/rhysd/go-github-selfupdate

    View full-size slide

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

    View full-size slide

  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,
    )
    }
    }

    View full-size slide

  11. GitHub ͷϦϦʔεϖʔδ +
    go-github-selfupdate

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

    ίϚϯυҰൃͰࣗಈΞοϓσʔτʢϢʔβʣ

    View full-size slide

  12. go-github-selfupdate ৄࡉ
    • ✔ Linux, Windows, macOS Ͱ CI
    • ✔ ϓϥΠϕʔτϦϙδτϦରԠ
    • ✔ GitHub Enterprise ରԠ
    • ✔ ࣮ߦϑΝΠϧஔ͖׵ࣦ͑ഊ࣌ͷϩʔϧόοΫ
    • ✔ ѹॖܗࣜɿzip, tar, gzip, xzip

    View full-size slide

  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

    View full-size slide