Skip to content

Commit

Permalink
fix: add continueOnError flag
Browse files Browse the repository at this point in the history
Signed-off-by: Eray Ates <eates23@gmail.com>
  • Loading branch information
rytsh committed Sep 28, 2023
1 parent 0909faa commit e9cb6b1
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 176 deletions.
47 changes: 0 additions & 47 deletions .github/workflows/golangci-lint.yml

This file was deleted.

15 changes: 3 additions & 12 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "Release"
on:
push:
tags:
- v*
- v[0-9]*

permissions:
contents: write
Expand All @@ -11,29 +11,20 @@ permissions:
jobs:
release:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
# stable: 'false' # Keep this line to be able to use rc and beta version of Go (ex: 1.18.0-rc1).
go-version: 1.18
go-version: 1.21.1
- name: Unshallow
run: git fetch --prune --unshallow

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create release
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --rm-dist
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50 changes: 35 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
name: Test

on: [push, pull_request]
on: [push]

name: Test
jobs:
test:
sonarcloud:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ secrets.GO_VERSION }}

- name: Run coverage
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage to Codecov
run: bash <(curl -s https://codecov.io/bash)
- name: get epository name
run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
- uses: actions/checkout@v2
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version: 1.21.1 # The Go version to download (if necessary) and use.
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
- name: Run tests
run: |
# [[ ! -f ".golangci.yml" ]] && curl -kfsSL -O https://raw.githubusercontent.com/worldline-go/guide/main/lint/.golangci.yml || true
GOPATH="$(dirname ${PWD})" golangci-lint run --out-format checkstyle ./... > golangci-lint-report.out || true
go test -coverprofile=coverage.out -json ./... > test-report.out
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
with:
args: >
-Dsonar.organization=${{ github.repository_owner }}
-Dsonar.projectKey=${{ github.repository_owner }}_${{ env.REPOSITORY_NAME }}
-Dsonar.go.coverage.reportPaths=coverage.out
-Dsonar.go.tests.reportPaths=test-report.out
-Dsonar.go.golangci-lint.reportPaths=golangci-lint-report.out
-Dsonar.sources=.
-Dsonar.exclusions=**/vendor/**,**/*_test.go
-Dsonar.tests=.
-Dsonar.test.inclusions=**/*_test.go
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
24 changes: 17 additions & 7 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
project_name: pong

release:
header: |
Get the latest release with brew or binary:
```sh
# curl -fSL https://github.com/worldline-go/pong/releases/latest/download/pong_Linux_x86_64.tar.gz | tar -xz --overwrite -C ~/bin/ pong
curl -fSL https://github.com/worldline-go/pong/releases/download/{{ .Tag }}/pong_Linux_x86_64.tar.gz | tar -xz --overwrite -C ~/bin/ pong
```
footer: |
**Full Changelog**: https://github.com/worldline-go/pong/compare/{{ .PreviousTag }}...{{ .Tag }}
before:
Expand All @@ -16,19 +23,22 @@ builds:
- linux
- windows
- darwin
goarch:
- amd64
- arm
- arm64
main: ./cmd/pong
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
flags:
- -trimpath
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
- name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
format_overrides:
- goos: windows
format: zip
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# PONG 🏓

[![Codecov](https://img.shields.io/codecov/c/github/worldline-go/pong?logo=codecov&style=flat-square)](https://app.codecov.io/gh/worldline-go/pong)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/worldline-go/pong/Test?logo=github&style=flat-square&label=ci)](https://github.com/worldline-go/pong/actions)
[![Go Reference](https://pkg.go.dev/badge/github.com/worldline-go/pong.svg)](https://pkg.go.dev/github.com/worldline-go/pong)
[![License](https://img.shields.io/github/license/worldline-go/pong?color=red&style=flat-square)](https://raw.githubusercontent.com/worldline-go/pong/main/LICENSE)
[![Coverage](https://img.shields.io/sonar/coverage/worldline-go_pong?logo=sonarcloud&server=https%3A%2F%2Fsonarcloud.io&style=flat-square)](https://sonarcloud.io/summary/overall?id=worldline-go_pong)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/worldline-go/pong/test.yml?branch=main&logo=github&style=flat-square&label=ci)](https://github.com/worldline-go/pong/actions)
[![Go Report Card](https://goreportcard.com/badge/github.com/worldline-go/pong?style=flat-square)](https://goreportcard.com/report/github.com/worldline-go/pong)

Pong status checker.

Expand All @@ -24,6 +25,7 @@ log_level: "debug"
client:
rest:
- concurrent: 1
continueOnError: false
setting:
# InsecureSkipVerify is the flag to skip the verification of the server's certificate chain and host name
insecureSkipVerify: false
Expand Down
77 changes: 26 additions & 51 deletions cmd/pong/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"flag"
"fmt"
"os"
"os/signal"
"strings"
"sync"
"syscall"

"github.com/rs/zerolog/log"
"github.com/worldline-go/initializer"
"github.com/worldline-go/logz"

"github.com/worldline-go/pong/internal/load"
Expand Down Expand Up @@ -46,9 +45,7 @@ func usage() {
os.Exit(0)
}

var (
flagVersion bool
)
var flagVersion bool

func flagParse() []string {
flag.Usage = usage
Expand All @@ -68,71 +65,47 @@ func flagParse() []string {
}

func main() {
logz.InitializeLog(nil)

files := flagParse()

exitCode := 0
wg := &sync.WaitGroup{}

defer func() {
wg.Wait()
os.Exit(exitCode)
}()

// check length of the arguments
if len(files) == 0 {
load.ResponseError(fmt.Errorf("missing argument file"))

exitCode = 1

return
initFn := Init{
files: files,
}

// start operation
chNotify := make(chan os.Signal, 1)

signal.Notify(chNotify, os.Interrupt, syscall.SIGTERM)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
initializer.Init(
initFn.run,
initializer.WithMsgf("pong [%s]", version),
initializer.WithOptionsLogz(logz.WithCaller(false)),
)
}

wg.Add(1)
type Init struct {
files []string
}

go func() {
defer wg.Done()
func (s Init) run(ctx context.Context, wg *sync.WaitGroup) error {
// check length of the arguments
if len(s.files) == 0 {
err := fmt.Errorf("missing argument file")
load.ResponseError(err)

select {
case <-ctx.Done():
return
case <-chNotify:
log.Info().Msg("shutting down...")
log.Info().Msg("send signal again to exit force")
signal.Stop(chNotify)
close(chNotify)
cancel()
}
}()
return err
}

var errRequests []error
// read config
for _, file := range files {
for _, file := range s.files {
args, err := load.ReadConfig(file)
if err != nil {
load.ResponseError(err)

exitCode = 1

return
return err
}

if len(args.Delimeters) >= 2 {
if err := template.SetDelimeters(args.Delimeters); err != nil {
load.ResponseError(err)

exitCode = 1

return
return err
}
}

Expand All @@ -148,7 +121,7 @@ func main() {
Failed: false,
})

return
return nil
}

var errStrings []string
Expand All @@ -161,4 +134,6 @@ func main() {
Msg: strings.Join(errStrings, " "),
Failed: true,
})

return nil
}
15 changes: 8 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/worldline-go/pong

go 1.18
go 1.21

require (
github.com/Masterminds/sprig/v3 v3.2.2
github.com/rs/zerolog v1.28.0
github.com/worldline-go/logz v0.1.0
github.com/rs/zerolog v1.30.0
github.com/worldline-go/initializer v0.2.0
github.com/worldline-go/logz v0.5.0
)

require (
Expand All @@ -18,12 +19,12 @@ require (
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 // indirect
golang.org/x/crypto v0.11.0 // indirect
)

require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
golang.org/x/sys v0.10.0 // indirect
gopkg.in/yaml.v3 v3.0.1
)
Loading

0 comments on commit e9cb6b1

Please sign in to comment.