Skip to content

Commit eb0e41e

Browse files
authored
Merge pull request #53 from Code-Hex/fix/actions-windows
fixed actions for testing windows
2 parents bb2459c + df932b1 commit eb0e41e

File tree

7 files changed

+56
-22
lines changed

7 files changed

+56
-22
lines changed

.github/workflows/main.yml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,41 @@ on:
77
pull_request:
88

99
jobs:
10-
build:
11-
name: Build
12-
runs-on: ubuntu-latest
10+
test:
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, windows-latest]
14+
name: test
15+
runs-on: ${{ matrix.os }}
1316
steps:
1417
- name: Setup Go 1.17.2
15-
uses: actions/setup-go@v1
18+
uses: actions/setup-go@v2
1619
with:
1720
go-version: 1.17.2
1821
- name: Check out code into the Go module directory
19-
uses: actions/checkout@v1
22+
uses: actions/checkout@v2
2023
- name: Vet
2124
run: make vet
2225
- name: Test
2326
run: make test
2427
- name: Lint
28+
if: matrix.os == 'ubuntu-latest'
2529
run: |
2630
go get golang.org/x/lint/golint
2731
export PATH="$PATH:$(go env GOPATH)/bin"
2832
make lint
2933
env:
3034
GO111MODULE: off
3135
- name: Declare some variables
36+
if: matrix.os == 'ubuntu-latest'
3237
id: vars
3338
run: |
3439
echo "::set-output name=coverage_txt::${RUNNER_TEMP}/coverage.txt"
3540
- name: Test Coverage (pkg)
41+
if: matrix.os == 'ubuntu-latest'
3642
run: go test ./... -coverprofile=${{ steps.vars.outputs.coverage_txt }}
3743
- name: Upload coverage
44+
if: matrix.os == 'ubuntu-latest'
3845
uses: codecov/codecov-action@v2
3946
with:
40-
files: ${{ steps.vars.outputs.coverage_txt }}
41-
- name: Run GoReleaser
42-
if: contains(github.ref, 'tags/v')
43-
uses: goreleaser/goreleaser-action@v2
44-
with:
45-
version: latest
46-
args: release --rm-dist
47-
env:
48-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49-
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
47+
files: ${{ steps.vars.outputs.coverage_txt }}

.github/workflows/release.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
on:
2+
push:
3+
tags:
4+
- "v*.*.*"
5+
6+
jobs:
7+
release:
8+
name: Release
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Setup Go 1.17.2
12+
uses: actions/setup-go@v2
13+
with:
14+
go-version: 1.17.2
15+
- name: Check out code into the Go module directory
16+
uses: actions/checkout@v2
17+
- name: Run GoReleaser
18+
if: contains(github.ref, 'tags/v')
19+
uses: goreleaser/goreleaser-action@v2
20+
with:
21+
version: latest
22+
args: release --rm-dist
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}

cmd/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ go 1.16
55
require (
66
github.com/Code-Hex/Neo-cowsay/v2 v2.0.3
77
github.com/Code-Hex/go-wordwrap v1.0.0
8+
github.com/google/go-cmp v0.5.6
89
github.com/jessevdk/go-flags v1.5.0
910
github.com/ktr0731/go-fuzzyfinder v0.5.1
1011
github.com/mattn/go-colorable v0.1.11
1112
github.com/mattn/go-runewidth v0.0.13
1213
github.com/rivo/uniseg v0.2.0
1314
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa
1415
)
16+
17+
replace github.com/Code-Hex/Neo-cowsay/v2 => ../

cmd/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/Code-Hex/Neo-cowsay/v2 v2.0.3 h1:mreJLDHRxoFhUvlw/1pFZIkekYVCg1hdMJ49QdZSASA=
2-
github.com/Code-Hex/Neo-cowsay/v2 v2.0.3/go.mod h1:6k40Pwrc2FazLf1BUbmAC36E9LvT+DErjZr30isbXhg=
31
github.com/Code-Hex/go-wordwrap v1.0.0 h1:yl5fLyZEz3+hPGbpTRlTQ8mQJ1HXWcTq1FCNR1ch6zM=
42
github.com/Code-Hex/go-wordwrap v1.0.0/go.mod h1:/SsbgkY2Q0aPQRyvXcyQwWYTQOIwSORKe6MPjRVGIWU=
53
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=

cmd/internal/cli/cli_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"path/filepath"
88
"strings"
99
"testing"
10+
11+
"github.com/google/go-cmp/cmp"
1012
)
1113

1214
func TestCLI_Run(t *testing.T) {
@@ -130,8 +132,10 @@ func TestCLI_Run(t *testing.T) {
130132
if err != nil {
131133
t.Fatal(err)
132134
}
133-
want := string(content)
134-
if got := stdout.String(); want != got {
135+
got := strings.Replace(stdout.String(), "\r", "", -1) // for windows
136+
want := strings.Replace(string(content), "\r", "", -1) // for windows
137+
if want != got {
138+
t.Log(cmp.Diff(want, got))
135139
t.Errorf("want\n%s\n-----got\n%s\n", want, got)
136140
}
137141
})

cowsay.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"io/ioutil"
55
"math/rand"
66
"os"
7+
"path"
78
"path/filepath"
89
"sort"
910
"strings"
@@ -74,10 +75,12 @@ type CowFile struct {
7475
// If LocationType is InBinary, the file read from binary.
7576
// otherwise reads from file system.
7677
func (c *CowFile) ReadAll() ([]byte, error) {
77-
joinedPath := filepath.Join(c.BasePath, c.Name+".cow")
7878
if c.LocationType == InBinary {
79+
// go embed is used "/" separator
80+
joinedPath := path.Join(c.BasePath, c.Name+".cow")
7981
return Asset(joinedPath)
8082
}
83+
joinedPath := filepath.Join(c.BasePath, c.Name+".cow")
8184
return ioutil.ReadFile(joinedPath)
8285
}
8386

cowsay_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io/ioutil"
77
"os"
88
"path/filepath"
9+
"strings"
910
"testing"
1011

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

5455
wants := []*CowPath{
5556
{
56-
Name: "testdata/testdir",
57+
Name: filepath.Join("testdata", "testdir"),
5758
LocationType: InDirectory,
5859
},
5960
{
@@ -222,8 +223,10 @@ func TestSay(t *testing.T) {
222223
if err != nil {
223224
t.Fatal(err)
224225
}
225-
want := string(content)
226+
got = strings.Replace(got, "\r", "", -1) // for windows
227+
want := strings.Replace(string(content), "\r", "", -1) // for windows
226228
if want != got {
229+
t.Log(cmp.Diff([]byte(want), []byte(got)))
227230
t.Fatalf("want\n%s\n\ngot\n%s", want, got)
228231
}
229232
})

0 commit comments

Comments
 (0)