Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create workflow #1

Merged
merged 19 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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: Generate Test Coverage
run: |
mkdir -p coverage
go test ./... -coverprofile=./coverage/cover.out

- name: check test coverage
id: coverage ## this step must have id
uses: vladopajic/go-test-coverage@v2
with:
config: ./.testcoverage.yml

- 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 }}"
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions .testcoverage.yml
Original file line number Diff line number Diff line change
@@ -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
61 changes: 61 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Welcome to Wooductter contributing guide <!-- omit in toc -->

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 **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!

### 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.

- 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: and thank you :sparkles:.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
GOBIN ?= $$(go env GOPATH)/bin

.PHONY: lint
lint:
golangci-lint run
Expand All @@ -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 ./... &&\
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
![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.

Package woodcutter provides a rolling logger that enhances lumberjack with the following changes:
Expand Down
4 changes: 2 additions & 2 deletions chown.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !linux
// +build !linux
//go:build !linux && !darwin
// +build !linux,!darwin

package lumberjack

Expand Down
12 changes: 11 additions & 1 deletion chown_linux.go → chown_goos.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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))
}
Loading