Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to release gitql as a static file (#84)
- Loading branch information
1 parent
cc252e3
commit a1a84eb
Showing
11 changed files
with
249 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,31 @@ | ||
name: Go | ||
name: CI | ||
on: [push] | ||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
test: | ||
strategy: | ||
matrix: | ||
platform: [ubuntu-latest] | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- name: Set up Go 1.12 | ||
uses: actions/setup-go@v1 | ||
with: | ||
version: 1.12 | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v1 | ||
with: | ||
path: go/src/github.com/cloudson/gitql | ||
|
||
- name: Run tests | ||
working-directory: ${{ go.module-path }} | ||
run: make test | ||
|
||
- name: Build | ||
working-directory: ${{ go.module-path }} | ||
run: make | ||
run: | | ||
make test | ||
- name: Build linux | ||
env: | ||
GOPATH: /home/runner/work/cloudson/go | ||
TARGET_OS_ARCH: linux/amd64 | ||
run: | | ||
./install.sh | ||
./gitql -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ git2go | |
libgit2 | ||
gitql | ||
.vscode* | ||
.idea/ | ||
.idea/ | ||
vendor |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM golang:1.12-alpine | ||
|
||
WORKDIR /etc | ||
ADD . . | ||
RUN apk update && \ | ||
apk add git make clang build-base pkgconfig openssh cmake libssh2 libssh2-dev openssl bash ninja | ||
RUN go get -u -d -v . | ||
RUN ./install.sh | ||
RUN ./gitql -v | ||
RUN echo "INSTALLED " $TARGET_OS_ARCH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module github.com/cloudson/gitql | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/chzyer/logex v1.1.10 // indirect | ||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e | ||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect | ||
github.com/cloudson/git2go v0.0.0-20191006111621-d809ba5282bf | ||
github.com/jessevdk/go-flags v1.4.0 | ||
github.com/mattn/go-runewidth v0.0.4 // indirect | ||
github.com/olekukonko/tablewriter v0.0.1 | ||
github.com/pkg/errors v0.8.1 | ||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= | ||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= | ||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= | ||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= | ||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= | ||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= | ||
github.com/cloudson/git2go v0.0.0-20191006111621-d809ba5282bf h1:4ZRjBIIIzpcKadgdlZ/PrXL9Nzvzc+Ocgj7jkKyInco= | ||
github.com/cloudson/git2go v0.0.0-20191006111621-d809ba5282bf/go.mod h1:+2sIqmFkqG9ZMPRAOjp55Q3VTDQwpzQEtAymVW6vGWA= | ||
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= | ||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= | ||
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= | ||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= | ||
github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88= | ||
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= | ||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= | ||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 h1:L2auWcuQIvxz9xSEqzESnV/QN/gNRXNApHi3fYwl2w0= | ||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,172 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
export GO111MODULE="on" | ||
export GOFLAGS="-mod=vendor -tags=static" | ||
export CGO_ENABLED=1 | ||
|
||
unameOut="$(uname -s)" | ||
case "${unameOut}" in | ||
Linux*) machine=Linux;; | ||
Darwin*) machine=Mac;; | ||
CYGWIN*) machine=Cygwin;; | ||
MINGW*) machine=MinGw;; | ||
*) machine="UNKNOWN:${unameOut}" | ||
esac | ||
|
||
if [[ $machine == MinGw ]] | ||
then | ||
# Everything here is ugly. But MinGW seem to have no ldconfig, | ||
# no respect to /usr/local/bin, /usr/local/lib | ||
cp ./libgit2/install/bin/libgit2.dll /usr/bin/ | ||
cp ./gitql.exe /usr/bin/gitql.exe | ||
ln -s -f /usr/bin/gitql.exe /usr/bin/git-ql | ||
echo "Gitql.exe is in /usr/bin/gitql.exe" | ||
echo "You can also use: git ql 'query here'" | ||
else | ||
cp ./libgit2/install/lib/lib* /usr/local/lib/ | ||
ldconfig /usr/local/lib >/dev/null 2>&1 || echo "ldconfig not found">/dev/null | ||
cp ./gitql /usr/local/bin/gitql | ||
ln -s -f /usr/local/bin/gitql /usr/local/bin/git-ql | ||
echo "Git is in /usr/local/bin/gitql" | ||
echo "You can also use: git ql 'query here'" | ||
fi | ||
export GIT2GO_PATH="${PWD}/vendor/github.com/cloudson/git2go" | ||
export LIBGIT2_PATH="${GIT2GO_PATH}/vendor/libgit2" | ||
export LIBGIT2_BUILD="${GIT2GO_PATH}/static-build/${TARGET_OS_ARCH}" | ||
export LIBGIT2_STATIC_PREFIX="${GIT2GO_PATH}/static-build/install" | ||
|
||
setup_vendor(){ | ||
LIBGIT2_URL=https://github.com/libgit2/libgit2.git | ||
LIBGIT2_VER=v0.28.2 | ||
|
||
go mod download | ||
|
||
if ! [[ -d vendor ]]; then | ||
go mod vendor | ||
fi | ||
|
||
git -c advice.detachedHead=false clone --quiet --depth 1 -b $LIBGIT2_VER $LIBGIT2_URL $LIBGIT2_PATH || : | ||
} | ||
|
||
build_libgit2_generic(){ | ||
cmake \ | ||
-G Ninja \ | ||
-DTHREADSAFE=ON \ | ||
-DBUILD_CLAR=OFF \ | ||
-DBUILD_SHARED_LIBS=OFF \ | ||
-DUSE_EXT_HTTP_PARSER=OFF \ | ||
-DUSE_BUNDLED_ZLIB=ON \ | ||
-DUSE_HTTPS=OFF \ | ||
-DUSE_SSH=OFF \ | ||
-DUSE_ICONV=OFF \ | ||
-DCMAKE_C_FLAGS=-fPIE \ | ||
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \ | ||
-DCMAKE_INSTALL_PREFIX="${LIBGIT2_STATIC_PREFIX}" \ | ||
${LIBGIT2_PATH} | ||
} | ||
|
||
build_libgit2_linux(){ | ||
cmake \ | ||
-DTHREADSAFE=ON \ | ||
-DBUILD_CLAR=OFF \ | ||
-DBUILD_SHARED_LIBS=OFF \ | ||
-DUSE_EXT_HTTP_PARSER=OFF \ | ||
-DUSE_BUNDLED_ZLIB=ON \ | ||
-DUSE_HTTPS=OFF \ | ||
-DUSE_SSH=OFF \ | ||
-DUSE_ICONV=OFF \ | ||
-DCMAKE_SYSTEM_NAME=Linux \ | ||
-DCMAKE_C_COMPILER=${CC} \ | ||
-DCMAKE_C_FLAGS=-fPIE \ | ||
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \ | ||
-DCMAKE_INSTALL_PREFIX="${LIBGIT2_STATIC_PREFIX}" \ | ||
${LIBGIT2_PATH} | ||
} | ||
|
||
build_libgit2_windows(){ | ||
cmake \ | ||
-G Ninja \ | ||
-DTHREADSAFE=ON \ | ||
-DBUILD_CLAR=OFF \ | ||
-DBUILD_SHARED_LIBS=OFF \ | ||
-DUSE_EXT_HTTP_PARSER=OFF \ | ||
-DUSE_BUNDLED_ZLIB=ON \ | ||
-DUSE_HTTPS=OFF \ | ||
-DUSE_SSH=OFF \ | ||
-DUSE_ICONV=OFF \ | ||
-DWINHTTP=OFF \ | ||
-DCMAKE_SYSTEM_NAME=Windows \ | ||
-DCMAKE_C_COMPILER=${CC} \ | ||
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \ | ||
-DCMAKE_INSTALL_PREFIX="${LIBGIT2_STATIC_PREFIX}" \ | ||
-DWIN32=ON \ | ||
-DMINGW=ON \ | ||
-DCMAKE_SIZEOF_VOID_P=8 \ | ||
${LIBGIT2_PATH} | ||
} | ||
|
||
build_libgit2_darwin(){ | ||
cmake \ | ||
-G "Ninja" \ | ||
-DTHREADSAFE=ON \ | ||
-DBUILD_CLAR=OFF \ | ||
-DBUILD_SHARED_LIBS=OFF \ | ||
-DUSE_EXT_HTTP_PARSER=OFF \ | ||
-DUSE_BUNDLED_ZLIB=ON \ | ||
-DUSE_HTTPS=OFF \ | ||
-DUSE_SSH=OFF \ | ||
-DUSE_ICONV=OFF \ | ||
-DCMAKE_SYSTEM_NAME=Darwin \ | ||
-DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" \ | ||
-DCMAKE_C_COMPILER=${CC} \ | ||
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \ | ||
-DCMAKE_INSTALL_PREFIX="${LIBGIT2_STATIC_PREFIX}" \ | ||
-DCMAKE_OSX_SYSROOT="${OSX_SDK}" \ | ||
${LIBGIT2_PATH} | ||
} | ||
|
||
build_libgit2(){ | ||
mkdir -vp $LIBGIT2_BUILD | ||
pushd $LIBGIT2_BUILD | ||
|
||
case "$TARGET_OS_ARCH" in | ||
"") | ||
FLAGS="" | ||
export CGO_LDFLAGS="${LIBGIT2_STATIC_PREFIX}/lib/libgit2.a -L${LIBGIT2_STATIC_PREFIX}/include ${FLAGS}" | ||
build_libgit2_generic | ||
;; | ||
linux/amd64*) | ||
export GOOS=linux GOARCH=amd64 CC=clang | ||
FLAGS="" | ||
export CGO_LDFLAGS="${LIBGIT2_STATIC_PREFIX}/lib/libgit2.a -L${LIBGIT2_STATIC_PREFIX}/include ${FLAGS}" | ||
build_libgit2_linux | ||
;; | ||
darwin/amd64*) | ||
export GOOS=darwin GOARCH=amd64 CC=x86_64-apple-darwin18-clang OSX_SDK=/opt/osxcross/SDK/MacOSX10.14.sdk/ | ||
FLAGS="" | ||
export CGO_LDFLAGS="${LIBGIT2_STATIC_PREFIX}/lib/libgit2.a -L${LIBGIT2_STATIC_PREFIX}/include ${FLAGS}" | ||
build_libgit2_darwin | ||
;; | ||
windows/amd64*) | ||
export GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-clang | ||
FLAGS="-lws2_32" | ||
export CGO_LDFLAGS="${LIBGIT2_STATIC_PREFIX}/lib/libgit2.a -L${LIBGIT2_STATIC_PREFIX}/include ${FLAGS}" | ||
build_libgit2_windows | ||
;; | ||
windows/386*) | ||
export GOOS=windows GOARCH=386 CC=i686-w64-mingw32-clang | ||
FLAGS="-lws2_32" | ||
export CGO_LDFLAGS="${LIBGIT2_STATIC_PREFIX}/lib/libgit2.a -L${LIBGIT2_STATIC_PREFIX}/include ${FLAGS}" | ||
build_libgit2_windows | ||
;; | ||
esac | ||
|
||
cmake --build . -- -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) && cmake --build . --target install &>/dev/null | ||
|
||
popd | ||
} | ||
|
||
build_gitql(){ | ||
case "$TARGET_OS_ARCH" in | ||
windows/amd64*) | ||
;& | ||
windows/386*) | ||
;& | ||
linux/amd64*) | ||
go build -v -ldflags '-extldflags "-static"' . | ||
;; | ||
darwin/amd64*) | ||
# MacOS doesn't support fully static binaries, see | ||
# https://stackoverflow.com/questions/3801011/ld-library-not-found-for-lcrt0-o-on-osx-10-6-with-gcc-clang-static-flag | ||
# this is the best we could possibly do | ||
;& | ||
"") | ||
;& | ||
*) | ||
go build -v . | ||
;; | ||
esac | ||
} | ||
|
||
main(){ | ||
setup_vendor | ||
build_libgit2 | ||
build_gitql | ||
} | ||
|
||
main "$@" |
Oops, something went wrong.