Skip to content
This repository has been archived by the owner on Nov 12, 2021. It is now read-only.

Commit

Permalink
Run golangci-lint as part of pull request workflow louketo#604
Browse files Browse the repository at this point in the history
- Merge build and linter jobs in a single file
- Runs tests for go 1.13 and 1.14
- Introduces code coverage with coveralls
- Fixes some issues reported by golangci-lint and relax/disable some
rules until the codebase is refactored

Resolves louketo#604
  • Loading branch information
Bruno Oliveira da Silva committed May 14, 2020
1 parent c500821 commit 3516f6d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build & Lint

# Only trigger the event on pull-requests
on: [pull_request]

jobs:
build:
name: Build
runs-on: ubuntu-latest
# Test the latest release of Go
strategy:
matrix:
go: [ '1.14', '1.13' ]
steps:
# Setup the workflow to use the specific version of Go
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
id: go
# Checkout the repository
- name: Checkout
uses: actions/checkout@v2
# Verify downloaded dependencies
- name: Verify dependencies
run: go mod verify
# Run tests and generates a coverage profile
- name: Test
run: |
go test -v -coverprofile=profile.cov ./...
# Run Go benchmarks
- name: Benchmark
run: |
go test -bench=. -benchmem
# Sends code coverage report to Coveralls
- name: Coveralls
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
GO111MODULE=off go get github.com/mattn/goveralls
$(go env GOPATH)/bin/goveralls -coverprofile=profile.cov -service=github
# Run the linter as a separate job
golangci:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v0.1.7
with:
version: v1.26
github-token: "${{ secrets.GITHUB_TOKEN }}"
16 changes: 14 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ linters-settings:
golint:
min-confidence: 0
gocyclo:
min-complexity: 60
min-complexity: 64
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2

# TODO: Revisit after the refactor
funlen:
lines: 220
statements: 110

linters:
enable-all: true
disable:
Expand All @@ -21,3 +25,11 @@ linters:
- lll
- gochecknoinits
- gochecknoglobals
- dupl
- wsl
- godox
- gomnd
# TODO: Revisit after the refactor
- gocognit
- goerr113
- testpackage
2 changes: 0 additions & 2 deletions forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
zap.String("subject", state.identity.ID),
zap.String("email", state.identity.Email),
zap.String("expires", state.expiration.Format(time.RFC3339)))

} else {
r.log.Info("access token is about to expiry",
zap.String("subject", state.identity.ID),
Expand Down Expand Up @@ -182,7 +181,6 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
zap.String("subject", state.identity.ID),
zap.String("email", state.identity.Email),
zap.String("expires", state.expiration.Format(time.RFC3339)))

} else {
r.log.Info("session does not support refresh token, acquiring new token",
zap.String("subject", state.identity.ID),
Expand Down
1 change: 0 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ func (r *oauthProxy) createHTTPListener(config listenerConfig) (net.Listener, er
return nil, err
}
getCertificate = rotate.GetCertificate

}

if config.useFileTLS {
Expand Down
3 changes: 1 addition & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
cryptorand "crypto/rand"
"crypto/rsa"
sha "crypto/sha256"
Expand Down Expand Up @@ -70,7 +69,7 @@ var (
// createCertificate is responsible for creating a certificate
func createCertificate(key *rsa.PrivateKey, hostnames []string, expire time.Duration) (tls.Certificate, error) {
// @step: create a serial for the certificate
serial, err := cryptorand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128))
serial, err := cryptorand.Int(cryptorand.Reader, new(big.Int).Lsh(big.NewInt(1), 128))
if err != nil {
return tls.Certificate{}, err
}
Expand Down
1 change: 0 additions & 1 deletion utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ func TestDecryptDataBlock(t *testing.T) {
t.Errorf("test case: %d are not the same", i)
}
}

}

func TestHasAccessOK(t *testing.T) {
Expand Down

0 comments on commit 3516f6d

Please sign in to comment.