Compare commits

...

11 Commits
v0.3.3 ... main

Author SHA1 Message Date
github-actions[bot] 43c38d47d1 go mod tidy 2022-11-20 18:01:42 +00:00
renovate[bot] 1345795c05 fix(deps): update module github.com/sirupsen/logrus to v1.9.0 2022-11-20 18:01:18 +00:00
github-actions[bot] 5d197234fd gofmt 2021-10-24 12:51:17 +00:00
Oskar 1cb931d9ef
chore: new tests
* Create bytes_test.go
* Create cpu_test.go
* Create memory_test.go
* Create uptime_test.go
2021-10-24 14:50:52 +02:00
Oskar df1b532e2a
Create codeql-analysis.yml 2021-10-24 14:11:36 +02:00
Oskar a557f452a7
feat(log): SetReportCaller to true
example output:
INFO[0000]/home/trex/go/src/awesomeProject/main.go:11 main.main() hello world  

from https://stackoverflow.com/a/68301267
2021-10-21 23:18:24 +02:00
Oskar b6fc96d90a
ci: update workflows (#3)
* Update ci.yml
* Delete auto-fix.yml
2021-10-21 23:09:46 +02:00
Medzik 857ddb66b0 feat(common): add retry function 2021-09-04 11:37:07 +00:00
Medzik 2006d90d17 update 2021-08-22 12:16:39 +02:00
Oskar ce20c581e9
Update auto-fix.yml 2021-08-20 22:43:02 +02:00
Medzik b4526de784 update workflows 2021-08-19 18:18:31 +00:00
16 changed files with 181 additions and 39 deletions

View File

@ -1,16 +1,21 @@
name: auto fix
name: CI
on:
push:
branches:
- main
pull_request:
jobs:
auto-fix:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Repo clone (go mod tidy / gofmt)
if: github.event_name != 'pull_request'
uses: actions/checkout@v2
with:
persist-credentials: false
fetch-depth: 0
- name: Set up Go
@ -19,27 +24,46 @@ jobs:
go-version: 1.17
- name: Setup Git
if: github.event_name != 'pull_request'
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: tidy
- name: Tidy
if: github.event_name != 'pull_request'
run: |
go mod tidy
git add .
git diff-index --quiet HEAD || git commit -m "go mod tidy"
- name: gofmt
- name: GoFmt
if: github.event_name != 'pull_request'
run: |
go fmt ./...
git add .
git diff-index --quiet HEAD || git commit -m "gofmt"
- name: Pull changes
if: github.event_name != 'pull_request'
run: git pull -r
- name: Push changes
if: github.event_name != 'pull_request'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: Repo clone (test)
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Test
run: go test -v ./...
- name: Semantic Release
if: github.event_name != 'pull_request'
uses: go-semantic-release/action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

45
.github/workflows/codeql-analysis.yml vendored Normal file
View File

@ -0,0 +1,45 @@
name: "CodeQL"
on:
push:
branches:
pull_request:
branches:
schedule:
- cron: '42 7 * * 0'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

View File

@ -1,19 +0,0 @@
name: test
on:
push:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Test
run: go test -v ./...

1
.gitignore vendored
View File

@ -8,7 +8,6 @@
# Binaries
*.exe
*.exe~
*.out
*.test
/dist/

View File

@ -25,3 +25,7 @@ var Log = &logrus.Logger{
Hooks: make(logrus.LevelHooks),
Level: logrus.InfoLevel,
}
func init() {
Log.SetReportCaller(true)
}

37
common/retry.go Normal file
View File

@ -0,0 +1,37 @@
package common
import (
"fmt"
"time"
)
/*
If there is an error in the performed function, it will be restarted, this process will be repeated the given number of times
e.g.
err := Retry(3, 5*time.Second, connectToDB)
if err != nil {
Log.Error(err)
}
*/
func Retry(attempts int, sleep time.Duration, f func() error) (err error) {
for i := 0; ; i++ {
err = f()
if err == nil {
return
}
if i >= (attempts - 1) {
break
}
time.Sleep(sleep)
sleep *= 2
Log.Error("Retrying after error: ", err)
}
return fmt.Errorf("after %d attempts, last error: %s", attempts, err)
}

12
common/uptime_test.go Normal file
View File

@ -0,0 +1,12 @@
package common
import (
"fmt"
"testing"
"time"
)
func TestCheckUptime(T *testing.T) {
uptime := Uptime(time.Date(2016, 6, 2, 1, 1, 1, 1, time.UTC))
fmt.Println(uptime)
}

5
go.mod
View File

@ -5,8 +5,7 @@ go 1.16
require (
github.com/MedzikUser/go-github-selfupdate v1.3.1
github.com/blang/semver/v4 v4.0.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.0
github.com/struCoder/pidusage v0.2.1
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)

15
go.sum
View File

@ -24,12 +24,11 @@ github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/struCoder/pidusage v0.2.1 h1:dFiEgUDkubeIj0XA1NpQ6+8LQmKrLi7NiIQl86E6BoY=
github.com/struCoder/pidusage v0.2.1/go.mod h1:bewtP2KUA1TBUyza5+/PCpSQ6sc/H6jJbIKAzqW86BA=
github.com/tcnksm/go-gitconfig v0.1.2 h1:iiDhRitByXAEyjgBqsKi9QU4o2TNtv9kPP3RgPgXBPw=
@ -51,8 +50,8 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
@ -68,3 +67,5 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

3
main.go Normal file
View File

@ -0,0 +1,3 @@
package main
func main() {}

10
stats/cpu_test.go Normal file
View File

@ -0,0 +1,10 @@
package stats
import "testing"
func TestCPU(t *testing.T) {
_, err := CPU()
if err != nil {
t.Fatal(err)
}
}

7
stats/memory_test.go Normal file
View File

@ -0,0 +1,7 @@
package stats
import "testing"
func TestMemory(t *testing.T) {
Memory()
}

View File

@ -14,7 +14,7 @@ import (
func (c *Client) AutoUpdater() {
// Check on start
err := c.Update()
common.CheckErr(err, "AutoUpdater")
common.CheckErr(err, "Auto Updater")
ticker := time.NewTicker(c.CheckEvery)
@ -24,7 +24,7 @@ func (c *Client) AutoUpdater() {
select {
case <-ticker.C:
err := c.Update()
common.CheckErr(err, "AutoUpdater")
common.CheckErr(err, "Auto Updater")
case <-quit:
ticker.Stop()

View File

@ -23,6 +23,6 @@ type Client struct {
// Update Rules
// X.y.z
// Should I update the major? (X.y.z)
Major bool
}

View File

@ -17,6 +17,9 @@ func (c *Client) Update() error {
updater, err := selfupdate.NewUpdater(selfupdate.Config{
APIToken: c.GitHubToken,
})
if err != nil {
return err
}
release, found, err := updater.DetectLatest(c.GitHub)
if err != nil {

17
utils/bytes_test.go Normal file
View File

@ -0,0 +1,17 @@
package utils
import "testing"
func TestBytes(t *testing.T) {
// 1
r := Bytes(53)
if r != "53 B" {
t.Fatal(r)
}
// 2
r = Bytes(1522)
if r != "1.5 kB" {
t.Fatal(r)
}
}