diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d058ec6..931cc09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,15 +4,49 @@ on: push: branches: - master + - release-* - v* jobs: - build: + build-legacy: strategy: fail-fast: false matrix: - go: [ '1.9', '1.10', '1.11', '1.12' , '1.13'] + go: [ '1.9', '1.10' ] + name: Go ${{ matrix.go }} + + runs-on: ubuntu-18.04 + + steps: + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go }} + id: go + - name: Check out code into the GOPATH + uses: actions/checkout@v1 + with: + fetch-depth: 1 + path: src/github.com/${{ github.repository }} + - name: Build + env: + GOPATH: /home/runner/work/git2go + run: | + git submodule update --init + make build-libgit2-static + go get --tags "static" github.com/${{ github.repository }}/... + go build --tags "static" github.com/${{ github.repository }}/... + - name: Test + env: + GOPATH: /home/runner/work/git2go + run: make test-static + + build-static: + strategy: + fail-fast: false + matrix: + go: [ '1.11', '1.12', '1.13' ] name: Go ${{ matrix.go }} runs-on: ubuntu-18.04 @@ -28,4 +62,28 @@ jobs: - name: Build run: | git submodule update --init - make test-static + make build-libgit2-static + - name: Test + run: make test-static + + build-dynamic: + strategy: + fail-fast: false + name: Go (dynamic) + + runs-on: ubuntu-18.04 + + steps: + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: '1.13' + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + - name: Build + run: | + git submodule update --init + make build-libgit2-dynamic + - name: Test + run: make test-dynamic diff --git a/.gitignore b/.gitignore index edc18d5..713781b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /static-build/ +/dynamic-build/ diff --git a/.travis.yml b/.travis.yml index f611cc3..c89cb5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,31 @@ language: go go: - - 1.7 - - 1.8 - - 1.9 + - "1.7" + - "1.8" + - "1.9" - "1.10" + - "1.11" + - "1.12" + - "1.13" - tip -script: make test-static +install: + - make build-libgit2-static + - go get --tags "static" ./... + +script: + - make test-static matrix: allow_failures: - go: tip git: - submodules: false - -before_install: - - git submodule update --init + submodules: true branches: only: - master - /v\d+/ - - next + - /release-.*/ diff --git a/Makefile b/Makefile index cf00cef..182c53e 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,53 @@ default: test -test: build-libgit2 +# System library +# ============== +# This uses whatever version of libgit2 can be found in the system. +test: go run script/check-MakeGitError-thread-lock.go - go test ./... + go test --count=1 ./... -install: build-libgit2 +install: go install ./... -build-libgit2: +# Bundled dynamic library +# ======================= +# In order to avoid having to manipulate `git_dynamic.go`, which would prevent +# the system-wide libgit2.so from being used in a sort of ergonomic way, this +# instead moves the complexity of overriding the paths so that the built +# libraries can be found by the build and tests. +.PHONY: build-libgit2-dynamic +build-libgit2-dynamic: + ./script/build-libgit2-dynamic.sh + +dynamic-build/install/lib/libgit2.so: + ./script/build-libgit2-dynamic.sh + +test-dynamic: dynamic-build/install/lib/libgit2.so + PKG_CONFIG_PATH=dynamic-build/install/lib/pkgconfig \ + go run script/check-MakeGitError-thread-lock.go + PKG_CONFIG_PATH=dynamic-build/install/lib/pkgconfig \ + LD_LIBRARY_PATH=dynamic-build/install/lib \ + go test --count=1 ./... + +install-dynamic: dynamic-build/install/lib/libgit2.so + PKG_CONFIG_PATH=dynamic-build/install/lib/pkgconfig \ + go install ./... + +# Bundled static library +# ====================== +# This is mostly used in tests, but can also be used to provide a +# statically-linked library with the bundled version of libgit2. +.PHONY: build-libgit2-static +build-libgit2-static: ./script/build-libgit2-static.sh -install-static: build-libgit2 - go install --tags "static" ./... +static-build/install/lib/libgit2.a: + ./script/build-libgit2-static.sh -test-static: build-libgit2 +test-static: static-build/install/lib/libgit2.a go run script/check-MakeGitError-thread-lock.go - go test --tags "static" ./... + go test --count=1 --tags "static" ./... + +install-static: static-build/install/lib/libgit2.a + go install --tags "static" ./... diff --git a/script/build-libgit2-dynamic.sh b/script/build-libgit2-dynamic.sh new file mode 100755 index 0000000..af037f3 --- /dev/null +++ b/script/build-libgit2-dynamic.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -e + +exec "$(dirname "$0")/build-libgit2.sh" --dynamic diff --git a/script/build-libgit2-static.sh b/script/build-libgit2-static.sh index 4d89fba..1d28898 100755 --- a/script/build-libgit2-static.sh +++ b/script/build-libgit2-static.sh @@ -1,20 +1,5 @@ #!/bin/sh -set -ex +set -e -ROOT="$(cd "$(dirname "$0")/.." && echo "${PWD}")" -BUILD_PATH="${ROOT}/static-build" -VENDORED_PATH="${ROOT}/vendor/libgit2" - -mkdir -p "${BUILD_PATH}/build" "${BUILD_PATH}/install/lib" - -cd "${BUILD_PATH}/build" && -cmake -DTHREADSAFE=ON \ - -DBUILD_CLAR=OFF \ - -DBUILD_SHARED_LIBS=OFF \ - -DCMAKE_C_FLAGS=-fPIC \ - -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DCMAKE_INSTALL_PREFIX="${BUILD_PATH}/install" \ - "${VENDORED_PATH}" && - -cmake --build . --target install +exec "$(dirname "$0")/build-libgit2.sh" --static diff --git a/script/build-libgit2.sh b/script/build-libgit2.sh new file mode 100755 index 0000000..fbb05ab --- /dev/null +++ b/script/build-libgit2.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# Since CMake cannot build the static and dynamic libraries in the same +# directory, this script helps build both static and dynamic versions of it and +# have the common flags in one place instead of split between two places. + +set -e + +if [ "$#" -eq "0" ]; then + echo "Usage: $0 <--dynamic|--static>">&2 + exit 1 +fi + +ROOT="$(cd "$(dirname "$0")/.." && echo "${PWD}")" +VENDORED_PATH="${ROOT}/vendor/libgit2" + +case "$1" in + --static) + BUILD_PATH="${ROOT}/static-build" + BUILD_SHARED_LIBS=OFF + ;; + + --dynamic) + BUILD_PATH="${ROOT}/dynamic-build" + BUILD_SHARED_LIBS=ON + ;; + + *) + echo "Usage: $0 <--dynamic|--static>">&2 + exit 1 + ;; +esac + +mkdir -p "${BUILD_PATH}/build" "${BUILD_PATH}/install/lib" + +cd "${BUILD_PATH}/build" && +cmake -DTHREADSAFE=ON \ + -DBUILD_CLAR=OFF \ + -DBUILD_SHARED_LIBS"=${BUILD_SHARED_LIBS}" \ + -DCMAKE_C_FLAGS=-fPIC \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DCMAKE_INSTALL_PREFIX="${BUILD_PATH}/install" \ + "${VENDORED_PATH}" && + +exec cmake --build . --target install