Skip to content

Commit

Permalink
Merge pull request #119 from hellofresh/patch/gh-actions
Browse files Browse the repository at this point in the history
PT-7159 Added GH Actions pipeline
  • Loading branch information
vgarvardt authored Jun 10, 2020
2 parents b572200 + 85a1df4 commit ee68056
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 94 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Testing

on:
release:
types:
- created

jobs:
goreleaser:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v2
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
if: startsWith(github.ref, 'refs/tags/')
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73 changes: 73 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Testing

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v1
with:
version: v1.27

test:
name: Test
runs-on: ubuntu-latest
needs: [lint]

services:
postgres:
image: postgres:9.6-alpine
ports:
- "5432"
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
mysql:
image: mysql:5.7
ports:
- "3306"
env:
MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
options: >-
--health-cmd "mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Set up Go
uses: actions/setup-go@v2
- name: Check out code
uses: actions/checkout@v2
- name: Run tests
if: success()
run: go test -cover ./... -coverprofile=coverage.txt -covermode=atomic
env:
TEST_POSTGRES: postgres://test:test@localhost:${{ job.services.postgres.ports[5432] }}/?sslmode=disable
TEST_MYSQL: root:test@tcp(localhost:${{ job.services.mysql.ports[3306] }})/?charset=utf8

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
if: success()
with:
file: ./coverage.txt
fail_ci_if_error: false
15 changes: 15 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See https://golangci-lint.run/usage/configuration/#config-file for more information
run:
timeout: 5m
linters:
disable-all: true
enable:
- gofmt
- golint
- goimports
fast: false
linters-settings:
gofmt:
simplify: false
issues:
exclude-use-default: false
41 changes: 0 additions & 41 deletions .travis.yml

This file was deleted.

46 changes: 3 additions & 43 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,15 @@ OK_COLOR=\033[32;01m
ERROR_COLOR=\033[31;01m
WARN_COLOR=\033[33;01m

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

.PHONY: all clean deps build

all: clean deps build

deps:
@echo "$(OK_COLOR)==> Installing dependencies$(NO_COLOR)"
@go get -u golang.org/x/lint/golint
@go mod vendor
all: test build

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

test: lint format vet
test:
@echo "$(OK_COLOR)==> Running tests$(NO_COLOR)"
@CGO_ENABLED=0 go test -cover ./... -coverprofile=coverage.txt -covermode=atomic

lint:
@echo "$(OK_COLOR)==> Checking code style with 'golint' tool$(NO_COLOR)"
@go list ./... | xargs -n 1 golint -set_exit_status

format:
@echo "$(OK_COLOR)==> Checking code formating with 'gofmt' tool$(NO_COLOR)"
@gofmt -l -s cmd pkg | grep ".*\.go"; if [ "$$?" = "0" ]; then exit 1; fi

vet:
@echo "$(OK_COLOR)==> Checking code correctness with 'go vet' tool$(NO_COLOR)"
@go vet ./...

test-docker:
docker-compose up -d
@TEST_POSTGRES="postgres://hello:fresh@localhost:8050/klepto?sslmode=disable" \
TEST_MYSQL="root:hellofresh@tcp(localhost:8052)/" \
/bin/sh -c "./build/test.sh $(allpackages)"

# Cleans our project: deletes binaries
clean:
@echo "$(OK_COLOR)==> Cleaning project$(NO_COLOR)"
@go clean
@rm -rf dist

# cd into the GOPATH to workaround ./... not following symlinks
_allpackages = $(shell ( go list ./... 2>&1 1>&3 | \
grep -v -e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES)) 1>&2 ) 3>&1 | \
grep -v -e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES)))

# memoize allpackages, so that it's executed only once and only if used
allpackages = $(if $(__allpackages),,$(eval __allpackages := $$(_allpackages)))$(__allpackages)
40 changes: 31 additions & 9 deletions features/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ func (s *MysqlTestSuite) TestExample() {

rdr, err := reader.Connect(reader.ConnOpts{DSN: readDSN, Timeout: s.timeout})
s.Require().NoError(err, "Unable to create reader")
defer rdr.Close()
defer func() {
err := rdr.Close()
s.Assert().NoError(err)
}()

dmp, err := dumper.NewDumper(dumper.ConnOpts{DSN: dumpDSN}, rdr)
s.Require().NoError(err, "Unable to create dumper")
defer dmp.Close()
defer func() {
err := dmp.Close()
s.Assert().NoError(err)
}()

done := make(chan struct{})
defer close(done)
Expand Down Expand Up @@ -75,7 +81,8 @@ func (s *MysqlTestSuite) TearDownSuite() {
s.dropDatabase(db)
}

s.rootConnection.Close()
err := s.rootConnection.Close()
s.Assert().NoError(err)
}

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

conn, err := sql.Open("mysql", dsn)
defer conn.Close()
defer func() {
err := conn.Close()
s.Assert().NoError(err)
}()
s.Require().NoError(err, "Unable to open db connection to load fixture")

_, err = conn.Exec(string(data))
Expand All @@ -112,11 +122,17 @@ func (s *MysqlTestSuite) loadFixture(dsn string, file string) {
func (s *MysqlTestSuite) assertDatabaseAreTheSame(expectedDSN string, dumpDSN string) {
sourceConn, err := sql.Open("mysql", expectedDSN)
s.Require().NoError(err, "Unable to connect to source db")
defer sourceConn.Close()
defer func() {
err := sourceConn.Close()
s.Assert().NoError(err)
}()

targetConn, err := sql.Open("mysql", dumpDSN)
s.Require().NoError(err, "Unable to connect to target db")
defer targetConn.Close()
defer func() {
err := targetConn.Close()
s.Assert().NoError(err)
}()

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

tables := []tableInfo{}
var tables []tableInfo
for tableRows.Next() {
table := tableInfo{}

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

expectedRows, err := source.Query(query)
assert.NoError(err, "Unable to query source table")
defer expectedRows.Close()
defer func() {
err := expectedRows.Close()
s.Assert().NoError(err)
}()

rows, err := target.Query(query)
assert.NoError(err, "Unable to query target table")
defer rows.Close()
defer func() {
err := rows.Close()
s.Assert().NoError(err)
}()

for expectedRows.Next() {
assert.True(rows.Next(), "target row mismatch")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/hellofresh/klepto

go 1.13
go 1.14

require (
github.com/BurntSushi/toml v0.3.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -207,6 +208,7 @@ golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384 h1:TFlARGu6Czu1z7q93HTxcP1P+/ZFC/IKythI5RzrnRg=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
Expand Down

0 comments on commit ee68056

Please sign in to comment.