Skip to content

Commit ba93ce6

Browse files
authored
Merge pull request #12 from vgarvardt/patch/gh-actions
Added GH Actions pipeline
2 parents 0409aac + 685297f commit ba93ce6

File tree

12 files changed

+224
-107
lines changed

12 files changed

+224
-107
lines changed

.github/workflows/testing.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
steps:
42+
- name: Set up Go
43+
uses: actions/setup-go@v2
44+
- name: Check out code
45+
uses: actions/checkout@v2
46+
- name: Run tests
47+
if: success()
48+
run: go test -timeout 60s -cover ./... -coverprofile=coverage.txt -covermode=atomic
49+
env:
50+
PG_URI: postgres://test:test@localhost:${{ job.services.postgres.ports[5432] }}/test?sslmode=disable
51+
52+
- name: Upload coverage to Codecov
53+
uses: codecov/codecov-action@v1
54+
if: success()
55+
with:
56+
file: ./coverage.txt
57+
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+
fast: false
7+
enable:
8+
- gofmt
9+
- golint
10+
- goimports
11+
linters-settings:
12+
gofmt:
13+
simplify: false
14+
issues:
15+
exclude-use-default: false

.travis.yml

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

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Vladimir Garvardt
3+
Copyright (c) 2020 Vladimir Garvardt
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
lint:
2+
@echo "$(OK_COLOR)==> Linting with golangci-lint$(NO_COLOR)"
3+
@docker run --rm -v `pwd`:/app -w /app golangci/golangci-lint:v1.27.0 golangci-lint run -v
4+
5+
test:
6+
@echo "$(OK_COLOR)==> Running tests using docker-compose deps$(NO_COLOR)"
7+
@docker-compose up -d
8+
@sleep 3 && \
9+
PG_URI="postgres://test:test@`docker-compose port postgres 5432`/test?sslmode=disable" \
10+
go test -timeout 60s -cover -coverprofile=coverage.txt -covermode=atomic ./...

README.md

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# PostgreSQL Storage for [OAuth 2.0](https://github.com/go-oauth2/oauth2)
22

3-
[![Build][Build-Status-Image]][Build-Status-Url] [![Codecov][codecov-image]][codecov-url] [![ReportCard][reportcard-image]][reportcard-url] [![GoDoc][godoc-image]][godoc-url] [![License][license-image]][license-url]
3+
[![GoDoc](https://godoc.org/github.com/vgarvardt/go-oauth2-pg?status.svg)](https://godoc.org/github.com/vgarvardt/go-oauth2-pg)
4+
[![Coverage Status](https://codecov.io/gh/vgarvardt/go-oauth2-pg/branch/master/graph/badge.svg)](https://codecov.io/gh/vgarvardt/go-oauth2-pg)
5+
[![ReportCard](https://goreportcard.com/badge/github.com/vgarvardt/go-oauth2-pg)](https://goreportcard.com/report/github.com/vgarvardt/go-oauth2-pg)
6+
[![License](https://img.shields.io/npm/l/express.svg)](http://opensource.org/licenses/MIT)
47

58
## Install
69

710
```bash
8-
$ go get -u -v github.com/vgarvardt/go-oauth2-pg
11+
$ go get -u github.com/vgarvardt/go-oauth2-pg
912
```
1013

1114
## PostgreSQL drivers
@@ -48,31 +51,19 @@ func main() {
4851

4952
## How to run tests
5053

51-
You will need running PostgreSQL instance. E.g. the one running in docker and exposing a port to a host system
54+
## Testing
5255

53-
```bash
54-
docker run --rm -p 5432:5432 -it -e POSTGRES_PASSWORD=oauth2 -e POSTGRES_USER=oauth2 -e POSTGRES_DB=oauth2 postgres:10
55-
```
56+
Linter and tests are running for every Pul Request, but it is possible to run linter
57+
and tests locally using `docker` and `make`.
5658

57-
Now you can run tests using the running PostgreSQL instance using `PG_URI` environment variable
59+
Run linter: `make link`. This command runs liner in docker container with the project
60+
source code mounted.
5861

59-
```bash
60-
PG_URI=postgres://oauth2:oauth2@localhost:5432/oauth2?sslmode=disable go test -cover ./...
61-
```
62+
Run tests: `make test`. This command runs project dependencies in docker containers
63+
if they are not started yet and runs go tests with coverage.
6264

6365
## MIT License
6466

6567
```
66-
Copyright (c) 2019 Vladimir Garvardt
68+
Copyright (c) 2020 Vladimir Garvardt
6769
```
68-
69-
[Build-Status-Url]: https://travis-ci.org/vgarvardt/go-oauth2-pg
70-
[Build-Status-Image]: https://travis-ci.org/vgarvardt/go-oauth2-pg.svg?branch=master
71-
[codecov-url]: https://codecov.io/gh/vgarvardt/go-oauth2-pg
72-
[codecov-image]: https://codecov.io/gh/vgarvardt/go-oauth2-pg/branch/master/graph/badge.svg
73-
[reportcard-url]: https://goreportcard.com/report/github.com/vgarvardt/go-oauth2-pg
74-
[reportcard-image]: https://goreportcard.com/badge/github.com/vgarvardt/go-oauth2-pg
75-
[godoc-url]: https://godoc.org/github.com/vgarvardt/go-oauth2-pg
76-
[godoc-image]: https://godoc.org/github.com/vgarvardt/go-oauth2-pg?status.svg
77-
[license-url]: http://opensource.org/licenses/MIT
78-
[license-image]: https://img.shields.io/npm/l/express.svg

client_store.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ package pg
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"log"
78
"os"
89

9-
"github.com/json-iterator/go"
1010
"gopkg.in/oauth2.v3"
1111
"gopkg.in/oauth2.v3/models"
1212

13-
"github.com/vgarvardt/go-pg-adapter"
13+
pgAdapter "github.com/vgarvardt/go-pg-adapter"
1414
)
1515

1616
// ClientStore PostgreSQL client store
1717
type ClientStore struct {
18-
adapter pgadapter.Adapter
18+
adapter pgAdapter.Adapter
1919
tableName string
2020
logger Logger
2121

@@ -31,7 +31,7 @@ type ClientStoreItem struct {
3131
}
3232

3333
// NewClientStore creates PostgreSQL store instance
34-
func NewClientStore(adapter pgadapter.Adapter, options ...ClientStoreOption) (*ClientStore, error) {
34+
func NewClientStore(adapter pgAdapter.Adapter, options ...ClientStoreOption) (*ClientStore, error) {
3535
store := &ClientStore{
3636
adapter: adapter,
3737
tableName: "oauth2_clients",
@@ -68,7 +68,7 @@ CREATE TABLE IF NOT EXISTS %[1]s (
6868

6969
func (s *ClientStore) toClientInfo(data []byte) (oauth2.ClientInfo, error) {
7070
var cm models.Client
71-
err := jsoniter.Unmarshal(data, &cm)
71+
err := json.Unmarshal(data, &cm)
7272
return &cm, err
7373
}
7474

@@ -88,7 +88,7 @@ func (s *ClientStore) GetByID(id string) (oauth2.ClientInfo, error) {
8888

8989
// Create creates and stores the new client information
9090
func (s *ClientStore) Create(info oauth2.ClientInfo) error {
91-
data, err := jsoniter.Marshal(info)
91+
data, err := json.Marshal(info)
9292
if err != nil {
9393
return err
9494
}

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: "3"
2+
3+
services:
4+
postgres:
5+
image: postgres:9.6-alpine
6+
ports:
7+
- '5432'
8+
environment:
9+
LC_ALL: C.UTF-8
10+
POSTGRES_USER: test
11+
POSTGRES_PASSWORD: test
12+
POSTGRES_DB: test
13+
tmpfs:
14+
- /var/lib/postgresql/data
15+
healthcheck:
16+
test: ["CMD", "pg_isready"]
17+
interval: 10s
18+
timeout: 5s
19+
retries: 5

go.mod

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
module github.com/vgarvardt/go-oauth2-pg
22

3-
go 1.12
3+
go 1.14
44

55
require (
6-
github.com/jackc/pgx/v4 v4.4.1
6+
github.com/jackc/pgconn v1.6.0 // indirect
7+
github.com/jackc/pgx/v4 v4.6.0
78
github.com/jmoiron/sqlx v1.2.0
8-
github.com/json-iterator/go v1.1.7
9-
github.com/stretchr/testify v1.4.0
9+
github.com/stretchr/testify v1.6.1
1010
github.com/vgarvardt/go-pg-adapter v0.4.1
11-
gopkg.in/oauth2.v3 v3.10.1
11+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
12+
golang.org/x/text v0.3.3 // indirect
13+
gopkg.in/oauth2.v3 v3.12.0
14+
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
1215
)

0 commit comments

Comments
 (0)