Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add go and release workflow #23

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: mev-commit-oracle-ci

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Go 1.21.1
uses: actions/setup-go@v2
with:
go-version: 1.21.1
id: go

- name: Lint with golangci-lint v1.54.2
uses: golangci/golangci-lint-action@v2
with:
version: v1.54.2

- name: Vet
run: go vet ./...

- name: Build
run: go build ./...

- name: Test
run: go test -short ./...

36 changes: 36 additions & 0 deletions .github/workflows/goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: goreleaser

on:
push:
tags:
- 'v*'

permissions:
contents: write
packages: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: echo "flags=--snapshot" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version: 1.21
cache: true
- name: GHCR Docker Login
run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean ${{ env.flags }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

52 changes: 52 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: 1

before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
main: ./cmd
flags:
- -v
- -trimpath
ldflags:
- -s -w

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}

dockers:
- image_templates:
- ghcr.io/primevprotocol/mev-commit-oracle:v{{ .Major }}.{{ .Minor }}
- ghcr.io/primevprotocol/mev-commit-oracle:latest
dockerfile: Dockerfile.goreleaser
use: buildx
goarch: amd64
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--platform=linux/amd64"

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
7 changes: 7 additions & 0 deletions Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:latest

COPY mev-commit-oracle /usr/local/bin/mev-commit-oracle

EXPOSE 8080

ENTRYPOINT ["mev-commit-oracle", "start"]
10 changes: 8 additions & 2 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ func (a *Service) registerStatsEndpoints() {

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(resp)
_, err = w.Write(resp)
if err != nil {
log.Error().Err(err).Msg("failed to write response")
}
})

a.router.HandleFunc("/stats", func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -119,7 +122,10 @@ func (a *Service) registerStatsEndpoints() {

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(resp)
_, err = w.Write(resp)
if err != nil {
log.Error().Err(err).Msg("failed to write response")
}
})
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ func NewNode(opts *Options) (*Node, error) {
)
if err != nil {
log.Fatal().Err(err).Msg("failed to instantiate preconf contract")
cancel()
return nil, err
}

oracleContract, err := rollupclient.NewOracle(opts.OracleContractAddr, settlementClient)
if err != nil {
log.Fatal().Err(err).Msg("failed to instantiate oracle contract")
cancel()
return nil, err
}

Expand All @@ -121,6 +123,7 @@ func NewNode(opts *Options) (*Node, error) {
)
if err != nil {
log.Fatal().Err(err).Msg("failed to set builder mapping")
cancel()
return nil, err
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/settler/settler.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func (s *Settler) Start(ctx context.Context) <-chan struct{} {
for {
select {
case <-ctx.Done():
unsub()
return
case settlement, more := <-settlementChan:
if !more {
Expand Down
1 change: 1 addition & 0 deletions pkg/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (u *Updater) Start(ctx context.Context) <-chan struct{} {
for {
select {
case <-ctx.Done():
unsub()
return
case winner, more := <-winnerChan:
if !more {
Expand Down
22 changes: 10 additions & 12 deletions pkg/updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,17 @@ func TestUpdater(t *testing.T) {
if count == 10 {
break
}
select {
case settlement := <-testWinnerRegister.settlements:
if settlement.blockNum != 5 {
t.Fatal("wrong block number")
}
if settlement.builder != "test" {
t.Fatal("wrong builder")
}
if settlement.isSlash {
t.Fatal("should not be slash")
}
count++
settlement := <-testWinnerRegister.settlements
if settlement.blockNum != 5 {
t.Fatal("wrong block number")
}
if settlement.builder != "test" {
t.Fatal("wrong builder")
}
if settlement.isSlash {
t.Fatal("should not be slash")
}
count++
}

select {
Expand Down
Loading