From 3769f66567d004768d770083fa9fffd255167234 Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 12:18:46 +0545 Subject: [PATCH 01/19] Create workflow --- .github/workflows/go.yml | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..f1fe0bc --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,48 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: + push: + pull_request: + branches: [ "main" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21.0' + + - name: Install dependencies + run: go get . + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v -cover ./... + + - name: Export Test Results + run: go test -json > TestResults.json + + - name: Upload Go test results + uses: actions/upload-artifact@v3 + with: + name: Test-results + path: TestResults.json + + - name: Get Coverage Report + uses: ncruces/go-coverage-report@v0 + with: + report: 'true' + chart: 'true' + amend: 'false' + if: github.event_name == 'push' + continue-on-error: true From 2ebd97dbb96c91fa9f6cba2f9df2049c104e1b11 Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 15:26:21 +0545 Subject: [PATCH 02/19] lint: Disable testpackage since disabled in all --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index e953fcd..d6c954e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -243,7 +243,6 @@ linters: - stylecheck # is a replacement for golint - tenv # detects using os.Setenv instead of t.Setenv since Go1.17 - testableexamples # checks if examples are testable (have an expected output) - - testpackage # makes you use a separate _test package - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes - unconvert # removes unnecessary type conversions - unparam # reports unused function parameters @@ -252,6 +251,7 @@ linters: - whitespace # detects leading and trailing whitespace ## you may want to enable + #- testpackage # makes you use a separate _test package #- decorder # checks declaration order and count of types, constants, variables and functions #- exhaustruct # [highly recommend to enable] checks if all structure fields are initialized #- gci # controls golang package import order and makes it always deterministic From ce2337469ce93b57d9faf8a81f8e1bb05895062d Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 15:26:34 +0545 Subject: [PATCH 03/19] lint: remove unncessary nolint --- lumberjack_test.go | 1 - rotate_test.go | 1 - slogrotate_test.go | 1 - 3 files changed, 3 deletions(-) diff --git a/lumberjack_test.go b/lumberjack_test.go index ece6d75..85be7ec 100644 --- a/lumberjack_test.go +++ b/lumberjack_test.go @@ -1,4 +1,3 @@ -//nolint:testpackage // use same name as package to access variables to mock package lumberjack import ( diff --git a/rotate_test.go b/rotate_test.go index 27a28a8..24f4ffd 100644 --- a/rotate_test.go +++ b/rotate_test.go @@ -1,4 +1,3 @@ -//nolint:testpackage // use same name as package to access variables to mock package lumberjack import ( diff --git a/slogrotate_test.go b/slogrotate_test.go index 63f496e..f3d0bfc 100644 --- a/slogrotate_test.go +++ b/slogrotate_test.go @@ -1,4 +1,3 @@ -//nolint:testpackage // use same name as package to access variables to mock package lumberjack import ( From 1e1b4cdf9f51c68b7aa879c171824cf2e059360a Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 15:27:08 +0545 Subject: [PATCH 04/19] fix: stop acquiring mutex to prevent deadlock --- lumberjack.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/lumberjack.go b/lumberjack.go index 1a61b34..27fa1c9 100644 --- a/lumberjack.go +++ b/lumberjack.go @@ -364,9 +364,6 @@ func (l *Logger) millRunOnce() error { // the max number of backups and the max age configured // for the old log files present in the log directory. func (l *Logger) filesToRemoveAndKeep(oldLogFiles []logInfo) ([]logInfo, []logInfo) { - l.mu.Lock() - defer l.mu.Unlock() - var filesToRemove []logInfo filesToKeep := oldLogFiles From 6c8c8364643246c1db7b46957d08ab7c95a618b7 Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 15:27:27 +0545 Subject: [PATCH 05/19] feat: support chown on darwin --- chown.go | 4 +- chown_linux.go => chown_goos.go | 12 +++- linux_test.go => chown_test.go | 112 ++++++++++++++++++-------------- 3 files changed, 75 insertions(+), 53 deletions(-) rename chown_linux.go => chown_goos.go (58%) rename linux_test.go => chown_test.go (60%) diff --git a/chown.go b/chown.go index 948f989..d62decb 100644 --- a/chown.go +++ b/chown.go @@ -1,5 +1,5 @@ -//go:build !linux -// +build !linux +//go:build !linux && !darwin +// +build !linux,!darwin package lumberjack diff --git a/chown_linux.go b/chown_goos.go similarity index 58% rename from chown_linux.go rename to chown_goos.go index 465f569..d7a1ffc 100644 --- a/chown_linux.go +++ b/chown_goos.go @@ -1,11 +1,17 @@ +//go:build linux || darwin +// +build linux darwin + package lumberjack import ( + "fmt" "os" "syscall" ) // osChown is a var so we can mock it out during tests. +// +//nolint:gochecknoglobals // global variable for testing var osChown = os.Chown func chown(name string, info os.FileInfo) error { @@ -14,6 +20,10 @@ func chown(name string, info os.FileInfo) error { return err } f.Close() - stat := info.Sys().(*syscall.Stat_t) + sys := info.Sys() + stat, ok := sys.(*syscall.Stat_t) + if !ok { + return fmt.Errorf("could not change log permissions for %s", name) + } return osChown(name, int(stat.Uid), int(stat.Gid)) } diff --git a/linux_test.go b/chown_test.go similarity index 60% rename from linux_test.go rename to chown_test.go index b084402..b5a336e 100644 --- a/linux_test.go +++ b/chown_test.go @@ -1,25 +1,29 @@ -//go:build linux -// +build linux +//go:build linux || darwin +// +build linux darwin package lumberjack import ( + "fmt" "os" "syscall" "testing" "time" + + "github.com/stretchr/testify/assert" ) -func TestLinux_MaintainMode(t *testing.T) { +func TestDarwin_MaintainMode(t *testing.T) { + resetMocks() currentTime = fakeTime - dir := makeTempDir("TestMaintainMode", t) - defer os.RemoveAll(dir) + newUUID = fakeUUID + cwd := t.TempDir() - filename := logFile(dir) + filename := logFile(cwd) - mode := os.FileMode(0600) + mode := os.FileMode(0o600) f, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, mode) - isNil(err, t) + assert.Nil(t, err) f.Close() l := &Logger{ @@ -30,25 +34,28 @@ func TestLinux_MaintainMode(t *testing.T) { defer l.Close() b := []byte("boo!") n, err := l.Write(b) - isNil(err, t) - equals(len(b), n, t) + assert.Nil(t, err) + assert.Equal(t, len(b), n) newFakeTime() err = l.Rotate() - isNil(err, t) + assert.Nil(t, err) - filename2 := backupFile(dir) + filename2 := backupFile(cwd) info, err := os.Stat(filename) - isNil(err, t) + assert.Nil(t, err) info2, err := os.Stat(filename2) - isNil(err, t) - equals(mode, info.Mode(), t) - equals(mode, info2.Mode(), t) + assert.Nil(t, err) + assert.Equal(t, mode, info.Mode()) + assert.Equal(t, mode, info2.Mode()) } -func TestMaintainOwner(t *testing.T) { +func TestDarwin_MaintainOwner(t *testing.T) { + resetMocks() fakeFS := newFakeFS() + newUUID = fakeUUID + osChown = fakeFS.Chown osStat = fakeFS.Stat defer func() { @@ -56,13 +63,13 @@ func TestMaintainOwner(t *testing.T) { osStat = os.Stat }() currentTime = fakeTime - dir := makeTempDir("TestMaintainOwner", t) + dir := t.TempDir() defer os.RemoveAll(dir) filename := logFile(dir) - f, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0644) - isNil(err, t) + f, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0o644) + assert.Nil(t, err) f.Close() l := &Logger{ @@ -73,29 +80,29 @@ func TestMaintainOwner(t *testing.T) { defer l.Close() b := []byte("boo!") n, err := l.Write(b) - isNil(err, t) - equals(len(b), n, t) + assert.Nil(t, err) + assert.Equal(t, len(b), n) newFakeTime() err = l.Rotate() - isNil(err, t) + assert.Nil(t, err) - equals(555, fakeFS.files[filename].uid, t) - equals(666, fakeFS.files[filename].gid, t) + assert.Equal(t, 555, fakeFS.files[filename].uid) + assert.Equal(t, 666, fakeFS.files[filename].gid) } -func TestCompressMaintainMode(t *testing.T) { +func TestDarwin_CompressMaintainMode(t *testing.T) { + resetMocks() currentTime = fakeTime + newUUID = fakeUUID - dir := makeTempDir("TestCompressMaintainMode", t) - defer os.RemoveAll(dir) - + dir := t.TempDir() filename := logFile(dir) - mode := os.FileMode(0600) + mode := os.FileMode(0o600) f, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, mode) - isNil(err, t) + assert.Nil(t, err) f.Close() l := &Logger{ @@ -107,31 +114,34 @@ func TestCompressMaintainMode(t *testing.T) { defer l.Close() b := []byte("boo!") n, err := l.Write(b) - isNil(err, t) - equals(len(b), n, t) + assert.Nil(t, err) + assert.Equal(t, len(b), n) newFakeTime() err = l.Rotate() - isNil(err, t) + assert.Nil(t, err) // we need to wait a little bit since the files get compressed on a different // goroutine. - <-time.After(10 * time.Millisecond) + <-time.After(20 * time.Millisecond) // a compressed version of the log file should now exist with the correct // mode. filename2 := backupFile(dir) info, err := os.Stat(filename) - isNil(err, t) + assert.Nil(t, err) info2, err := os.Stat(filename2 + compressSuffix) - isNil(err, t) - equals(mode, info.Mode(), t) - equals(mode, info2.Mode(), t) + assert.Nil(t, err) + assert.Equal(t, mode, info.Mode()) + assert.Equal(t, mode, info2.Mode()) } -func TestCompressMaintainOwner(t *testing.T) { +func TestDarwin_CompressMaintainOwner(t *testing.T) { + resetMocks() fakeFS := newFakeFS() + newUUID = fakeUUID + osChown = fakeFS.Chown osStat = fakeFS.Stat defer func() { @@ -139,13 +149,12 @@ func TestCompressMaintainOwner(t *testing.T) { osStat = os.Stat }() currentTime = fakeTime - dir := makeTempDir("TestCompressMaintainOwner", t) - defer os.RemoveAll(dir) + dir := t.TempDir() filename := logFile(dir) - f, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0644) - isNil(err, t) + f, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0o644) + assert.Nil(t, err) f.Close() l := &Logger{ @@ -157,13 +166,13 @@ func TestCompressMaintainOwner(t *testing.T) { defer l.Close() b := []byte("boo!") n, err := l.Write(b) - isNil(err, t) - equals(len(b), n, t) + assert.Nil(t, err) + assert.Equal(t, len(b), n) newFakeTime() err = l.Rotate() - isNil(err, t) + assert.Nil(t, err) // we need to wait a little bit since the files get compressed on a different // goroutine. @@ -172,8 +181,8 @@ func TestCompressMaintainOwner(t *testing.T) { // a compressed version of the log file should now exist with the correct // owner. filename2 := backupFile(dir) - equals(555, fakeFS.files[filename2+compressSuffix].uid, t) - equals(666, fakeFS.files[filename2+compressSuffix].gid, t) + assert.Equal(t, 555, fakeFS.files[filename2+compressSuffix].uid) + assert.Equal(t, 666, fakeFS.files[filename2+compressSuffix].gid) } type fakeFile struct { @@ -199,7 +208,10 @@ func (fs *fakeFS) Stat(name string) (os.FileInfo, error) { if err != nil { return nil, err } - stat := info.Sys().(*syscall.Stat_t) + stat, ok := info.Sys().(*syscall.Stat_t) + if !ok { + return nil, fmt.Errorf("could not get file info for %s", name) + } stat.Uid = 555 stat.Gid = 666 return info, nil From f779661b04965be581bb05f522aac252c5a9b36b Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 15:59:22 +0545 Subject: [PATCH 06/19] docs: add contributing --- CONTRIBUTING.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..cd98ac5 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,61 @@ +# Welcome to Wooductter contributing guide + +Thank you for investing your time in contributing to our project! :sparkles:. + +In this guide you will get an overview of the contribution workflow from opening an issue, creating a PR, reviewing, and merging the PR. + +## New contributor guide + +To get an overview of the project, read the [README](README.md). Here are some resources to help you get started with open source contributions: + +- [Finding ways to contribute to open source on GitHub](https://docs.github.com/en/get-started/exploring-projects-on-github/finding-ways-to-contribute-to-open-source-on-github) +- [Set up Git](https://docs.github.com/en/get-started/quickstart/set-up-git) +- [GitHub flow](https://docs.github.com/en/get-started/quickstart/github-flow) +- [Collaborating with pull requests](https://docs.github.com/en/github/collaborating-with-pull-requests) + +### Issues + +#### Create a new issue + +If you spot a problem with the docs, [search if an issue already exists](https://docs.github.com/en/github/searching-for-information-on-github/searching-on-github/searching-issues-and-pull-requests#search-by-the-title-body-or-comments). If a related issue doesn't exist, you can open a new issue. + +#### Solve an issue + +Scan through our [existing issues](https://github.com/Rajil1213/woodcutter/issues) to find one that interests you. As a general rule, we don’t assign issues to anyone. If you find an issue to work on, you are welcome to open a PR with a fix. + +### Make changes in a codespace + +For more information about using a codespace for working on GitHub documentation, see "[Working in a codespace](https://github.com/github/docs/blob/main/contributing/codespace.md)." + +#### Make changes locally + +1. Fork the repository. + [Fork the repo](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo#fork-an-example-repository) so that you can make your changes without affecting the original project until you're ready to merge them. + +2. Install or update to **Node.js**, at the version specified in `.node-version`. For more information, see [the development guide](contributing/development.md). + +3. Create a working branch and start with your changes! + +### Commit your update + +Commit the changes once you are happy with them. Don't forget to run `make lint` and `make test` locally to speed up the process. :zap:. + +### Pull Request + +When you're finished with the changes, create a pull request, also known as a PR. + +- Fill the "Ready for review" template so that we can review your PR. This template helps reviewers understand your changes as well as the purpose of your pull request. + +- Don't forget to [link PR to issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) if you are solving one. + +- Enable the checkbox to [allow maintainer edits](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork) so the branch can be updated for a merge. + + Once you submit your PR, a Docs team member will review your proposal. We may ask questions or request additional information. + +- We may ask for changes to be made before a PR can be merged, either using [suggested changes](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/incorporating-feedback-in-your-pull-request) or pull request comments. You can apply suggested changes directly through the UI. You can make any other changes in your fork, then commit them to your branch. +- As you update your PR and apply changes, mark each conversation as [resolved](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/commenting-on-a-pull-request#resolving-conversations). +- If you run into any merge issues, checkout this [git tutorial](https://github.com/skills/resolve-merge-conflicts) to help you resolve merge conflicts and other issues. + +### Your PR is merged + +Congratulations :tada::tada: The GitHub team thanks you :sparkles:. From ede6a21dbf9cf6cd724ea26bdcd0dd3cb321d84a Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 16:00:54 +0545 Subject: [PATCH 07/19] fix: correct typo --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cd98ac5..37bdd98 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,4 +58,4 @@ When you're finished with the changes, create a pull request, also known as a PR ### Your PR is merged -Congratulations :tada::tada: The GitHub team thanks you :sparkles:. +Congratulations :tada::tada: and thank you :sparkles:. From 25056e6e39e929dbcc8872849030b9b501046d40 Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 16:03:00 +0545 Subject: [PATCH 08/19] docs: update local setup instructions --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 37bdd98..85ef6bc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,7 +32,7 @@ For more information about using a codespace for working on GitHub documentation 1. Fork the repository. [Fork the repo](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo#fork-an-example-repository) so that you can make your changes without affecting the original project until you're ready to merge them. -2. Install or update to **Node.js**, at the version specified in `.node-version`. For more information, see [the development guide](contributing/development.md). +2. Install or update to **Go**, at the version specified in [go.mod](./go.mod). Also, install [golangci-lint](https://golangci-lint.run/) if not already installed. 3. Create a working branch and start with your changes! @@ -44,8 +44,6 @@ Commit the changes once you are happy with them. Don't forget to run `make lint` When you're finished with the changes, create a pull request, also known as a PR. -- Fill the "Ready for review" template so that we can review your PR. This template helps reviewers understand your changes as well as the purpose of your pull request. - - Don't forget to [link PR to issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) if you are solving one. - Enable the checkbox to [allow maintainer edits](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork) so the branch can be updated for a merge. @@ -53,7 +51,9 @@ When you're finished with the changes, create a pull request, also known as a PR Once you submit your PR, a Docs team member will review your proposal. We may ask questions or request additional information. - We may ask for changes to be made before a PR can be merged, either using [suggested changes](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/incorporating-feedback-in-your-pull-request) or pull request comments. You can apply suggested changes directly through the UI. You can make any other changes in your fork, then commit them to your branch. + - As you update your PR and apply changes, mark each conversation as [resolved](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/commenting-on-a-pull-request#resolving-conversations). + - If you run into any merge issues, checkout this [git tutorial](https://github.com/skills/resolve-merge-conflicts) to help you resolve merge conflicts and other issues. ### Your PR is merged From 42fba7d71e34735b7e5110d52707db41196c3512 Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 16:07:09 +0545 Subject: [PATCH 09/19] docs: add ci badges --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index a90ac9e..6f3f48a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Woodcutter +[![Build](https://github.com/Rajil1213/woodcutter/actions/workflows/go.yml/badge.svg)](https://github.com/Rajil1213/woodcutter/actions/workflows/go.yml) +[![Go Coverage](https://github.com/Rajil1213/woodcutter/wiki/coverage.svg)](https://raw.githack.com/wiki/Rajil1213/woodcutter/coverage.html) + Woodcutter is a Go package for writing logs to rolling files, forked from [lumberjack](https://github.com/natefinch/lumberjack). This fork was created since the original package remains largely unmaintained. Package woodcutter provides a rolling logger that enhances lumberjack with the following changes: From f59002d82054f7bd30209927e74217755a413390 Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 16:18:32 +0545 Subject: [PATCH 10/19] ci: get coverage badge --- .github/workflows/go.yml | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f1fe0bc..f5e2755 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -29,20 +29,12 @@ jobs: - name: Test run: go test -v -cover ./... - - name: Export Test Results - run: go test -json > TestResults.json - - - name: Upload Go test results - uses: actions/upload-artifact@v3 - with: - name: Test-results - path: TestResults.json - - name: Get Coverage Report - uses: ncruces/go-coverage-report@v0 + run: | + go test -v ./... -covermode=count -coverprofile=coverage.out + go tool cover -func=coverage.out -o=coverage.out + + - name: Go Coverage Badge # Pass the `coverage.out` output to this action + uses: tj-actions/coverage-badge-go@v2 with: - report: 'true' - chart: 'true' - amend: 'false' - if: github.event_name == 'push' - continue-on-error: true + filename: coverage.out From fbb5ab402728522e9363024c4e7ef1077aba46ef Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 16:21:02 +0545 Subject: [PATCH 11/19] ci: add steps to update readme with coverage badge --- .github/workflows/go.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f5e2755..cca3772 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -38,3 +38,24 @@ jobs: uses: tj-actions/coverage-badge-go@v2 with: filename: coverage.out + + - name: Verify Changed files + uses: tj-actions/verify-changed-files@v12 + id: verify-changed-files + with: + files: README.md + + - name: Commit changes + if: steps.verify-changed-files.outputs.files_changed == 'true' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add README.md + git commit -m "chore: Updated coverage badge." + + - name: Push changes + if: steps.verify-changed-files.outputs.files_changed == 'true' + uses: ad-m/github-push-action@master + with: + github_token: ${{ github.token }} + branch: ${{ github.head_ref }} From aba727a4fcb1484d3018ce3004365e6b23411a19 Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 16:22:08 +0545 Subject: [PATCH 12/19] docs: use blank coverage to be updated later --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f3f48a..be4f844 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Woodcutter [![Build](https://github.com/Rajil1213/woodcutter/actions/workflows/go.yml/badge.svg)](https://github.com/Rajil1213/woodcutter/actions/workflows/go.yml) -[![Go Coverage](https://github.com/Rajil1213/woodcutter/wiki/coverage.svg)](https://raw.githack.com/wiki/Rajil1213/woodcutter/coverage.html) +[![Coverage]()]() Woodcutter is a Go package for writing logs to rolling files, forked from [lumberjack](https://github.com/natefinch/lumberjack). This fork was created since the original package remains largely unmaintained. From 5cb459903d37168eb0fc3deec0fd626593b033f1 Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 16:41:12 +0545 Subject: [PATCH 13/19] ci: create coverage report --- .github/workflows/go.yml | 35 +++++++---------------------------- .testcoverage.yml | 17 +++++++++++++++++ Makefile | 11 +++++++++++ README.md | 1 - 4 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 .testcoverage.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index cca3772..d99186a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -29,33 +29,12 @@ jobs: - name: Test run: go test -v -cover ./... - - name: Get Coverage Report - run: | - go test -v ./... -covermode=count -coverprofile=coverage.out - go tool cover -func=coverage.out -o=coverage.out + - name: Generate Test Coverage + run: go test ./... -coverprofile=./cover.out - - name: Go Coverage Badge # Pass the `coverage.out` output to this action - uses: tj-actions/coverage-badge-go@v2 + - name: check test coverage + uses: vladopajic/go-test-coverage@v2 with: - filename: coverage.out - - - name: Verify Changed files - uses: tj-actions/verify-changed-files@v12 - id: verify-changed-files - with: - files: README.md - - - name: Commit changes - if: steps.verify-changed-files.outputs.files_changed == 'true' - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add README.md - git commit -m "chore: Updated coverage badge." - - - name: Push changes - if: steps.verify-changed-files.outputs.files_changed == 'true' - uses: ad-m/github-push-action@master - with: - github_token: ${{ github.token }} - branch: ${{ github.head_ref }} + # Configure action by specifying input parameters individually (option 2) + profile: cover.out + threshold-total: 95 \ No newline at end of file diff --git a/.testcoverage.yml b/.testcoverage.yml new file mode 100644 index 0000000..64c2468 --- /dev/null +++ b/.testcoverage.yml @@ -0,0 +1,17 @@ +# (mandatory) +# Path to coverprofile file (output of `go test -coverprofile` command) +profile: coverage/cover.out + +# Holds coverage thresholds percentages, values should be in range [0-100] +threshold: + # (optional; default 0) + # The minimum coverage that each file should have + file: 70 + + # (optional; default 0) + # The minimum7coverage that each package should have + package: 70 + + # (optional; default 0) + # The minimum total coverage project should have + total: 80 diff --git a/Makefile b/Makefile index 671b55a..492c6b4 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +GOBIN ?= $$(go env GOPATH)/bin + .PHONY: lint lint: golangci-lint run @@ -6,6 +8,15 @@ lint: test: go test -cover ./... +.PHONY: install-go-test-coverage +install-go-test-coverage: + go install github.com/vladopajic/go-test-coverage/v2@latest + +.PHONY: check-coverage +check-coverage: install-go-test-coverage + go test ./... -coverprofile=./coverage/cover.out -covermode=atomic -coverpkg=./... + ${GOBIN}/go-test-coverage --config=./.testcoverage.yml + .PHONY: cover cover: go test -v -coverprofile coverage/cover.out ./... &&\ diff --git a/README.md b/README.md index be4f844..4b5d278 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Woodcutter [![Build](https://github.com/Rajil1213/woodcutter/actions/workflows/go.yml/badge.svg)](https://github.com/Rajil1213/woodcutter/actions/workflows/go.yml) -[![Coverage]()]() Woodcutter is a Go package for writing logs to rolling files, forked from [lumberjack](https://github.com/natefinch/lumberjack). This fork was created since the original package remains largely unmaintained. From 947377e245b0f322e42532614f5ec7bf10c52a09 Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 18:31:49 +0545 Subject: [PATCH 14/19] docs: add coverage badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4b5d278..a34cde2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Woodcutter [![Build](https://github.com/Rajil1213/woodcutter/actions/workflows/go.yml/badge.svg)](https://github.com/Rajil1213/woodcutter/actions/workflows/go.yml) +![coverage](https://raw.githubusercontent.com/Rajil1213/woodcutter/badges/.badges/main/coverage.svg) Woodcutter is a Go package for writing logs to rolling files, forked from [lumberjack](https://github.com/natefinch/lumberjack). This fork was created since the original package remains largely unmaintained. From bb0504c34b7922a7a7bed37e3f1c90fe00109d93 Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 18:34:24 +0545 Subject: [PATCH 15/19] ignore patch version --- go.mod | 2 +- go.work | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index a47717a..f6ce20e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/Rajil1213/woodcutter -go 1.21.0 +go 1.21 require github.com/stretchr/testify v1.8.4 diff --git a/go.work b/go.work index 1fbf39b..1cd473e 100644 --- a/go.work +++ b/go.work @@ -1,3 +1,3 @@ -go 1.21.0 +go 1.21 use . From fe6a17e148124e38b0febab5ce08922c9479511a Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 18:39:28 +0545 Subject: [PATCH 16/19] ci: create coverage badge --- .github/workflows/go.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d99186a..22e5f98 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -37,4 +37,15 @@ jobs: with: # Configure action by specifying input parameters individually (option 2) profile: cover.out - threshold-total: 95 \ No newline at end of file + threshold-total: 95 + + - name: make coverage badge + uses: action-badges/core@0.2.2 + # if: contains(github.ref, 'main') + with: + label: coverage + message: ${{ steps.coverage.outputs.badge-text }} + message-color: ${{ steps.coverage.outputs.badge-color }} + file-name: coverage.svg + badge-branch: badges ## orphan branch where badge will be committed + github-token: "${{ secrets.GITHUB_TOKEN }}" \ No newline at end of file From b074305ab2b5baf0482b875824ddca38ba9889e3 Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 18:46:25 +0545 Subject: [PATCH 17/19] docs: update badge location --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a34cde2..8e8e574 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Woodcutter [![Build](https://github.com/Rajil1213/woodcutter/actions/workflows/go.yml/badge.svg)](https://github.com/Rajil1213/woodcutter/actions/workflows/go.yml) -![coverage](https://raw.githubusercontent.com/Rajil1213/woodcutter/badges/.badges/main/coverage.svg) +![coverage](https://raw.githubusercontent.com/Rajil1213/woodcutter/badges/.badges/coverage.svg) Woodcutter is a Go package for writing logs to rolling files, forked from [lumberjack](https://github.com/natefinch/lumberjack). This fork was created since the original package remains largely unmaintained. From 5c8f6724a178f3757afb4f3e4fbd0af4c355bc8f Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 18:52:32 +0545 Subject: [PATCH 18/19] ci: add config,id and only run on main --- .github/workflows/go.yml | 7 +++---- README.md | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 22e5f98..7c6b4b3 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -33,15 +33,14 @@ jobs: run: go test ./... -coverprofile=./cover.out - name: check test coverage + id: coverage ## this step must have id uses: vladopajic/go-test-coverage@v2 with: - # Configure action by specifying input parameters individually (option 2) - profile: cover.out - threshold-total: 95 + config: ./.testcoverage.yml - name: make coverage badge uses: action-badges/core@0.2.2 - # if: contains(github.ref, 'main') + if: contains(github.ref, 'main') with: label: coverage message: ${{ steps.coverage.outputs.badge-text }} diff --git a/README.md b/README.md index 8e8e574..a34cde2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Woodcutter [![Build](https://github.com/Rajil1213/woodcutter/actions/workflows/go.yml/badge.svg)](https://github.com/Rajil1213/woodcutter/actions/workflows/go.yml) -![coverage](https://raw.githubusercontent.com/Rajil1213/woodcutter/badges/.badges/coverage.svg) +![coverage](https://raw.githubusercontent.com/Rajil1213/woodcutter/badges/.badges/main/coverage.svg) Woodcutter is a Go package for writing logs to rolling files, forked from [lumberjack](https://github.com/natefinch/lumberjack). This fork was created since the original package remains largely unmaintained. From 5ec669b495642637de4279a4d2564ad17a97f700 Mon Sep 17 00:00:00 2001 From: Rajil Bajracharya Date: Fri, 1 Sep 2023 18:54:03 +0545 Subject: [PATCH 19/19] ci: create separate coverage directory --- .github/workflows/go.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7c6b4b3..0d05aaf 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -30,7 +30,9 @@ jobs: run: go test -v -cover ./... - name: Generate Test Coverage - run: go test ./... -coverprofile=./cover.out + run: | + mkdir -p coverage + go test ./... -coverprofile=./coverage/cover.out - name: check test coverage id: coverage ## this step must have id