Skip to content

Commit

Permalink
Merge pull request #11 from jamie1192/feature/unit-tests-ci
Browse files Browse the repository at this point in the history
Feature/unit tests ci
  • Loading branch information
jamieastley authored Jan 17, 2021
2 parents 8bf36fd + bc9e458 commit 1c771e3
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 9 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on: [push, pull_request]
name: Unit Tests
jobs:
test:
strategy:
matrix:
go-version: [ 1.14.x, 1.15.x ]
platform: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: go test ./...
21 changes: 12 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

var buildSucceeded = os.Getenv("BITRISE_BUILD_STATUS") == "0"

func buildStatusValue(ifSuccess, ifFailed string) string {
func getValueForBuildStatus(ifSuccess, ifFailed string, buildSucceeded bool) string {
if buildSucceeded || ifFailed == "" {
return ifSuccess
}
Expand All @@ -29,23 +29,25 @@ func optionalUserValue(defaultValue, userValue string) string {
return userValue
}

func newMessage(cfg config) Message {
func newMessage(cfg config, buildSuccessful bool) Message {
message := Message{}
message.Type = "MessageCard"
message.Context = "http://schema.org/extensions"
message.ThemeColor = buildStatusValue(
message.ThemeColor = getValueForBuildStatus(
cfg.SuccessThemeColor,
cfg.FailedThemeColor,
buildSuccessful,
)
message.Title = optionalUserValue(cfg.AppTitle, cfg.CardTitle)
message.Summary = buildStatusValue(
message.Summary = getValueForBuildStatus(
fmt.Sprintf("%s #%s succeeded", cfg.AppTitle, cfg.BuildNumber),
fmt.Sprintf("%s #%s failed", cfg.AppTitle, cfg.BuildNumber),
buildSuccessful,
)

// MessageCard sections
primarySection := buildPrimarySection(cfg)
factsSection := buildFactsSection(cfg)
factsSection := buildFactsSection(cfg, buildSuccessful)
message.Sections = []Section{primarySection, factsSection}

// MessageCard Actions
Expand All @@ -69,12 +71,13 @@ func buildPrimarySection(cfg config) Section {
}

// Builds a Section containing a list of Fact related to build status
func buildFactsSection(cfg config) Section {
func buildFactsSection(cfg config, buildSuccessful bool) Section {
buildStatusFact := Fact{
Name: "Build Status",
Value: buildStatusValue(
Value: getValueForBuildStatus(
fmt.Sprintf(`<span style="color:#%s">Success</span>`, cfg.SuccessThemeColor),
fmt.Sprintf(`<span style="color:#%s">Fail</span>`, cfg.FailedThemeColor),
buildSuccessful,
),
}

Expand Down Expand Up @@ -130,7 +133,7 @@ func postMessage(webhookURL string, msg Message, debugEnabled bool) error {
}
fmt.Println(fmt.Sprintf("Request to Microsoft Teams: %s", webhookURL))
if debugEnabled {
fmt.Println(fmt.Sprintf("JSON body: %s", b))
fmt.Println(fmt.Sprintf("JSON body: %s\n", b))
}

resp, err := http.Post(webhookURL, "application/json", bytes.NewReader(b))
Expand Down Expand Up @@ -162,7 +165,7 @@ func main() {
}
stepconf.Print(cfg)

message := newMessage(cfg)
message := newMessage(cfg, buildSucceeded)
if err := postMessage(cfg.WebhookURL, message, cfg.EnableDebug); err != nil {
fmt.Println(fmt.Sprintf("Error: %s", err))
os.Exit(1)
Expand Down
Loading

0 comments on commit 1c771e3

Please sign in to comment.