Skip to content

Commit

Permalink
chore: improve battle tests (#159)
Browse files Browse the repository at this point in the history
* chore: improve battle tests

* fix: pick up the top 2k repo per language

* chore: include language to the report

* fix: document is independant to the language but rest is
  • Loading branch information
cfabianski committed Nov 23, 2022
1 parent 10e2312 commit 4f3d2cc
Show file tree
Hide file tree
Showing 16 changed files with 48,972 additions and 222,048 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/battle_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@ on:
- 25
- 100

language:
description: "Language you want to process"
required: true
default: "all"
type: choice
options:
- "all"
- "javascript"
- "typescript"
- "ruby"
- "php"
- "c_sharp"
- "go"
- "python"
- "java"
- "crm"

attempt:
description: "Attempt (if you need to re-trigger for the same curio version)"
required: true
default: "1"
type: string

curio_version:
description: "Version of curio to pick up (`tags/<tag_name>`, `<release_id>` or `latest`)"
default: "latest"
required: true
type: string

permissions:
contents: write
packages: write
Expand Down Expand Up @@ -47,6 +76,7 @@ jobs:
uses: dsaltares/fetch-gh-release-asset@1.1.0
with:
repo: "Bearer/curio"
version: ${{ input.curio_version }}
# version: "tags/v0.5.0"
# file: "curio_0.5.0_linux_amd64.tar.gz"
regex: true
Expand All @@ -69,6 +99,8 @@ jobs:
build-args: |
CURIO_VERSION=${{ steps.latest_artifact.outputs.version }}
BATTLE_TEST_SHA=${{ github.sha }}
ATTEMPT=${{ input.attempt }}
LANGUAGE=${{ input.language }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand Down
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/battle_tests/build.CurioVersion=${CURIO_VERSION}' -X 'github.com/bearer/curio/battle_tests/build.BattleTestSHA=${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}' -X 'github.com/bearer/curio/battle_tests/build.Attempt=${ATTEMPT}' -X 'github.com/bearer/curio/battle_tests/build.Language=${Language}'" \
-a -o dist/battle_tests ./battle_tests/battle_tests.go

# FROM alpine
Expand Down
2 changes: 2 additions & 0 deletions battle_tests/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ var (
// These should be set via go build -ldflags -X 'xxxx'.
CurioVersion = "dev"
BattleTestSHA = "devSHA"
Attempt = "1"
Language = "all"
)
36 changes: 22 additions & 14 deletions battle_tests/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"

"github.com/bearer/curio/battle_tests/build"
"github.com/rs/zerolog/log"
)

Expand All @@ -22,15 +23,25 @@ type Item struct {
HtmlUrl string `json:"html_url" yaml:"html_url"`
}

func UnmarshalRaw() []Item {
items := []Item{}
type ItemWithLanguage struct {
FullName string `json:"full_name" yaml:"full_name"`
HtmlUrl string `json:"html_url" yaml:"html_url"`
Language string `json:"language" yaml:"language"`
}

func UnmarshalRaw() []ItemWithLanguage {
items := []ItemWithLanguage{}

files, err := githubDir.ReadDir("github")
if err != nil {
log.Fatal().Err(fmt.Errorf("unable to open directory %e", err)).Send()
}

for _, file := range files {
if build.Language != "all" && file.Name() != build.Language {
continue
}

val, err := githubDir.ReadFile("github/" + file.Name())
if err != nil {
log.Fatal().Err(fmt.Errorf("unable to open file %e", err)).Send()
Expand All @@ -43,19 +54,16 @@ func UnmarshalRaw() []Item {
log.Fatal().Err(fmt.Errorf("unable to unmarshal %e", err)).Send()
}

items = append(items, category.Items...)
}
for _, item := range category.Items {
newItem := ItemWithLanguage{
HtmlUrl: item.HtmlUrl,
FullName: item.FullName,
Language: category.Language,
}

return items
}

func Unmarshal(rawBytes []byte) Category {
var category Category

err := json.Unmarshal(rawBytes, &category)
if err != nil {
log.Fatal().Err(fmt.Errorf("failed to unmarshal category file %e", err)).Send()
items = append(items, newItem)
}
}

return category
return items
}
Loading

0 comments on commit 4f3d2cc

Please sign in to comment.