From 2cfe722ef80ed0f5effc1a5fff7d7f956c42b9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Fri, 15 Jan 2021 12:59:17 +0100 Subject: [PATCH] Migrate to static building to remove dependency to libgit2 --- .github/workflows/go.yml | 20 ++++++++------------ README.md | 36 ++++++++++++++++++++++++++++++++++++ bin/build | 9 ++------- bin/setup | 14 +++++++++++++- bin/test | 5 +++-- env.sh | 9 +++++++++ ext_deps/git2go | 2 +- go.mod | 4 ++-- go.sum | 2 ++ 9 files changed, 76 insertions(+), 25 deletions(-) create mode 100644 env.sh diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ce6eb94..1c385ae 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -8,6 +8,8 @@ jobs: steps: - name: Check out code into the Go module directory uses: actions/checkout@v2 + with: + submodules: recursive - name: Set up Go 1.15 uses: actions/setup-go@v2 @@ -20,41 +22,35 @@ jobs: sudo apt-get update -y \ && sudo apt-get install -y cmake pkg-config gcc libssh2-1-dev libssl-dev - - name: set up git2go for static mode - run: | - git clone https://github.com/libgit2/git2go - cd git2go/ - git checkout release-1.1 - git submodule update --init # get libgit2 - make install-static - - name: get dependencies run: | - go get -v -t -d ./... + bin/setup - name: test run: bin/test + env: + GO_TAGS: static - name: build linux amd64 run: bin/build env: GOOS: linux GOARCH: amd64 - BUILD_TAGS: static + GO_TAGS: static - name: build windows amd64 run: bin/build env: GOOS: windows GOARCH: amd64 - BUILD_TAGS: static + GO_TAGS: static - name: build darwin amd64 run: bin/build env: GOOS: darwin GOARCH: amd64 - BUILD_TAGS: static + GO_TAGS: static - name: package software for linux amd64 run: bin/package diff --git a/README.md b/README.md index ebbadd2..2f0eba4 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,42 @@ lg build -V After building letters, you will find a directory called `letters` in the current directory. +## Development + +### Build letter-generator from its sources + +~~~ +bin/setup +bin/build +bin/test +~~~ + +### Central configuration file for helper scripts + +Configuration for helper scripts is done via environment variables in [`env.sh`](env.sh). + +### Upgrade git2go / libgit2 + +See https://github.com/libgit2/git2go#master-branch-or-vendored-static-linking +for more information about this. + +If you plan to upgrade your version, you need to modify a few files. + +1. Update version for "libgit2" in `env.sh` + + ~~~bash +: ${LIBGIT2_TAG:=release-1.1} + ~~~ + +2. Update version of "git2go" in `go.mod` + + ~~~bash + # [...] + github.com/libgit2/git2go/v31 v31.4.7 + # [...] + replace github.com/libgit2/git2go/v31 => ./ext_deps/git2go + ~~~ + ## Copyright (c) 2021, Dennis Günnewig diff --git a/bin/build b/bin/build index 13d715d..cf13738 100755 --- a/bin/build +++ b/bin/build @@ -1,13 +1,8 @@ #!/usr/bin/env bash -: ${GOOS:=linux} -: ${GOARCH:=amd64} -: ${GO_TAGS:=static,system_libgit2} +source ./env.sh -COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null) -BUILD_DATE=$(date +%FT%T%z) -VERSION=$(git tag | sort | tail -n 1) -VERSION=${VERSION/v/}; +echo --- Build letter-generator echo GO111MODULE=on CGO_ENABLED=1 go build --tags ${GO_TAGS} $* -ldflags "-w -s -X main.AppVersionNumber=${VERSION} -X main.CommitHash=${COMMIT_HASH} -X main.BuildDate=${BUILD_DATE}" -o dist/${GOOS}/${GOARCH}/lg ./cmd/lg GO111MODULE=on CGO_ENABLED=1 go build --tags ${GO_TAGS} $* -ldflags "-w -s -X main.AppVersionNumber=${VERSION} -X main.CommitHash=${COMMIT_HASH} -X main.BuildDate=${BUILD_DATE}" -o dist/${GOOS}/${GOARCH}/lg ./cmd/lg diff --git a/bin/setup b/bin/setup index 7f90560..aac358c 100755 --- a/bin/setup +++ b/bin/setup @@ -1,5 +1,17 @@ #!/bin/bash -echo install libgit2 +source ./env.sh +echo --- Build static git2go + +git submodule update --init # get git2go +cd ext_deps/git2go +git checkout ${LIBGIT2_TAG} +git submodule update --init # get libgit2 +make install-static +cd - + +echo +echo --- Install dependencies +echo go get -d -v ./... go get -d -v ./... diff --git a/bin/test b/bin/test index cccc374..ab1fd80 100755 --- a/bin/test +++ b/bin/test @@ -1,5 +1,6 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash -: ${GO_TAGS:=static,system_libgit2} +source ./env.sh +echo --- Test letter-generator go test --tags ${GO_TAGS} -v ./... $* diff --git a/env.sh b/env.sh new file mode 100644 index 0000000..534a0b8 --- /dev/null +++ b/env.sh @@ -0,0 +1,9 @@ +: ${GOOS:=linux} +: ${GOARCH:=amd64} +: ${GO_TAGS:=static} +: ${LIBGIT2_TAG:=release-1.1} + +: ${COMMIT_HASH:=$(git rev-parse --short HEAD 2>/dev/null)} +: ${BUILD_DATE:=$(date +%FT%T%z)} +: ${VERSION:=$(git tag | sort | tail -n 1)} +: ${VERSION:=${VERSION/v/}} diff --git a/ext_deps/git2go b/ext_deps/git2go index 4b2ac7c..ad3ec36 160000 --- a/ext_deps/git2go +++ b/ext_deps/git2go @@ -1 +1 @@ -Subproject commit 4b2ac7c998be677d865367908787f17fb570c679 +Subproject commit ad3ec3664d54779c4c2e49e41f85e886fbff343c diff --git a/go.mod b/go.mod index 7f1df98..e8c51c5 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/feduxorg/letter-generator go 1.12 -//replace github.com/libgit2/git2go => github.com/maxmeyer/git2go v0.28.4 - require ( github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/libgit2/git2go/v31 v31.4.7 @@ -17,3 +15,5 @@ require ( golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78 // indirect gopkg.in/yaml.v2 v2.4.0 ) + +replace github.com/libgit2/git2go/v31 => ./ext_deps/git2go diff --git a/go.sum b/go.sum index 7e2d1f6..d70d141 100644 --- a/go.sum +++ b/go.sum @@ -43,6 +43,7 @@ github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c h1:9HhBz5L/UjnK9XLtiZhYAdue5BVKep3PMmS2LuPDt8k= golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= @@ -54,6 +55,7 @@ golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=