Skip to content

Commit

Permalink
chore: rebase from mergestat
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Oct 17, 2023
1 parent 7159c0b commit b34202a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 45 deletions.
58 changes: 29 additions & 29 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Publish
on:
push:
tags:
- 'v*'
- "v*"

jobs:
publish:
Expand All @@ -12,38 +12,38 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-latest
- os: ubuntu-22.04
asset_name: mergestat-linux-amd64
# - os: windows-latest
# asset_name: mergestat-windows-amd64
- os: macos-latest
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 }}
14 changes: 10 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 .
Expand Down
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
21 changes: 10 additions & 11 deletions extensions/internal/github/check_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,7 +66,7 @@ type checkRun struct {
Url githubv4.URI
}

type ref struct {
type checkRunRef struct {
Name string
Target struct {
Commit struct {
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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"},
Expand All @@ -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]

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b34202a

Please sign in to comment.