Skip to content

Commit

Permalink
Merge pull request #95 from replicatedhq/github-actions
Browse files Browse the repository at this point in the history
GitHub actions
  • Loading branch information
marccampbell committed Dec 18, 2019
2 parents ca9106e + 1757af5 commit 4338b22
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 5 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/preflight.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Run preflights on a cluster"
on: [push]

jobs:
compile-preflight:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v1
with:
go-version: '1.12.14'
- name: setup env
run: |
echo "::set-env name=GOPATH::$(go env GOPATH)"
echo "::add-path::$(go env GOPATH)/bin"
shell: bash
- uses: actions/checkout@master
- run: make preflight
- uses: actions/upload-artifact@v1
with:
name: preflight
path: bin/preflight

run-preflights:
runs-on: ubuntu-latest
needs: compile-preflight
steps:
- name: Download preflight binary
uses: actions/download-artifact@v1
with:
name: preflight
path: bin/
- uses: engineerd/setup-kind@v0.2.0
- run: chmod +x bin/preflight
- run: bin/preflight --interactive=false --format=json https://preflight.replicated.com

2 changes: 1 addition & 1 deletion cmd/preflight/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func runPreflights(v *viper.Viper, arg string) error {
return showInteractiveResults(preflight.Name, analyzeResults)
}

return showStdoutResults(preflight.Name, analyzeResults)
return showStdoutResults(v.GetString("format"), preflight.Name, analyzeResults)
}

func runCollectors(v *viper.Viper, preflight troubleshootv1beta1.Preflight) (map[string][]byte, error) {
Expand Down
60 changes: 56 additions & 4 deletions cmd/preflight/cli/stdout_results.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package cli

import (
"encoding/json"
"fmt"

"github.com/pkg/errors"
analyzerunner "github.com/replicatedhq/troubleshoot/pkg/analyze"
)

func showStdoutResults(preflightName string, analyzeResults []*analyzerunner.AnalyzeResult) error {
fmt.Printf("\n=== TEST %s\n", preflightName)
for _, analyzeResult := range analyzeResults {
fmt.Printf("=== RUN: %s\n", analyzeResult.Title)
func showStdoutResults(format string, preflightName string, analyzeResults []*analyzerunner.AnalyzeResult) error {
if format == "human" {
return showStdoutResultsHuman(preflightName, analyzeResults)
} else if format == "json" {
return showStdoutResultsJSON(preflightName, analyzeResults)
}

return errors.Errorf("unknown output format: %q", format)
}

func showStdoutResultsHuman(preflightName string, analyzeResults []*analyzerunner.AnalyzeResult) error {
var failed bool
for _, analyzeResult := range analyzeResults {
testResultfailed := outputResult(analyzeResult)
Expand All @@ -28,6 +36,50 @@ func showStdoutResults(preflightName string, analyzeResults []*analyzerunner.Ana
return nil
}

func showStdoutResultsJSON(preflightName string, analyzeResults []*analyzerunner.AnalyzeResult) error {
type ResultOutput struct {
Title string `json:"title"`
Message string `json:"message"`
URI string `json:"uri,omitempty"`
}
type Output struct {
Pass []ResultOutput `json:"pass,omitempty"`
Warn []ResultOutput `json:"warn,omitempty"`
Fail []ResultOutput `json:"fail,omitempty"`
}

output := Output{
Pass: []ResultOutput{},
Warn: []ResultOutput{},
Fail: []ResultOutput{},
}

for _, analyzeResult := range analyzeResults {
resultOutput := ResultOutput{
Title: analyzeResult.Title,
Message: analyzeResult.Message,
URI: analyzeResult.URI,
}

if analyzeResult.IsPass {
output.Pass = append(output.Pass, resultOutput)
} else if analyzeResult.IsWarn {
output.Warn = append(output.Warn, resultOutput)
} else if analyzeResult.IsFail {
output.Fail = append(output.Fail, resultOutput)
}
}

b, err := json.MarshalIndent(output, "", " ")
if err != nil {
return errors.Wrap(err, "failed to marshal results")
}

fmt.Printf("%s\n", b)

return nil
}

func outputResult(analyzeResult *analyzerunner.AnalyzeResult) bool {
if analyzeResult.IsPass {
fmt.Printf(" --- PASS %s\n", analyzeResult.Title)
Expand Down

0 comments on commit 4338b22

Please sign in to comment.