Skip to content
This repository was archived by the owner on Dec 22, 2025. It is now read-only.

Commit ee68056

Browse files
authored
Merge pull request #119 from hellofresh/patch/gh-actions
PT-7159 Added GH Actions pipeline
2 parents b572200 + 85a1df4 commit ee68056

File tree

8 files changed

+151
-94
lines changed

8 files changed

+151
-94
lines changed

.github/workflows/release.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Testing
2+
3+
on:
4+
release:
5+
types:
6+
- created
7+
8+
jobs:
9+
goreleaser:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Check out code
14+
uses: actions/checkout@v2
15+
- name: Unshallow
16+
run: git fetch --prune --unshallow
17+
- name: Set up Go
18+
uses: actions/setup-go@v2
19+
- name: Run GoReleaser
20+
uses: goreleaser/goreleaser-action@v2
21+
if: startsWith(github.ref, 'refs/tags/')
22+
with:
23+
version: latest
24+
args: release --rm-dist
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/testing.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Testing
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out code
15+
uses: actions/checkout@v2
16+
- name: golangci-lint
17+
uses: golangci/golangci-lint-action@v1
18+
with:
19+
version: v1.27
20+
21+
test:
22+
name: Test
23+
runs-on: ubuntu-latest
24+
needs: [lint]
25+
26+
services:
27+
postgres:
28+
image: postgres:9.6-alpine
29+
ports:
30+
- "5432"
31+
env:
32+
POSTGRES_USER: test
33+
POSTGRES_PASSWORD: test
34+
POSTGRES_DB: test
35+
options: >-
36+
--health-cmd pg_isready
37+
--health-interval 10s
38+
--health-timeout 5s
39+
--health-retries 5
40+
41+
mysql:
42+
image: mysql:5.7
43+
ports:
44+
- "3306"
45+
env:
46+
MYSQL_ROOT_PASSWORD: test
47+
MYSQL_DATABASE: test
48+
MYSQL_USER: test
49+
MYSQL_PASSWORD: test
50+
options: >-
51+
--health-cmd "mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD"
52+
--health-interval 10s
53+
--health-timeout 5s
54+
--health-retries 5
55+
56+
steps:
57+
- name: Set up Go
58+
uses: actions/setup-go@v2
59+
- name: Check out code
60+
uses: actions/checkout@v2
61+
- name: Run tests
62+
if: success()
63+
run: go test -cover ./... -coverprofile=coverage.txt -covermode=atomic
64+
env:
65+
TEST_POSTGRES: postgres://test:test@localhost:${{ job.services.postgres.ports[5432] }}/?sslmode=disable
66+
TEST_MYSQL: root:test@tcp(localhost:${{ job.services.mysql.ports[3306] }})/?charset=utf8
67+
68+
- name: Upload coverage to Codecov
69+
uses: codecov/codecov-action@v1
70+
if: success()
71+
with:
72+
file: ./coverage.txt
73+
fail_ci_if_error: false

.golangci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# See https://golangci-lint.run/usage/configuration/#config-file for more information
2+
run:
3+
timeout: 5m
4+
linters:
5+
disable-all: true
6+
enable:
7+
- gofmt
8+
- golint
9+
- goimports
10+
fast: false
11+
linters-settings:
12+
gofmt:
13+
simplify: false
14+
issues:
15+
exclude-use-default: false

.travis.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

Makefile

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,15 @@ OK_COLOR=\033[32;01m
33
ERROR_COLOR=\033[31;01m
44
WARN_COLOR=\033[33;01m
55

6-
# Space separated patterns of packages to skip in list, test, format.
7-
IGNORED_PACKAGES := /vendor/
6+
.PHONY: all test build
87

9-
.PHONY: all clean deps build
10-
11-
all: clean deps build
12-
13-
deps:
14-
@echo "$(OK_COLOR)==> Installing dependencies$(NO_COLOR)"
15-
@go get -u golang.org/x/lint/golint
16-
@go mod vendor
8+
all: test build
179

1810
# Builds the project
1911
build:
2012
@echo "$(OK_COLOR)==> Building... $(NO_COLOR)"
2113
@goreleaser --snapshot --rm-dist --skip-validate
2214

23-
test: lint format vet
15+
test:
2416
@echo "$(OK_COLOR)==> Running tests$(NO_COLOR)"
2517
@CGO_ENABLED=0 go test -cover ./... -coverprofile=coverage.txt -covermode=atomic
26-
27-
lint:
28-
@echo "$(OK_COLOR)==> Checking code style with 'golint' tool$(NO_COLOR)"
29-
@go list ./... | xargs -n 1 golint -set_exit_status
30-
31-
format:
32-
@echo "$(OK_COLOR)==> Checking code formating with 'gofmt' tool$(NO_COLOR)"
33-
@gofmt -l -s cmd pkg | grep ".*\.go"; if [ "$$?" = "0" ]; then exit 1; fi
34-
35-
vet:
36-
@echo "$(OK_COLOR)==> Checking code correctness with 'go vet' tool$(NO_COLOR)"
37-
@go vet ./...
38-
39-
test-docker:
40-
docker-compose up -d
41-
@TEST_POSTGRES="postgres://hello:fresh@localhost:8050/klepto?sslmode=disable" \
42-
TEST_MYSQL="root:hellofresh@tcp(localhost:8052)/" \
43-
/bin/sh -c "./build/test.sh $(allpackages)"
44-
45-
# Cleans our project: deletes binaries
46-
clean:
47-
@echo "$(OK_COLOR)==> Cleaning project$(NO_COLOR)"
48-
@go clean
49-
@rm -rf dist
50-
51-
# cd into the GOPATH to workaround ./... not following symlinks
52-
_allpackages = $(shell ( go list ./... 2>&1 1>&3 | \
53-
grep -v -e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES)) 1>&2 ) 3>&1 | \
54-
grep -v -e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES)))
55-
56-
# memoize allpackages, so that it's executed only once and only if used
57-
allpackages = $(if $(__allpackages),,$(eval __allpackages := $$(_allpackages)))$(__allpackages)

features/mysql_test.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@ func (s *MysqlTestSuite) TestExample() {
3939

4040
rdr, err := reader.Connect(reader.ConnOpts{DSN: readDSN, Timeout: s.timeout})
4141
s.Require().NoError(err, "Unable to create reader")
42-
defer rdr.Close()
42+
defer func() {
43+
err := rdr.Close()
44+
s.Assert().NoError(err)
45+
}()
4346

4447
dmp, err := dumper.NewDumper(dumper.ConnOpts{DSN: dumpDSN}, rdr)
4548
s.Require().NoError(err, "Unable to create dumper")
46-
defer dmp.Close()
49+
defer func() {
50+
err := dmp.Close()
51+
s.Assert().NoError(err)
52+
}()
4753

4854
done := make(chan struct{})
4955
defer close(done)
@@ -75,7 +81,8 @@ func (s *MysqlTestSuite) TearDownSuite() {
7581
s.dropDatabase(db)
7682
}
7783

78-
s.rootConnection.Close()
84+
err := s.rootConnection.Close()
85+
s.Assert().NoError(err)
7986
}
8087

8188
func (s *MysqlTestSuite) createDatabase(name string) string {
@@ -102,7 +109,10 @@ func (s *MysqlTestSuite) loadFixture(dsn string, file string) {
102109
s.Require().NoError(err, "Unable to load fixture file")
103110

104111
conn, err := sql.Open("mysql", dsn)
105-
defer conn.Close()
112+
defer func() {
113+
err := conn.Close()
114+
s.Assert().NoError(err)
115+
}()
106116
s.Require().NoError(err, "Unable to open db connection to load fixture")
107117

108118
_, err = conn.Exec(string(data))
@@ -112,11 +122,17 @@ func (s *MysqlTestSuite) loadFixture(dsn string, file string) {
112122
func (s *MysqlTestSuite) assertDatabaseAreTheSame(expectedDSN string, dumpDSN string) {
113123
sourceConn, err := sql.Open("mysql", expectedDSN)
114124
s.Require().NoError(err, "Unable to connect to source db")
115-
defer sourceConn.Close()
125+
defer func() {
126+
err := sourceConn.Close()
127+
s.Assert().NoError(err)
128+
}()
116129

117130
targetConn, err := sql.Open("mysql", dumpDSN)
118131
s.Require().NoError(err, "Unable to connect to target db")
119-
defer targetConn.Close()
132+
defer func() {
133+
err := targetConn.Close()
134+
s.Assert().NoError(err)
135+
}()
120136

121137
tables := s.fetchTableRowCount(sourceConn)
122138
s.Require().Equal(tables, s.fetchTableRowCount(targetConn))
@@ -142,7 +158,7 @@ func (s *MysqlTestSuite) fetchTableRowCount(db *sql.DB) []tableInfo {
142158
s.Require().NoError(err, "Unable to fetch table info")
143159
defer tableRows.Close()
144160

145-
tables := []tableInfo{}
161+
var tables []tableInfo
146162
for tableRows.Next() {
147163
table := tableInfo{}
148164

@@ -163,11 +179,17 @@ func (s *MysqlTestSuite) compareTable(source *sql.DB, target *sql.DB, table stri
163179

164180
expectedRows, err := source.Query(query)
165181
assert.NoError(err, "Unable to query source table")
166-
defer expectedRows.Close()
182+
defer func() {
183+
err := expectedRows.Close()
184+
s.Assert().NoError(err)
185+
}()
167186

168187
rows, err := target.Query(query)
169188
assert.NoError(err, "Unable to query target table")
170-
defer rows.Close()
189+
defer func() {
190+
err := rows.Close()
191+
s.Assert().NoError(err)
192+
}()
171193

172194
for expectedRows.Next() {
173195
assert.True(rows.Next(), "target row mismatch")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/hellofresh/klepto
22

3-
go 1.13
3+
go 1.14
44

55
require (
66
github.com/BurntSushi/toml v0.3.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf
171171
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
172172
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
173173
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
174+
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0=
174175
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
175176
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
176177
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -207,6 +208,7 @@ golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGm
207208
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
208209
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
209210
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
211+
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384 h1:TFlARGu6Czu1z7q93HTxcP1P+/ZFC/IKythI5RzrnRg=
210212
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
211213
google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs=
212214
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=

0 commit comments

Comments
 (0)