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

Setup Go builds and tests in the CI #107

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ jobs:
path: offchain/schema.graphql
if-no-files-found: error

- name: Install Go
torives marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'

- name: Run Go tests
working-directory: ${{ github.workspace }}
run: go test ./...

build_docker:
runs-on: ubuntu-22.04
needs:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/go-code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Assess Go code quality

on:
push:
paths:
- ".github/workflows/go-code-quality.yml"
- ".golangci.yml"
- "cmd/**"
- "internal/**"

jobs:
assess-go-code-quality:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
torives marked this conversation as resolved.
Show resolved Hide resolved
with:
submodules: recursive

- uses: actions/setup-go@v4
with:
go-version-file: "go.mod"

- name: Run Linter
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.2
2 changes: 1 addition & 1 deletion .github/workflows/rust-code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Assess Rust code quality
on:
push:
paths:
- '.github/workflows/code-quality.yml'
- '.github/workflows/rust-code-quality.yml'
torives marked this conversation as resolved.
Show resolved Hide resolved
- 'offchain/**'

jobs:
Expand Down
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
linters:
enable:
- exhaustive
- goconst
- godox
- gofmt
- gomnd
- lll
- misspell
linters-settings:
lll:
line-length: 100
tab-width: 4
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added `cartesi-rollups-node` Go binary as a single entrypoint to execute all Cartesi Node services

### Changed

- Added rollups-node version to the logs in all services
Expand Down
17 changes: 17 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
# syntax=docker.io/docker/dockerfile:1.4

ARG RUST_VERSION=1.72.1
ARG GO_VERSION=1.21.1
ARG SERVER_MANAGER_VERSION=0.8.2
ARG ROLLUPS_CONTRACTS_VERSION=1.0.2

ARG BASE_PATH=/opt/cartesi
ARG RUST_BUILD_PATH=${BASE_PATH}/src/rollups-node/offchain
ARG DEPLOYMENT_PATH=${BASE_PATH}/share/deployments
ARG GO_BASE_PATH=/go
ARG GO_BUILD_PATH=${GO_BASE_PATH}/cartesi-rollups-node
ARG GO_BIN_PATH=${GO_BASE_PATH}/bin
ARG RUNTIME_DIR=/var/opt/cartesi

#
Expand Down Expand Up @@ -69,6 +73,15 @@ COPY ./offchain/ .
COPY ./.git ../
RUN cargo build --release

#
# Go build
#
FROM golang:${GO_VERSION}-bookworm as go-builder
ARG GO_BUILD_PATH
WORKDIR ${GO_BUILD_PATH}
COPY . .
RUN go install -ldflags "-s -w" ./cmd/cartesi-rollups-node

#
# Runtime
#
Expand All @@ -93,6 +106,10 @@ ARG RUST_BUILD_PATH
COPY --from=rust-builder ${RUST_BUILD_PATH}/target/release/cartesi-rollups-* .
ENV PATH="${BASE_PATH}/bin:${PATH}"

# Copy Go binary
ARG GO_BIN_PATH
COPY --from=go-builder ${GO_BIN_PATH}/cartesi-rollups-node .

# Setup runtime dir
ARG RUNTIME_DIR
RUN mkdir -p ${RUNTIME_DIR}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package main
import "github.com/spf13/cobra"

var noBackend = &cobra.Command{
Use: "no-backend",
Short: "Starts the node in no-backend mode",
Use: "nobackend",
Short: "Starts the node in nobackend mode",
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
println("TODO")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import "github.com/spf13/cobra"

var rootCmd = &cobra.Command{
Use: "cartesi-node",
Use: "cartesi-rollups-node",
CompletionOptions: cobra.CompletionOptions{HiddenDefaultCmd: true},
DisableFlagsInUseLine: true,
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ func (g GraphQLService) Start(ctx context.Context) error {
go func() {
<-ctx.Done()
fmt.Printf("%v: %v\n", g.String(), ctx.Err())
cmd.Process.Signal(syscall.SIGTERM)
if err := cmd.Process.Signal(syscall.SIGTERM); err != nil {
msg := "%v: failed to send SIGTERM to %v\n"
fmt.Printf(msg, g.String(), binaryName)
}
}()

err := cmd.Wait()
Expand Down
50 changes: 50 additions & 0 deletions internal/pkg/services/graphql_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

package services

import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"syscall"
"testing"
"time"
)

func TestGraphQLService(t *testing.T) {
t.Run("it stops when the context is cancelled", func(t *testing.T) {
service := GraphQLService{}
setupEnvVars()
ctx, cancel := context.WithCancel(context.Background())
exit := make(chan error)

go func() {
if err := service.Start(ctx); err != nil {
exit <- err
}
}()

<-time.After(100 * time.Millisecond)
cancel()

err := <-exit
exitError, ok := err.(*exec.ExitError)
if !ok || !assertExitErrorWasCausedBy(exitError, syscall.SIGTERM) {
fmt.Printf("service exited for the wrong reason: %v", err)
t.FailNow()
}
})
}

func setupEnvVars() {
abs, _ := filepath.Abs("../../../offchain/target/debug")
os.Setenv("PATH", abs)
}

func assertExitErrorWasCausedBy(err *exec.ExitError, signal syscall.Signal) bool {
status := err.Sys().(syscall.WaitStatus)
return status.Signal() == signal
}
Loading