Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set ldflags in snap build #529

Merged
merged 2 commits into from
Jul 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: doctl
version-script: scripts/version.sh
version: git
summary: A command line tool for DigitalOcean services
description: doctl is a command line tool for DigitalOcean services using the API.
Expand Down Expand Up @@ -33,7 +32,19 @@ parts:
override-pull: |
git clone https://github.com/digitalocean/doctl.git .
override-build: |
GO111MODULE=on go build -mod=vendor -o doctl cmd/doctl/main.go
version=$(scripts/version.sh)
snapcraftctl set-version ${version}

short=${version%+*}
short=${short%-*}
baseFlag="-X github.com/digitalocean/doctl"
ldFlags="${baseFlag}.Label=release ${baseFlag}.Build=$(git rev-parse --short HEAD)"
ldFlags="${ldFlags} ${baseFlag}.Major=$(echo ${short} | cut -d'.' -f1)"
ldFlags="${ldFlags} ${baseFlag}.Minor=$(echo ${short} | cut -d'.' -f2)"
ldFlags="${ldFlags} ${baseFlag}.Patch=$(echo ${short} | cut -d'.' -f3 | cut -d'+' -f1)"

GO111MODULE=on go build -ldflags "${ldFlags}" -mod=vendor -o doctl cmd/doctl/main.go

chmod +x doctl
mkdir -p $SNAPCRAFT_PART_INSTALL/bin
mv doctl $SNAPCRAFT_PART_INSTALL/bin/
Expand Down