Skip to content

Commit

Permalink
Create go.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
xescugc committed Nov 21, 2023
1 parent 6ee7152 commit 018fa0a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:
env:
# We overwrite this value to be 4 so
# the test can pass because if not the
# goroutines will not run in "parallel"
# and so the tests do not pass.
# 4 is because:
# * 1 Main run
# * 2 clients
# * 1 server
GOMAXPROCS: 4
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

# We install xorg-dev because of https://github.com/go-gl/glfw/issues/129#issuecomment-75928365
# We install xvfb because of the error "The DISPLAY environment variable is missing" so we need
# to have a fake DISPLAY and xvfb does exactly that.
# Found it in https://stackoverflow.com/questions/834723/a-dev-null-equivilent-for-display-when-the-display-is-just-noise
- name: "Install xorg-dev and xvfb"
run: sudo apt-get install xvfb xorg-dev

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build
run: make build

- name: Test
run: make test
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.PHONY: help
help: ## Show this help
@grep -F -h "##" $(MAKEFILE_LIST) | grep -F -v grep -F | sed -e 's/:.*##/:##/' | column -t -s '##'

.PHONY: build
build:
@go build -v ./...

.PHONY: test
test: ## Run the tests
@xvfb-run go test -v ./...
2 changes: 1 addition & 1 deletion client/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func New(ad *ActionDispatcher, rs *RouterStore, opt Options) error {
var err error
wsc, _, err = websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
return fmt.Errorf("failed to dial the server %q: %w", u, err)
return fmt.Errorf("failed to dial the server %q: %w", u.String(), err)
}
defer wsc.Close()

Expand Down
8 changes: 5 additions & 3 deletions integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package integration_test
import (
"context"
"os/exec"
"runtime"
"testing"
"time"

Expand All @@ -23,10 +24,10 @@ import (
var (

// The actual one is 4
serverGameTick = 3 * time.Second
serverGameTick = time.Second / 2

// The actual one is 60
clientTPS = time.Second / 50
clientTPS = time.Second / 30
)

func TestRun(t *testing.T) {
Expand Down Expand Up @@ -63,7 +64,6 @@ func TestRun(t *testing.T) {
Store: s,
}

//i := inputer.NewEbiten()
i := mock.NewMockInputer(ctrl)

cs := client.NewCameraStore(cd, s, screenW, screenH)
Expand Down Expand Up @@ -174,6 +174,7 @@ func TestRun(t *testing.T) {

wait()
resetDefault()
wait(serverGameTick)

for _, p := range rooms.GetState().(server.RoomsState).Rooms[room].Game.Players.GetPlayers() {
if p.Name == p1n {
Expand Down Expand Up @@ -201,5 +202,6 @@ func wait(d ...time.Duration) {
if len(d) == 0 {
d = []time.Duration{clientTPS}
}
runtime.Gosched()
time.Sleep(d[0])
}

0 comments on commit 018fa0a

Please sign in to comment.