Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?
@ynozue

GoReleaser と Travis CI を連携してみる #golang

More than 3 years have passed since last update.

前回の記事(goreleaser を使って Github Releases へ簡単デプロイ)で紹介した GoReleaser が便利だったので、Git の tag を push したタイミングで、GitHub Release に自動(Travis CI)でデプロイされるようにしてみました。

GoReleaser と Travis CI を連携

イメージ

goreleaser.png
※ GitHub と Travis CI がどういう仕組みで動いてるかあまり詳しくなかったので適当にイメージして描いてます

Travis CI の設定に GoReleaser を追加

以下、変更点になります。

  • install する際に goreleaser を追加
  • script が成功した場合に goreleaser を実行
.travis.yml
language: go

install:
 - go get -u golang.org/x/tools/cmd/goimports
 - go get -u github.com/golang/lint/golint
 - go get -u github.com/goreleaser/goreleaser

script:
 - go vet ./...
 - diff <(goimports -d .) <(printf "")
 - diff <(golint ./...) <(printf "")
 - go test .

after_success:
 - goreleaser

tag を push

$ git tag v1.0.2
$ git push --tags
Total 0 (delta 0), reused 0 (delta 0)
To github.com:ynozue/apichecker.git
 * [new tag]         v1.0.2 -> v1.0.2

https://travis-ci.org/ の実行ログを見るといい感じで実行されていました。

$ go get -u golang.org/x/tools/cmd/goimports
$ go get -u github.com/golang/lint/golint
$ go get -u github.com/goreleaser/goreleaser
$ go vet ./...
The command "go vet ./..." exited with 0.
0.01s$ diff <(goimports -d .) <(printf "")
The command "diff <(goimports -d .) <(printf "")" exited with 0.
0.03s$ diff <(golint ./...) <(printf "")
The command "diff <(golint ./...) <(printf "")" exited with 0.
3.62s$ go test .
ok      github.com/ynozue/apichecker    3.186s
The command "go test ." exited with 0.
after_success
$ goreleaser
   • running goreleaser dev   
   • loading config file       file=.goreleaser.yml
   • SETTING DEFAULTS 
   • GETTING AND VALIDATING GIT STATE
   • releasing v1.0.2, commit dc485a54a76189a106a154a85d8b5999cfdb61e5
   • GENERATING CHANGELOG
   • LOADING ENVIRONMENT VARIABLES
   • CHECKING ./DIST  
   • BUILDING BINARIES
   • building                  binary=dist/apichecker_1.0.2_linux_amd64/apichecker
   • building                  binary=dist/apichecker_1.0.2_darwin_amd64/apichecker
   • building                  binary=dist/apichecker_1.0.2_windows_amd64/apichecker.exe
   • CREATING ARCHIVES
   • creating                  archive=dist/apichecker_1.0.2_windows_amd64.tar.gz
   • creating                  archive=dist/apichecker_1.0.2_linux_amd64.tar.gz
   • creating                  archive=dist/apichecker_1.0.2_darwin_amd64.tar.gz
   • new release artifact      artifact=apichecker_1.0.2_windows_amd64.tar.gz
   • new release artifact      artifact=apichecker_1.0.2_linux_amd64.tar.gz
   • new release artifact      artifact=apichecker_1.0.2_darwin_amd64.tar.gz
   • CREATING LINUX PACKAGES WITH FPM
   • skipped                   reason=no output formats configured
   • CREATING LINUX PACKAGES WITH SNAPCRAFT
   • skipped                   reason=no summary nor description were provided
   • CALCULATING CHECKSUMS
   • checksumming              file=apichecker_1.0.2_darwin_amd64.tar.gz
   • checksumming              file=apichecker_1.0.2_windows_amd64.tar.gz
   • checksumming              file=apichecker_1.0.2_linux_amd64.tar.gz
   • new release artifact      artifact=apichecker_1.0.2_checksums.txt
   • CREATING DOCKER IMAGES
   • skipped                   reason=docker section is not configured
   • RELEASING TO GITHUB
   • creating or updating release repo=ynozue/apichecker tag=v1.0.2
   • release updated           url=https://github.com/ynozue/apichecker/releases/tag/v1.0.2
   • uploading to release      file=dist/apichecker_1.0.2_checksums.txt name=apichecker_1.0.2_checksums.txt
   • uploading to release      file=dist/apichecker_1.0.2_linux_amd64.tar.gz name=apichecker_1.0.2_linux_amd64.tar.gz
   • uploading to release      file=dist/apichecker_1.0.2_windows_amd64.tar.gz name=apichecker_1.0.2_windows_amd64.tar.gz
   • uploading to release      file=dist/apichecker_1.0.2_darwin_amd64.tar.gz name=apichecker_1.0.2_darwin_amd64.tar.gz
   • CREATING HOMEBREW FORMULA
   • skipped                   reason=brew section is not configured
   • SUCCESS!         
Done. Your build exited with 0.

Git Releases にも問題なくデプロイされました。
Kobito.reIkQg.png

バイナリをタグを打つごとに自動的に作って Git Releases にデプロイされるのは便利ですね。

Appendix

1
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ynozue
会社でプログラミングすることが少なくなったので、趣味でプログラム組んでることが多いです。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
1
Help us understand the problem. What is going on with this article?