Skip to content

Commit

Permalink
chore: use dedicated build for battle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cfabianski committed Nov 18, 2022
1 parent a13e996 commit ae57e1c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 19 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/battle_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ jobs:
uses: dsaltares/fetch-gh-release-asset@1.1.0
with:
repo: "Bearer/curio"
# version: defaults to latest
version: "tags/v0.5.0"
file: "curio_0.5.0_linux_amd64.tar.gz"
# version: "tags/v0.5.0"
# file: "curio_0.5.0_linux_amd64.tar.gz"
regex: true
file: "curio_.*_linux_amd64\\.tar\\.gz"

- name: Extract artifact
run: |
tar -xzvf curio_0.5.0_linux_amd64.tar.gz
tar -xzvf curio_*_linux_amd64.tar.gz
ls -ltr
mkdir dist
cp curio dist/
Expand Down Expand Up @@ -82,4 +83,4 @@ jobs:
TASK_DEFINITION: ${{ secrets.TASK_DEFINITION }}
SUBNET: ${{ secrets.SUBNET }}
SECURITY_GROUP: ${{ secrets.SECURITY_GROUP }}
CONCURRENT_TASKS: 5
CONCURRENT_TASKS: 1
2 changes: 1 addition & 1 deletion battle_tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WORKDIR /app

# RUN apk update && apk upgrade && apk add --no-cache build-base git

RUN go build -ldflags="-X 'github.com/bearer/curio/cmd/curio/build.Version=${CURIO_VERSION}' -X 'github.com/bearer/curio/cmd/curio/build.CommitSHA=${BATTLE_TEST_SHA}'" \
RUN go build -ldflags="-X 'github.com/bearer/curio/battle_tests/build.CurioVersion=${CURIO_VERSION}' -X 'github.com/bearer/curio/battle_tests/build.BattleTestSHA=${BATTLE_TEST_SHA}'" \
-a -o dist/battle_tests ./battle_tests/battle_tests.go

# FROM alpine
Expand Down
5 changes: 3 additions & 2 deletions battle_tests/battle_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"os/signal"
"syscall"

"github.com/bearer/curio/battle_tests/build"
"github.com/bearer/curio/battle_tests/config"
"github.com/bearer/curio/battle_tests/db"
"github.com/bearer/curio/battle_tests/rediscli"
"github.com/bearer/curio/battle_tests/sheet"
"github.com/bearer/curio/battle_tests/sync"
"github.com/bearer/curio/cmd/curio/build"
)

type CurioVersion struct {
Expand All @@ -29,7 +29,8 @@ func main() {
log.Debug().Msgf("failed to init redis")
}

log.Printf("version %s", build.Version)
log.Debug().Msgf("curio version %s", build.CurioVersion)
log.Debug().Msgf("battle tests SHA %s", build.BattleTestSHA)

shutdown := make(chan os.Signal, 1)
signal.Notify(shutdown, os.Interrupt)
Expand Down
7 changes: 7 additions & 0 deletions battle_tests/build/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package build

var (
// These should be set via go build -ldflags -X 'xxxx'.
CurioVersion = "dev"
BattleTestSHA = "devSHA"
)
16 changes: 8 additions & 8 deletions battle_tests/rediscli/rediscli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package rediscli
import (
"errors"

"github.com/bearer/curio/battle_tests/build"
"github.com/bearer/curio/battle_tests/config"
"github.com/bearer/curio/cmd/curio/build"
"github.com/go-redis/redis"
)

Expand All @@ -19,19 +19,19 @@ func Setup() {
}

func WorkerOnline() (int64, error) {
key := build.Version + "_workers_online_" + build.CommitSHA
key := build.CurioVersion + "_workers_online_" + build.BattleTestSHA
cmd := cli.Incr(key)
return cmd.Result()
}

func WorkerOffline() (int64, error) {
key := build.Version + "_workers_online_" + build.CommitSHA
key := build.CurioVersion + "_workers_online_" + build.BattleTestSHA
cmd := cli.Decr(key)
return cmd.Result()
}

func SetDocument(documentID string) error {
key := build.Version + "_sheet_document_" + build.CommitSHA
key := build.CurioVersion + "_sheet_document_" + build.BattleTestSHA
cmd := cli.Set(key, documentID, 0)
result, err := cmd.Result()
if result != "OK" {
Expand All @@ -41,7 +41,7 @@ func SetDocument(documentID string) error {
}

func GetDocument() (string, error) {
key := build.Version + "_sheet_document_" + build.CommitSHA
key := build.CurioVersion + "_sheet_document_" + build.BattleTestSHA
cmd := cli.Get(key)
return cmd.Result()
}
Expand All @@ -51,15 +51,15 @@ func Init() error {
return nil
}

key := build.Version + "_work_assigned_" + build.CommitSHA
key := build.CurioVersion + "_work_assigned_" + build.BattleTestSHA
cmd := cli.Set(key, 0, 0)
_, err := cmd.Result()

if err != nil {
return err
}

key = build.Version + "_workers_online_" + build.CommitSHA
key = build.CurioVersion + "_workers_online_" + build.BattleTestSHA
cmd = cli.Set(key, 0, 0)
_, err = cmd.Result()

Expand All @@ -71,7 +71,7 @@ func Init() error {
}

func PickUpWork() (int, error) {
key := build.Version + "_work_assigned_" + build.CommitSHA
key := build.CurioVersion + "_work_assigned_" + build.BattleTestSHA
cmd := cli.Incr(key)
counter, err := cmd.Result()
return int(counter), err
Expand Down
6 changes: 3 additions & 3 deletions battle_tests/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"time"

"github.com/bearer/curio/battle_tests/build"
"github.com/bearer/curio/battle_tests/config"
repodb "github.com/bearer/curio/battle_tests/db"
metricsscan "github.com/bearer/curio/battle_tests/metrics_scan"
"github.com/bearer/curio/battle_tests/rediscli"
"github.com/bearer/curio/battle_tests/sheet"
"github.com/bearer/curio/cmd/curio/build"
"github.com/rs/zerolog/log"
)

Expand All @@ -21,8 +21,8 @@ func GetDocumentID(sheetClient *sheet.GoogleSheets) (documentID string, err erro
}

if workerCount == 1 {
log.Debug().Msgf("workerCount is 1... creating document %s in %s", build.Version, config.Runtime.Drive.ParentFolderId)
doc := sheetClient.CreateDocument(build.Version, config.Runtime.Drive.ParentFolderId)
log.Debug().Msgf("workerCount is 1... creating document %s in %s", build.CurioVersion, config.Runtime.Drive.ParentFolderId)
doc := sheetClient.CreateDocument(build.CurioVersion, config.Runtime.Drive.ParentFolderId)

log.Debug().Msgf("doc %s", doc.ID)
err = rediscli.SetDocument(doc.ID)
Expand Down

0 comments on commit ae57e1c

Please sign in to comment.