DEV Community

loading...

Deploying Go Applications to GitHub Releases with GoReleaser and Travis CI

Athul Cyriac
Originally published at blog.athulcyriac.co ・2 min read

Setting Up Goreleaser and Travis CI

All the installation Instructions of Gorelaser can be found in their Official Docs. I'm assuming you know how to set up Travis CI.

After Installing Goreleaser, you just have to cd to that go repository you want to deploy and run goreleaser init. This command will create a goreleaser.yml already filled with some commands and stuff.

You can add these to the bottom of the .gorealeaser.yml made by goreleaser init and it'll work fine.

Here is the Gorelaser part to Deploy the Application to GitHub Relases

release:
  github:
    owner: <username>
    name: <repo>

For Deploying to GitHub Releases change your .travis.yml file like this

deploy:
- provider: script
  skip_cleanup: true
  script: curl -sL https://git.io/goreleaser | bash
  on:
    tags: true

This will only deploy to GitHub releases when a tag is created and pushed. You will need a GitHub Token in the Repo scope and while adding it to Travis Secrets you must name it like GITHUB_TOKEN only.


Some tips before pushing a tags for checking Goreleaser.

You can always try goreleaser in you the terminal.

  • Try goreleaser release --skip-publish command and you can always test with this before you push to GitHub. I'd totally suggest this since I had simply pushed without any testing and I had to write the whole thing...again.

GoDownloader

You can install godownloader from their releases page. Follow the next steps to use it Globally

$ tar -xvf <filename>.tar.gz
$ mv godownloader /usr/local/bin/

Now go to your working folder and run

$ godownloader --repo=<user>/<repo> > godownloader.sh

This will make a godownlaoder.sh file which can be used as an installation script.


Here are my Pipelines for Shelby

  • .travis.yml
sudo: false
language: go

go:
  - "1.13"
before_script:
  - go get -v
  - go build
  - rm -rf shelby
#
# before we deploy, we go build for all operating systems we would like to support
deploy:
- provider: script
  skip_cleanup: true
  script: curl -sL https://git.io/goreleaser | bash
  on:
    tags: true
  • .goreleaser.yml

before:
  hooks:
    # you may remove this if you don't use vgo
    - go mod tidy
    # you may remove this if you don't need go generate
    - go get -v 
builds:
- 

  env:
    - CGO_ENABLED=0
  ldflags:
    - -s -w 
  goos:
    - darwin
    - linux
  goarch:
    - amd64
archives:
- replacements:
    darwin: Darwin
    linux: Linux
    amd64: x86_64
checksum:
  name_template: 'checksums.txt'
snapshot:
  name_template: "{{ .Tag }}"
changelog:
  sort: asc
  filters:
    exclude:
    - '^docs:'
    - '^test:'
release:
  github:
    owner: athul
    name: shelby

Discussion (2)

Collapse
davidpfarrell profile image
David Farrell

Hey !! Soo thinking I might be the inspiration for this post? re our discussion here:

reddit.com/r/golang/comments/eidfb...

Thanks for the info there (and here) - It convinced me to look into it and since your reply on reddit I’ve already used goreleaser on one of my projects !!

Collapse
athulcajay profile image
Athul Cyriac Author • Edited

Glad you found it helpful. I thought I was the only one with the confused docs. They you came up. So I wrote this up. Thank You ❤️