How to make a goreleaser script to build a deb file locally?

2.7k views Asked by At

I am an absolute novice in Golang but I want to modify a Go build script to build a file locally only instead of publishing it to GitHub.

https://github.com/dahendel/docker-machine-driver-cloudstack/blob/master/.goreleaser.yml

How to proceed?

1

There are 1 answers

0
Dimas Prawira On BEST ANSWER

I have cloned your repo and try that in my local machine. Here is the steps :

  1. Git clone

  2. executing Dry run (testing everything before doing a release "for real" :

    $ goreleaser release --skip-publish
    
  3. show there is no error

• SIGNING ARTIFACTS
   • pipe skipped              error=artifact signing is disabled
• DOCKER IMAGES
   • pipe skipped              error=docker section is not configured
• PUBLISHING
   • pipe skipped              error=publishing is disabled
• release succeeded after 20.75s
  1. execute goreleaser for release

    $ goreleaser release
    
  2. goreleaser will created dist folder inside project and this folder will consist of distribution packages (deb, rpm).

I have encounter some issues and here is what I do

  • error=missing GITHUB_TOKEN, GITLAB_TOKEN and GITEA_TOKEN

create github or gitlab token ( https://github.com/settings/tokens) and put it as environment variable

export GITHUB_TOKEN=xxxxyyyyyzzzzz

resolve the issue.

  • pre hook failed: xxxx is not within a known GOPATH/src

as I see in your goreleaser.yaml

hooks:
pre: dep ensure

you're using dep ensure, checking $GOPATH and make sure $GOPATH pointing to right path of your Go project.

  • error=dist is not empty, remove it before running goreleaser or use the --rm-dist flag

dist folder has been created before, you can either manually delete the folder or add flags --rm-dist when executing goreleaser command

$ goreleaser release --skip-publish --rm-dist
  • error=nfpm failed: rpmbuild not present in $PATH

this error occured as I was running on mac machine so there is no rpmbuild installed, installing rpm, rpmbuild solve the issue

$ brew install rpm
  • error=git is currently in a dirty state, please check in your pipeline what can be changing the following files: M Gopkg.lock

Goreleaser seems to check file diff, so as because running hook (dep ensure) updating the Gopkg.lock and this changes/updates are not pushed to git. The solution is always pushing the changes to git.

  • error=git tag v1.0.5 was not made against commit 3ae83eebd904d33cc549117254e857ebea04df90

reading from GoReleaser documentation which is "GoReleaser enforces semantic versioning and will error on non-compliant tags. Your tag should be a valid semantic version. If it is not, GoReleaser will error."

after pushing to git, make sure you have to update the tags, in this case I updates the tags to v1.0.6 (previously v1.0.5).

  • error=GitHub/GitLab/Gitea Releases: failed to publish artifacts POST http://xxxyyyzzz/releases: 404 Not Found []

make sure release text is there.

Hope that helps