Skip to content

Commit 7bfce0b

Browse files
chore: update GitHub Actions workflows and improve test coverage (#612)
* chore: update GitHub Actions workflows and improve test coverage * upload test results in a different step * chore: update golangci-lint version and enhance error handling across multiple files * chore: update linter configurations and improve code formatting in tests * chore: update exec command usage to use context for better control * chore: add JUnit file support for test results and update test command * chore: remove unused fs import and validate log file path in getFileHandler
1 parent 4d2a7b5 commit 7bfce0b

42 files changed

Lines changed: 140 additions & 95 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ jobs:
3737
cache: true
3838

3939
- name: golangci-lint
40-
uses: golangci/golangci-lint-action@v8
40+
uses: golangci/golangci-lint-action@v9
4141
with:
42-
version: v2.9.0
42+
version: v2.11.4
4343
args: --timeout=30m
4444

4545
- name: Test
@@ -50,12 +50,21 @@ jobs:
5050
- name: Build
5151
run: make build
5252

53-
- name: Code coverage with codecov
53+
- name: Upload code coverage to Codecov
5454
uses: codecov/codecov-action@v6
5555
with:
5656
env_vars: OS,GO
57-
files: ./coverage.out
57+
files: ./coverage.out,./unit-tests.xml
5858
flags: unittests
5959
fail_ci_if_error: false
6060
verbose: true
6161
token: ${{ secrets.CODECOV_TOKEN }}
62+
63+
- name: Upload test results to Codecov
64+
if: ${{ !cancelled() }}
65+
uses: codecov/codecov-action@v6
66+
with:
67+
env_vars: OS,GO
68+
token: ${{ secrets.CODECOV_TOKEN }}
69+
report_type: test_results
70+
files: ./unit-tests.xml

.github/workflows/docker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ jobs:
3131
uses: docker/setup-qemu-action@v3
3232

3333
- name: Login to DockerHub
34-
uses: docker/login-action@v3
34+
uses: docker/login-action@v4
3535
with:
3636
username: ${{ secrets.DOCKERHUB_USERNAME }}
3737
password: ${{ secrets.DOCKERHUB_TOKEN }}
3838

3939
- name: Login to GitHub Container Registry
40-
uses: docker/login-action@v3
40+
uses: docker/login-action@v4
4141
with:
4242
registry: ghcr.io
4343
username: ${{ github.actor }}

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ jobs:
2727
uses: docker/setup-qemu-action@v3
2828

2929
- name: Login to DockerHub
30-
uses: docker/login-action@v3
30+
uses: docker/login-action@v4
3131
with:
3232
username: ${{ secrets.DOCKERHUB_USERNAME }}
3333
password: ${{ secrets.DOCKERHUB_TOKEN }}
3434

3535
- name: Login to GitHub Container Registry
36-
uses: docker/login-action@v3
36+
uses: docker/login-action@v4
3737
with:
3838
registry: ghcr.io
3939
username: ${{ github.actor }}

.github/workflows/snapshot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ jobs:
2626
uses: docker/setup-qemu-action@v3
2727

2828
- name: Login to DockerHub
29-
uses: docker/login-action@v3
29+
uses: docker/login-action@v4
3030
with:
3131
username: ${{ secrets.DOCKERHUB_USERNAME }}
3232
password: ${{ secrets.DOCKERHUB_TOKEN }}
3333

3434
- name: Login to GitHub Container Registry
35-
uses: docker/login-action@v3
35+
uses: docker/login-action@v4
3636
with:
3737
registry: ghcr.io
3838
username: ${{ github.actor }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# test output
1717
/coverage.out
18+
/unit-tests.xml
1819

1920
# mock binaries
2021
/mock

.golangci.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ linters:
1010
- contextcheck
1111
- copyloopvar
1212
- decorder
13+
- dupl
1314
- durationcheck
1415
# - err113
1516
- errcheck
1617
- errchkjson
1718
- errname
18-
# - errorlint
19+
- errorlint
1920
- exptostd
2021
- fatcontext
2122
# - forcetypeassert
@@ -32,7 +33,7 @@ linters:
3233
- importas
3334
- inamedparam
3435
- ineffassign
35-
# - intrange
36+
- intrange
3637
# - ireturn
3738
- loggercheck
3839
- makezero
@@ -42,7 +43,7 @@ linters:
4243
- nilnesserr
4344
- nilnil
4445
# - nlreturn
45-
# - noctx
46+
- noctx
4647
- nolintlint
4748
- nosprintfhostport
4849
# - perfsprint
@@ -80,6 +81,12 @@ linters:
8081
- third_party$
8182
- builtin$
8283
- examples$
84+
rules:
85+
# Exclude some linters from running on tests files.
86+
- path: _test\.go
87+
linters:
88+
- dupl
89+
- gosec
8390
formatters:
8491
exclusions:
8592
generated: lax

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ README=README.md
2828

2929
TESTS=./...
3030
COVERAGE_FILE=coverage.out
31+
JUNIT_FILE=unit-tests.xml
3132

3233
BUILD=build/
3334

@@ -98,7 +99,7 @@ $(GOBIN)/mockery: verify $(GOBIN)/eget
9899

99100
$(GOBIN)/golangci-lint-v2: verify $(GOBIN)/eget
100101
@echo "[*] $@"
101-
"$(GOBIN)/eget" golangci/golangci-lint --tag v2.9.0 --asset=tar.gz --upgrade-only --to '$(GOBIN)/golangci-lint-v2'
102+
"$(GOBIN)/eget" golangci/golangci-lint --tag v2.11.4 --asset=tar.gz --upgrade-only --to '$(GOBIN)/golangci-lint-v2'
102103

103104
$(GOBIN)/hugo: $(GOBIN)/eget
104105
@echo "[*] $@"
@@ -108,6 +109,10 @@ $(GOBIN)/muffet: verify $(GOBIN)/eget
108109
@echo "[*] $@"
109110
"$(GOBIN)/eget" raviqqe/muffet --upgrade-only --to '$(GOBIN)'
110111

112+
$(GOBIN)/gotestsum: verify $(GOBIN)/eget
113+
@echo "[*] $@"
114+
"$(GOBIN)/eget" gotestyourself/gotestsum --upgrade-only --to '$(GOBIN)'
115+
111116
prepare_build: verify download
112117
@echo "[*] $@"
113118

@@ -173,9 +178,9 @@ test: prepare_test ## Run unit tests
173178
@echo "[*] $@"
174179
$(GOTEST) $(TESTS)
175180

176-
test-ci: prepare_test ## Run unit tests with coverage (for CI)
181+
test-ci: $(GOBIN)/gotestsum prepare_test ## Run unit tests with coverage (for CI)
177182
@echo "[*] $@"
178-
$(GOTEST) -v -race -short -coverprofile='coverage.out' ./...
183+
$(GOBIN)/gotestsum --junitfile $(JUNIT_FILE) -- -race -short -coverprofile='$(COVERAGE_FILE)' ./...
179184

180185
coverage: ## Generate coverage report
181186
@echo "[*] $@"
@@ -194,6 +199,7 @@ clean: ## Clean up the build artifacts
194199
$(BINARY_WINDOWS_AMD64) \
195200
$(BINARY_WINDOWS_ARM64) \
196201
$(COVERAGE_FILE) \
202+
$(JUNIT_FILE) \
197203
restic_*_linux_amd64* \
198204
${BUILD}restic* \
199205
${BUILD}rclone* \

batt/battery.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package batt
22

33
import (
4+
"errors"
45
"math"
56

67
"github.com/creativeprojects/clog"
@@ -46,28 +47,29 @@ func IsRunningOnBattery() (bool, int, error) {
4647

4748
// isFatalError returns an error if we can't detect any battery state
4849
func isFatalError(err error) error {
49-
switch perr := err.(type) {
50-
51-
case battery.ErrFatal: // complete failure
52-
return err
53-
54-
case battery.Errors: // range of errors per battery
55-
for _, err := range perr {
56-
if err != nil {
57-
err = isFatalError(err)
50+
{
51+
var perr battery.ErrFatal
52+
var perr1 battery.Errors
53+
var perr2 battery.ErrPartial
54+
switch {
55+
case errors.As(err, &perr):
56+
return err
57+
case errors.As(err, &perr1):
58+
for _, err := range perr1 {
5859
if err != nil {
59-
return err
60+
err = isFatalError(err)
61+
if err != nil {
62+
return err
63+
}
6064
}
6165
}
66+
return nil
67+
case errors.As(err, &perr2):
68+
if perr2.State != nil {
69+
return perr2.State
70+
}
71+
return nil
6272
}
63-
return nil
64-
65-
case battery.ErrPartial: // only some errors on one battery
66-
if perr.State != nil {
67-
return perr.State
68-
}
69-
// we're only interested in the state
70-
return nil
7173
}
7274

7375
return err

calendar/event_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func BenchmarkNextTrigger(b *testing.B) {
210210
event := NewEvent()
211211
_ = event.Parse(testItem.event)
212212
b.ResetTimer()
213-
for i := 0; i < b.N; i++ {
213+
for range b.N {
214214
next := event.Next(ref).String()
215215
if next == "" {
216216
b.Fail()

calendar/value.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (v *Value) HasContiguousRange() bool {
101101
return false
102102
}
103103

104-
for i := 0; i < v.maxRange-v.minRange; i++ {
104+
for i := range v.maxRange - v.minRange {
105105
if v.rangeValues[i] && v.rangeValues[i+1] {
106106
return true
107107
}
@@ -115,7 +115,7 @@ func (v *Value) HasLongContiguousRange() bool {
115115
return false
116116
}
117117

118-
for i := 0; i < v.maxRange-v.minRange-1; i++ {
118+
for i := range v.maxRange - v.minRange - 1 {
119119
if v.rangeValues[i] && v.rangeValues[i+1] && v.rangeValues[i+2] {
120120
return true
121121
}

0 commit comments

Comments
 (0)