From 9c6e769e07a94629a77d8c463b110f79434c16eb Mon Sep 17 00:00:00 2001 From: Patrick DeVivo Date: Mon, 7 Mar 2022 17:43:24 -0500 Subject: [PATCH 1/5] feat: vendor `libgit2` (via `git2go`) --- .gitmodules | 3 +++ Dockerfile | 5 +---- Makefile | 8 ++++++-- git2go | 1 + go.mod | 2 ++ go.sum | 2 -- 6 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 .gitmodules create mode 160000 git2go diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..49ab8fc4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "git2go"] + path = git2go + url = https://github.com/libgit2/git2go diff --git a/Dockerfile b/Dockerfile index fe4cea57..75222820 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,8 @@ FROM golang:1.17-buster as builder WORKDIR /app -COPY scripts . RUN apt-get update && apt-get -y install cmake libssl-dev -RUN ./install_libgit2.sh -COPY go.mod go.sum ./ -RUN go mod download COPY . . +RUN make libgit2 RUN make FROM debian:buster-slim diff --git a/Makefile b/Makefile index 51a90d82..ad9da8f8 100644 --- a/Makefile +++ b/Makefile @@ -11,16 +11,20 @@ ifeq ($(shell uname -s),Darwin) export CGO_LDFLAGS = -Wl,-undefined,dynamic_lookup endif +# target to build and install libgit2 +libgit2: + cd git2go; make install-static + # target to build a dynamic extension that can be loaded at runtime .build/libmergestat.so: $(shell find . -type f -name '*.go' -o -name '*.c') $(call log, $(CYAN), "building $@") - @go build -buildmode=c-shared -o $@ -tags="system_libgit2,shared" shared.go + @go build -buildmode=c-shared -o $@ -tags="static,shared" shared.go $(call log, $(GREEN), "built $@") # target to compile mergestat executable .build/mergestat: $(shell find . -type f -name '*.go' -o -name '*.c') $(call log, $(CYAN), "building $@") - @go build -o $@ -tags="static,system_libgit2" mergestat.go + @go build -o $@ -tags="static" mergestat.go $(call log, $(GREEN), "built $@") # target to download latest sqlite3 amalgamation code diff --git a/git2go b/git2go new file mode 160000 index 00000000..eae00773 --- /dev/null +++ b/git2go @@ -0,0 +1 @@ +Subproject commit eae00773cce87d5282a8ac7c10b5c1961ee6f9cb diff --git a/go.mod b/go.mod index abc31f8b..39a0f33f 100644 --- a/go.mod +++ b/go.mod @@ -75,3 +75,5 @@ require ( gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) + +replace github.com/libgit2/git2go/v33 => ./git2go diff --git a/go.sum b/go.sum index ffc69a9e..a9ffdd13 100644 --- a/go.sum +++ b/go.sum @@ -342,8 +342,6 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+ github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk= github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/libgit2/git2go/v33 v33.0.9 h1:4ch2DJed6IhJO28BEohkUoGvxLsRzUjxljoNFJ6/O78= -github.com/libgit2/git2go/v33 v33.0.9/go.mod h1:KdpqkU+6+++4oHna/MIOgx4GCQ92IPCdpVRMRI80J+4= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w= From bc173d9527a7b1e6e2e66867759fc954fd78bd37 Mon Sep 17 00:00:00 2001 From: Patrick DeVivo Date: Mon, 7 Mar 2022 17:54:57 -0500 Subject: [PATCH 2/5] fix: update github actions to use submodules --- .github/workflows/release.yml | 6 +++--- .github/workflows/test.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4d28b8ef..30f8f752 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,11 +29,11 @@ jobs: - name: Check out source uses: actions/checkout@v1 - - name: Install libgit2 - run: sudo ./scripts/install_libgit2.sh + - name: Update submodules + run: git submodule update --init - name: Build - run: make + run: make libgit2 && make - name: Compress run: tar -czvf mergestat.tar.gz -C .build/ . diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index afd27194..298806b5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,8 +22,8 @@ jobs: - name: Check out source uses: actions/checkout@v1 - - name: Install libgit2 - run: sudo ./scripts/install_libgit2.sh + - name: Update submodules + run: git submodule update --init - name: Vet run: make vet From 32fbb61e20353fc580e14d7396524ccb7676325f Mon Sep 17 00:00:00 2001 From: Patrick DeVivo Date: Mon, 7 Mar 2022 18:02:01 -0500 Subject: [PATCH 3/5] fix: try fixing github actions again --- .github/workflows/release.yml | 6 +++--- .github/workflows/test.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 30f8f752..bcaf1ad8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,11 +29,11 @@ jobs: - name: Check out source uses: actions/checkout@v1 - - name: Update submodules - run: git submodule update --init + - name: Install libgit2 + run: git submodule update --init && make libgit2 - name: Build - run: make libgit2 && make + run: make - name: Compress run: tar -czvf mergestat.tar.gz -C .build/ . diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 298806b5..730bf6ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,8 +22,8 @@ jobs: - name: Check out source uses: actions/checkout@v1 - - name: Update submodules - run: git submodule update --init + - name: Install libgit2 + run: git submodule update --init && make libgit2 - name: Vet run: make vet From 755bba5bb4ebcc6b51c44a0a0fcf1badde8af372 Mon Sep 17 00:00:00 2001 From: Patrick DeVivo Date: Mon, 7 Mar 2022 18:07:09 -0500 Subject: [PATCH 4/5] fix: try a different approach to submodule update --- .github/workflows/release.yml | 4 +++- .github/workflows/test.yml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bcaf1ad8..4478ab55 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,9 +28,11 @@ jobs: - name: Check out source uses: actions/checkout@v1 + with: + submodules: recursive - name: Install libgit2 - run: git submodule update --init && make libgit2 + run: make libgit2 - name: Build run: make diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 730bf6ab..d7a3e095 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,9 +21,11 @@ jobs: - name: Check out source uses: actions/checkout@v1 + with: + submodules: recursive - name: Install libgit2 - run: git submodule update --init && make libgit2 + run: make libgit2 - name: Vet run: make vet From 43952831380bf481266885ba4ba1f554803d7ad6 Mon Sep 17 00:00:00 2001 From: Patrick DeVivo Date: Mon, 7 Mar 2022 18:15:29 -0500 Subject: [PATCH 5/5] fix: rm `system_libgit2` tag --- .vscode/settings.json | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6e978302..a79dd9a8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "go.buildFlags": [ "-tags='libsqlite3'" ], - "go.testFlags": ["-v", "-tags=libsqlite3,static,system_libgit2"], + "go.testFlags": ["-v", "-tags=libsqlite3,static"], "go.vetFlags": ["-tags=libsqlite3"], "go.toolsEnvVars": { "GOFLAGS": "-tags='libsqlite3'", diff --git a/Makefile b/Makefile index ad9da8f8..da37a749 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ clean: # target for common golang tasks # go build tags used by test, vet and more -TAGS = "static,system_libgit2" +TAGS = "static" update: go get -tags=$(TAGS) -u ./...