Skip to content
This repository was archived by the owner on Mar 2, 2022. It is now read-only.

Commit

Permalink
Some cleanup on UI and update goreleaser and github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jlarfors committed Sep 4, 2021
1 parent 86b5496 commit 8dbd2bb
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 54 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,33 @@ on:
# run this workflow on main branch or a PR
push:
branches:
- main
- "**"
pull_request:
branches:
- "**"

name: simple
jobs:
simple:
frontend:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
working-directory: ./ui
- run: npm run build --if-present
working-directory: ./ui
backend:
strategy:
# matrix lets us expand our range of OSs / go
matrix:
go-version: [1.16.2]
go-version: [1.17]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
3 changes: 0 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
project_name: bubbly
before:
hooks:
- go get -u github.com/swaggo/swag/cmd/swag
builds:
- binary: bubbly
main: main.go
Expand Down
12 changes: 5 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package main

import (
"embed"
"os"

"github.com/valocode/bubbly/cmd"
"github.com/valocode/bubbly/env"
"github.com/valocode/bubbly/ui"
)

var (
//go:embed ui/build ui/build/_app ui/build/_app/pages/*.js ui/build/_app/assets/pages/*.css
bubblyUI embed.FS
version = "dev"
commit = "dev"
date = "dev"
version = "dev"
commit = "dev"
date = "dev"
)

func main() {
// Set up the initial BubblyContext with config.Config defaults
bCtx := env.NewBubblyContext(
env.WithBubblyUI(&bubblyUI),
env.WithBubblyUI(&ui.Build),
env.WithVersion(&env.Version{
Version: version,
Commit: commit,
Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ func NewWithStore(bCtx *env.BubblyContext, store *store.Store) (*Server, error)
if bCtx.UI == nil {
return nil, fmt.Errorf("cannot run the bubbly UI with a nil filesystem")
}
subFS, err := fs.Sub(bCtx.UI, "ui/build")
buildDir, err := fs.Sub(bCtx.UI, "build")
if err != nil {
log.Fatalf("creating sub filesystem for ui: %s", err.Error())
}

ui := e.Group("/ui")
ui.Use(middleware.StaticWithConfig(middleware.StaticConfig{
Filesystem: http.FS(subFS),
Filesystem: http.FS(buildDir),
HTML5: true,
}))
}
Expand Down
44 changes: 5 additions & 39 deletions test/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/valocode/bubbly/ent/artifact"
"github.com/valocode/bubbly/ent/codeissue"
schema "github.com/valocode/bubbly/ent/schema/types"
"github.com/valocode/bubbly/ent/vulnerability"
"github.com/valocode/bubbly/integrations"
"github.com/valocode/bubbly/store/api"
)
Expand Down Expand Up @@ -95,40 +94,6 @@ func SaveSPDXData(client *ent.Client) error {
return nil
}

func SaveCVEData(client *ent.Client) error {
resp, err := integrations.FetchCVEs(integrations.DefaultCVEFetchOptions())
if err != nil {
return fmt.Errorf("error fetching CVEs: %w", err)
}
ctx := context.Background()
for _, vuln := range resp.Result.CVEItems {
var description string
// Get the english description
for _, d := range vuln.CVEItem.Description.DescriptionData {
if d.Lang == "en" {
description = d.Value
}
}
_, err := client.Vulnerability.Query().Where(
vulnerability.Vid(vuln.CVEItem.CVEDataMeta.ID),
).Only(ctx)
if err != nil {
if !ent.IsNotFound(err) {
return fmt.Errorf("error checking vulnerability: %w", err)
}
_, err = client.Vulnerability.Create().
SetVid(vuln.CVEItem.CVEDataMeta.ID).
SetDescription(description).
SetSeverityScore(float64(vuln.Impact.BaseMetricV3.CVSSV3.BaseScore)).
Save(ctx)
if err != nil {
return fmt.Errorf("error creating vulnerability: %w", err)
}
}
}
return nil
}

func CreateDummyData() []RepoData {
var repos []RepoData
for _, opt := range demoData {
Expand Down Expand Up @@ -213,15 +178,16 @@ func createRepoData(opt DemoRepoOptions) []ReleaseData {
SetTime(cTime),
}

var passAll = false
if rand.Intn(10) > 3 {
passAll = true
}
for j := 1; j <= opt.NumTests; j++ {
// Calculate the result based on the test case number. The higher
// the number, the more likely to fail
// Create a failChance percentage
failChance := (float64(j*100) / float64(opt.NumTests)) / 100.0
result := (float64(rand.Intn(100)) * failChance) <= 80.0
// if !result {
// fmt.Printf("Test Case will fail: %d\n", j)
// }
result := passAll || (float64(rand.Intn(100))*failChance) <= 80.0
run.TestCases = append(run.TestCases, &api.TestRunCase{
TestCaseModelCreate: *ent.NewTestCaseModelCreate().
SetName(fmt.Sprintf("test_case_%d", j)).
Expand Down
8 changes: 8 additions & 0 deletions ui/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build ui

package ui

import "embed"

//go:embed build build/_app build/_app/pages/*.js build/_app/assets/pages/*.css
var Build embed.FS
7 changes: 7 additions & 0 deletions ui/embed_dev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !ui

package ui

import "embed"

var Build embed.FS
3 changes: 3 additions & 0 deletions ui/tailwind-safelist.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
bg-green-100
bg-red-100
bg-yellow-100
bg-purple-100
bg-orange-100
bg-amber-100
bg-gray-100

bg-green-400
bg-red-400
bg-yellow-400
bg-purple-400
bg-orange-400
bg-amber-400
bg-gray-400

text-green-800
text-red-800
text-yellow-800
text-purple-800
Expand Down

0 comments on commit 8dbd2bb

Please sign in to comment.