Skip to content

Commit

Permalink
Merge pull request #53 from Code-Hex/fix/actions-windows
Browse files Browse the repository at this point in the history
fixed actions for testing windows
  • Loading branch information
Code-Hex authored Feb 24, 2022
2 parents bb2459c + df932b1 commit eb0e41e
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 22 deletions.
28 changes: 13 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,41 @@ on:
pull_request:

jobs:
build:
name: Build
runs-on: ubuntu-latest
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
name: test
runs-on: ${{ matrix.os }}
steps:
- name: Setup Go 1.17.2
uses: actions/setup-go@v1
uses: actions/setup-go@v2
with:
go-version: 1.17.2
- name: Check out code into the Go module directory
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Vet
run: make vet
- name: Test
run: make test
- name: Lint
if: matrix.os == 'ubuntu-latest'
run: |
go get golang.org/x/lint/golint
export PATH="$PATH:$(go env GOPATH)/bin"
make lint
env:
GO111MODULE: off
- name: Declare some variables
if: matrix.os == 'ubuntu-latest'
id: vars
run: |
echo "::set-output name=coverage_txt::${RUNNER_TEMP}/coverage.txt"
- name: Test Coverage (pkg)
if: matrix.os == 'ubuntu-latest'
run: go test ./... -coverprofile=${{ steps.vars.outputs.coverage_txt }}
- name: Upload coverage
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v2
with:
files: ${{ steps.vars.outputs.coverage_txt }}
- name: Run GoReleaser
if: contains(github.ref, 'tags/v')
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
files: ${{ steps.vars.outputs.coverage_txt }}
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on:
push:
tags:
- "v*.*.*"

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Setup Go 1.17.2
uses: actions/setup-go@v2
with:
go-version: 1.17.2
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Run GoReleaser
if: contains(github.ref, 'tags/v')
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ go 1.16
require (
github.com/Code-Hex/Neo-cowsay/v2 v2.0.3
github.com/Code-Hex/go-wordwrap v1.0.0
github.com/google/go-cmp v0.5.6
github.com/jessevdk/go-flags v1.5.0
github.com/ktr0731/go-fuzzyfinder v0.5.1
github.com/mattn/go-colorable v0.1.11
github.com/mattn/go-runewidth v0.0.13
github.com/rivo/uniseg v0.2.0
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa
)

replace github.com/Code-Hex/Neo-cowsay/v2 => ../
2 changes: 0 additions & 2 deletions cmd/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/Code-Hex/Neo-cowsay/v2 v2.0.3 h1:mreJLDHRxoFhUvlw/1pFZIkekYVCg1hdMJ49QdZSASA=
github.com/Code-Hex/Neo-cowsay/v2 v2.0.3/go.mod h1:6k40Pwrc2FazLf1BUbmAC36E9LvT+DErjZr30isbXhg=
github.com/Code-Hex/go-wordwrap v1.0.0 h1:yl5fLyZEz3+hPGbpTRlTQ8mQJ1HXWcTq1FCNR1ch6zM=
github.com/Code-Hex/go-wordwrap v1.0.0/go.mod h1:/SsbgkY2Q0aPQRyvXcyQwWYTQOIwSORKe6MPjRVGIWU=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
Expand Down
8 changes: 6 additions & 2 deletions cmd/internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"path/filepath"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
)

func TestCLI_Run(t *testing.T) {
Expand Down Expand Up @@ -130,8 +132,10 @@ func TestCLI_Run(t *testing.T) {
if err != nil {
t.Fatal(err)
}
want := string(content)
if got := stdout.String(); want != got {
got := strings.Replace(stdout.String(), "\r", "", -1) // for windows
want := strings.Replace(string(content), "\r", "", -1) // for windows
if want != got {
t.Log(cmp.Diff(want, got))
t.Errorf("want\n%s\n-----got\n%s\n", want, got)
}
})
Expand Down
5 changes: 4 additions & 1 deletion cowsay.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"math/rand"
"os"
"path"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -74,10 +75,12 @@ type CowFile struct {
// If LocationType is InBinary, the file read from binary.
// otherwise reads from file system.
func (c *CowFile) ReadAll() ([]byte, error) {
joinedPath := filepath.Join(c.BasePath, c.Name+".cow")
if c.LocationType == InBinary {
// go embed is used "/" separator
joinedPath := path.Join(c.BasePath, c.Name+".cow")
return Asset(joinedPath)
}
joinedPath := filepath.Join(c.BasePath, c.Name+".cow")
return ioutil.ReadFile(joinedPath)
}

Expand Down
7 changes: 5 additions & 2 deletions cowsay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -53,7 +54,7 @@ func TestCows(t *testing.T) {

wants := []*CowPath{
{
Name: "testdata/testdir",
Name: filepath.Join("testdata", "testdir"),
LocationType: InDirectory,
},
{
Expand Down Expand Up @@ -222,8 +223,10 @@ func TestSay(t *testing.T) {
if err != nil {
t.Fatal(err)
}
want := string(content)
got = strings.Replace(got, "\r", "", -1) // for windows
want := strings.Replace(string(content), "\r", "", -1) // for windows
if want != got {
t.Log(cmp.Diff([]byte(want), []byte(got)))
t.Fatalf("want\n%s\n\ngot\n%s", want, got)
}
})
Expand Down

0 comments on commit eb0e41e

Please sign in to comment.