Skip to content

Commit

Permalink
Merge pull request #1 from bodgit/travis
Browse files Browse the repository at this point in the history
Convert from Travis to Github Actions
  • Loading branch information
bodgit authored Apr 30, 2022
2 parents 27250a7 + a063245 commit 78174ac
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 12 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
48 changes: 48 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
name: build
on:
push:
tags:
- v*
branches:
- main
- master
pull_request:
permissions:
contents: read
pull-requests: read
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go:
- '1.17'
- '1.18'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
only-new-issues: true
- name: Test
run: go test -v -coverprofile=cover.out ./...
- name: Send coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: cover.out
flag-name: Go-${{ matrix.go }}
parallel: true
finish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: shogo82148/actions-goveralls@v1
with:
parallel-finished: true
10 changes: 10 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
linters:
enable-all: true
disable:
- exhaustivestruct
- paralleltest
- scopelint
- testpackage
- varnamelen
- wrapcheck
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[![Build Status](https://travis-ci.com/bodgit/plumbing.svg?branch=master)](https://travis-ci.com/bodgit/plumbing)
[![Build Status](https://img.shields.io/github/workflow/status/bodgit/plumbing/build)](https://github.com/bodgit/plumbing/actions?query=workflow%3Abuild)
[![Coverage Status](https://coveralls.io/repos/github/bodgit/plumbing/badge.svg?branch=master)](https://coveralls.io/github/bodgit/plumbing?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/bodgit/plumbing)](https://goreportcard.com/report/github.com/bodgit/plumbing)
[![GoDoc](https://godoc.org/github.com/bodgit/plumbing?status.svg)](https://godoc.org/github.com/bodgit/plumbing)
![Go version](https://img.shields.io/badge/Go-1.18-brightgreen.svg)
![Go version](https://img.shields.io/badge/Go-1.17-brightgreen.svg)

plumbing
========
Expand Down
1 change: 1 addition & 0 deletions count.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type WriteCounter struct {
func (wc *WriteCounter) Write(p []byte) (int, error) {
n := len(p)
atomic.AddUint64(&wc.count, uint64(n))

return n, nil
}

Expand Down
12 changes: 12 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ func ExampleWriteCounter() {
in := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
writer := WriteCounter{}
reader := io.TeeReader(bytes.NewReader(in), &writer)

if _, err := io.CopyN(ioutil.Discard, reader, 4); err != nil {
panic(err)
}

if _, err := io.Copy(ioutil.Discard, reader); err != nil {
panic(err)
}
Expand All @@ -26,6 +28,7 @@ func ExampleWriteCounter() {
func ExampleTeeReaderAt() {
// Smallest valid zip archive
in := []byte{80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

writer := WriteCounter{}
if _, err := zip.NewReader(TeeReaderAt(bytes.NewReader(in), &writer), int64(len(in))); err != nil {
panic(err)
Expand All @@ -37,9 +40,12 @@ func ExampleTeeReaderAt() {

func ExampleTeeReadCloser() {
in := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

writer := WriteCounter{}
reader := TeeReadCloser(ioutil.NopCloser(bytes.NewReader(in)), &writer)

defer reader.Close()

if _, err := io.Copy(ioutil.Discard, reader); err != nil {
panic(err)
}
Expand All @@ -50,8 +56,10 @@ func ExampleTeeReadCloser() {

func ExamplePaddedReader() {
in := []byte{1, 2, 3, 4}

reader := PaddedReader(bytes.NewReader(in), 8, 0)
writer := new(bytes.Buffer)

if _, err := io.Copy(writer, reader); err != nil {
panic(err)
}
Expand All @@ -71,9 +79,11 @@ func ExampleMultiWriteCloser() {
in := []byte{0, 1, 2, 3}
b1, b2 := new(bytes.Buffer), new(bytes.Buffer)
writer := MultiWriteCloser(NopWriteCloser(b1), NopWriteCloser(b2))

if _, err := writer.Write(in); err != nil {
panic(err)
}

if err := writer.Close(); err != nil {
panic(err)
}
Expand All @@ -86,9 +96,11 @@ func ExampleLimitReadCloser() {
in := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
reader := LimitReadCloser(ioutil.NopCloser(bytes.NewReader(in)), 5)
writer := new(bytes.Buffer)

if _, err := io.Copy(writer, reader); err != nil {
panic(err)
}

if err := reader.Close(); err != nil {
panic(err)
}
Expand Down
3 changes: 3 additions & 0 deletions limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ func (l *LimitedReadCloser) Read(p []byte) (n int, err error) {
if l.N <= 0 {
return 0, io.EOF
}

if int64(len(p)) > l.N {
p = p[0:l.N]
}

n, err = l.R.Read(p)
l.N -= int64(n)

return
}

Expand Down
6 changes: 6 additions & 0 deletions multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ func (t *multiWriteCloser) Write(p []byte) (n int, err error) {
if err != nil {
return
}

if n != len(p) {
err = io.ErrShortWrite

return
}
}

return len(p), nil
}

Expand All @@ -27,6 +30,7 @@ func (t *multiWriteCloser) Close() (err error) {
return
}
}

return
}

Expand All @@ -38,12 +42,14 @@ func (t *multiWriteCloser) Close() (err error) {
// stops and returns the error; it does not continue down the list.
func MultiWriteCloser(writeClosers ...io.WriteCloser) io.WriteCloser {
allWriteClosers := make([]io.WriteCloser, 0, len(writeClosers))

for _, wc := range writeClosers {
if mwc, ok := wc.(*multiWriteCloser); ok {
allWriteClosers = append(allWriteClosers, mwc.writeClosers...)
} else {
allWriteClosers = append(allWriteClosers, wc)
}
}

return &multiWriteCloser{allWriteClosers}
}
2 changes: 2 additions & 0 deletions multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func (partialWriter) Write(p []byte) (n int, err error) {
}

func TestMultiWriteCloser(t *testing.T) {
in := []byte("abcdefghij")

tables := map[string]struct {
writer io.WriteCloser
n int
Expand Down
2 changes: 2 additions & 0 deletions tee.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func (t *teeReaderAt) ReadAt(p []byte, off int64) (n int, err error) {
return n, err
}
}

return
}

Expand All @@ -38,6 +39,7 @@ func (t *teeReadCloser) Read(p []byte) (n int, err error) {
return n, err
}
}

return
}

Expand Down
6 changes: 4 additions & 2 deletions tee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func (errorWriter) Write(p []byte) (n int, err error) {
return 0, errWrite
}

var in = []byte("abcdefghij")

func TestTeeReaderAt(t *testing.T) {
in := []byte("abcdefghij")

tables := map[string]struct {
reader io.ReaderAt
writer io.Writer
Expand Down Expand Up @@ -61,6 +61,8 @@ func TestTeeReaderAt(t *testing.T) {
}

func TestTeeReadCloser(t *testing.T) {
in := []byte("abcdefghij")

tables := map[string]struct {
reader io.ReadCloser
writer io.Writer
Expand Down

0 comments on commit 78174ac

Please sign in to comment.