diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ab6011b2..ee19e8f3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,7 @@ name: Publish on: push: tags: - - 'v*' + - "v*" jobs: publish: @@ -12,7 +12,7 @@ jobs: strategy: matrix: include: - - os: ubuntu-latest + - os: ubuntu-22.04 asset_name: mergestat-linux-amd64 # - os: windows-latest # asset_name: mergestat-windows-amd64 @@ -20,30 +20,30 @@ jobs: asset_name: mergestat-macos-amd64 steps: - - name: Set up Go 1.19 - uses: actions/setup-go@v3 - with: - go-version: 1.19.4 - id: go - - - name: Check out source - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Install libgit2 - run: make libgit2 - - - name: Build - run: make - - - name: Compress - run: tar -czvf mergestat.tar.gz -C .build/ . - - - name: Upload binaries to release - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - file: mergestat.tar.gz - asset_name: ${{ matrix.asset_name }}.tar.gz - tag: ${{ github.ref }} + - name: Set up Go 1.19 + uses: actions/setup-go@v3 + with: + go-version: 1.19.4 + id: go + + - name: Check out source + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Install libgit2 + run: make libgit2 + + - name: Build + run: make + + - name: Compress + run: tar -czvf mergestat.tar.gz -C .build/ . + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: mergestat.tar.gz + asset_name: ${{ matrix.asset_name }}.tar.gz + tag: ${{ github.ref }} diff --git a/Dockerfile b/Dockerfile index 18a580b6..1e931a57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,17 @@ -FROM golang:1.19-buster as builder +FROM golang:1.20-bookworm@sha256:077ff85b374b23916b4b41835e242e5a3ddad9fc537ea7e980f230431747d245 as builder WORKDIR /app -RUN apt-get update && apt-get -y install cmake libssl-dev -COPY . . +RUN apt-get update && apt-get -y install cmake libssl-dev libssl3 bzip2 +COPY go.mod /app/go.mod +COPY go.sum /app/go.sum +COPY git2go /app/git2go +RUN go mod download +COPY Makefile /app/Makefile RUN make libgit2 +COPY . . RUN make +RUN ls -l -FROM debian:buster-slim +FROM debian:bookworm-slim@sha256:abbf1e0df2d9631707a41780bd9d332523d10cbb14560122536210298b77f09d WORKDIR /app/ RUN mkdir /repo COPY --from=builder /app/.build/mergestat . diff --git a/Makefile b/Makefile index eb5d1d07..f8f472ca 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,10 @@ .PHONY: clean update vet test lint lint-ci test-cover bench # default task invoked while running make -all: clean .build/libmergestat.so .build/mergestat +all: clean .build/libmergestat.so .build/mergestat compress +OS = $(shell uname -s | tr '[:upper:]' '[:lower:]') +ARCH = $(shell uname -m | sed 's/x86_64/amd64/') # pass these flags to linker to suppress missing symbol errors in intermediate artifacts export CGO_CFLAGS = -DUSE_LIBSQLITE3 export CPATH = ${PWD}/pkg/sqlite @@ -11,6 +13,26 @@ ifeq ($(shell uname -s),Darwin) export CGO_LDFLAGS = -Wl,-undefined,dynamic_lookup endif + +UPX_VERSION=4.1.0 +.bin/upx: +ifeq (, $(shell which upx)) +ifeq ($(OS), darwin) + brew install upx + UPX=upx +else + wget -nv -O upx.tar.xz https://github.com/upx/upx/releases/download/v$(UPX_VERSION)/upx-$(UPX_VERSION)-$(ARCH)_$(OS).tar.xz + tar xf upx.tar.xz upx-$(UPX_VERSION)-$(ARCH)_$(OS)/upx + rm -rf upx.tar.xz + UPX=./upx +endif +else + UPX=$(shell which upx) +endif + +compress: .bin/upx + upx -5 mergestat* + # target to build and install libgit2 libgit2: cd git2go; make install-static diff --git a/extensions/internal/github/check_suite.go b/extensions/internal/github/check_suite.go index ac3f3247..205708f3 100644 --- a/extensions/internal/github/check_suite.go +++ b/extensions/internal/github/check_suite.go @@ -6,9 +6,9 @@ import ( "time" "github.com/augmentable-dev/vtab" + "github.com/rs/zerolog" "github.com/shurcooL/githubv4" "go.riyazali.net/sqlite" - "go.uber.org/zap" ) // fetch checkRun from the checkSuiteConnection @@ -66,7 +66,7 @@ type checkRun struct { Url githubv4.URI } -type ref struct { +type checkRunRef struct { Name string Target struct { Commit struct { @@ -103,7 +103,7 @@ func (i *iterCheckSuites) fetchCheckSuiteResults(ctx context.Context, startCurso } Name string Refs struct { - Nodes []*ref + Nodes []*checkRunRef PageInfo struct { EndCursor githubv4.String HasNextPage bool @@ -126,9 +126,9 @@ func (i *iterCheckSuites) fetchCheckSuiteResults(ctx context.Context, startCurso return &fetchCheckSuiteResults{rows, CheckSuiteQuery.Repository.Refs.PageInfo.HasNextPage, &CheckSuiteQuery.Repository.Refs.PageInfo.EndCursor}, nil } -func (i *iterCheckSuites) logger() *zap.SugaredLogger { - logger := i.Logger.Sugar().With("per-page", i.PerPage, "owner", i.owner, "name", i.name) - return logger +func (i *iterCheckSuites) logger() *zerolog.Logger { + logger := i.Logger.With().Int("per-page", i.PerPage).Str("owner", i.owner).Str("name", i.name).Logger() + return &logger } func (i *iterCheckSuites) Next() (vtab.Row, error) { @@ -146,7 +146,7 @@ func (i *iterCheckSuites) Next() (vtab.Row, error) { cursor = i.results.EndCursor } - i.logger().With("cursor", cursor).Infof("fetching page of repo_check_runs for %s/%s", i.owner, i.name) + i.logger().Info().Msgf("fetching page of repo_check_runs for %s/%s", i.owner, i.name) results, err := i.fetchCheckSuiteResults(context.Background(), cursor) if err != nil { return nil, err @@ -164,7 +164,7 @@ func (i *iterCheckSuites) Next() (vtab.Row, error) { } var checkCols = []vtab.Column{ - {Name: "owner", Type: "TEXT", NotNull: true, Hidden: true, Filters: []*vtab.ColumnFilter{{Op: sqlite.INDEX_CONSTRAINT_EQ, Required: true, OmitCheck: true}}}, + {Name: "owner", Type: "TEXT", NotNull: true, Hidden: true, Filters: []*vtab.ColumnFilter{{Op: sqlite.INDEX_CONSTRAINT_EQ, OmitCheck: true}}}, {Name: "reponame", Type: "TEXT", NotNull: true, Hidden: true, Filters: []*vtab.ColumnFilter{{Op: sqlite.INDEX_CONSTRAINT_EQ, OmitCheck: true}}}, {Name: "name", Type: "TEXT"}, {Name: "workflow_name", Type: "TEXT"}, @@ -183,7 +183,7 @@ var checkCols = []vtab.Column{ {Name: "app_logo_url", Type: "TEXT"}, } -func (i *iterCheckSuites) Column(ctx *sqlite.Context, c int) error { +func (i *iterCheckSuites) Column(ctx vtab.Context, c int) error { current := i.results.Edges[i.current] col := checkCols[c] @@ -252,12 +252,11 @@ func NewCheckModule(opts *Options) sqlite.Module { } iter := &iterCheckSuites{opts, owner, name, -1, nil} - iter.logger().Infof("starting GitHub check iterator for %s/%s", owner, name) return iter, nil }) } -func getCheckRowsFromRefs(refs []*ref) []*checkRunRow { +func getCheckRowsFromRefs(refs []*checkRunRef) []*checkRunRow { var rows []*checkRunRow for _, r := range refs { for _, suite := range r.Target.Commit.CheckSuites.Nodes {