Skip to content

Commit

Permalink
ci: switch Go 1.5 and to the official golangci's action
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Sep 16, 2020
1 parent bcc6b16 commit 96eefc3
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.14'
go-version: '1.15'
- name: Docker Hub Login
run: docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
env:
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ env:
GO111MODULE: 'on'

jobs:
lint:
golangci:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@master
- name: Lint Go Code
uses: docker://golangci/golangci-lint:latest
with:
args: golangci-lint run ./...
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: latest

test:
name: Test
Expand All @@ -28,7 +27,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.14'
go-version: '1.15'
- name: Install project dependencies
run: go get
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{ // nolint:gochecknoglobals
var rootCmd = &cobra.Command{ //nolint:gochecknoglobals
Use: "mercure",
Short: "Start the Mercure Hub",
Long: `Mercure is a protocol allowing to push data updates to web browsers and
Expand All @@ -31,7 +31,7 @@ func Execute() {
}
}

func init() { // nolint:gochecknoinits
func init() { //nolint:gochecknoinits
v := viper.GetViper()
cobra.OnInitialize(func() {
hub.InitConfig(v)
Expand Down
8 changes: 4 additions & 4 deletions common/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ type AppVersionInfo struct {
Architecture string
}

var AppVersion AppVersionInfo // nolint:gochecknoglobals
var AppVersion AppVersionInfo //nolint:gochecknoglobals

// these variables are dynamically set at build.
var (
version = "dev"
buildDate = "" // nolint:gochecknoglobals
commit = "" // nolint:gochecknoglobals
buildDate = "" //nolint:gochecknoglobals
commit = "" //nolint:gochecknoglobals
)

func (v *AppVersionInfo) Shortline() string {
Expand Down Expand Up @@ -78,7 +78,7 @@ func (v *AppVersionInfo) NewMetricsCollector() *prometheus.GaugeVec {
return buildInfo
}

func init() { // nolint:gochecknoinits
func init() { //nolint:gochecknoinits
if version == "dev" {
info, ok := debug.ReadBuildInfo()
if ok && info.Main.Version != "(devel)" {
Expand Down
16 changes: 8 additions & 8 deletions hub/authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestAuthorizeMultipleAuthorizationHeader(t *testing.T) {
}

func TestAuthorizeMultipleAuthorizationHeaderRsa(t *testing.T) {
r, _ := http.NewRequest("GET", defaultHubURL, nil) // nolint:noctx
r, _ := http.NewRequest("GET", defaultHubURL, nil) //nolint:noctx
r.Header.Add("Authorization", validEmptyHeaderRsa)
r.Header.Add("Authorization", validEmptyHeaderRsa)

Expand Down Expand Up @@ -154,7 +154,7 @@ func TestAuthorizeAuthorizationHeader(t *testing.T) {
}

func TestAuthorizeAuthorizationHeaderRsa(t *testing.T) {
r, _ := http.NewRequest("GET", defaultHubURL, nil) // nolint:noctx
r, _ := http.NewRequest("GET", defaultHubURL, nil) //nolint:noctx
r.Header.Add("Authorization", "Bearer "+validFullHeaderRsa)

claims, err := authorize(r, []byte(publicKeyRsa), rsaSigningMethod, []string{})
Expand All @@ -164,7 +164,7 @@ func TestAuthorizeAuthorizationHeaderRsa(t *testing.T) {
}

func TestAuthorizeAuthorizationHeaderWrongAlgorithm(t *testing.T) {
r, _ := http.NewRequest("GET", defaultHubURL, nil) // nolint:noctx
r, _ := http.NewRequest("GET", defaultHubURL, nil) //nolint:noctx
r.Header.Add("Authorization", "Bearer "+validFullHeaderRsa)

claims, err := authorize(r, []byte(publicKeyRsa), nil, []string{})
Expand All @@ -173,7 +173,7 @@ func TestAuthorizeAuthorizationHeaderWrongAlgorithm(t *testing.T) {
}

func TestAuthorizeCookieInvalidAlg(t *testing.T) {
r, _ := http.NewRequest("GET", defaultHubURL, nil) // nolint:noctx
r, _ := http.NewRequest("GET", defaultHubURL, nil) //nolint:noctx
r.AddCookie(&http.Cookie{Name: "mercureAuthorization", Value: createDummyNoneSignedJWT()})

claims, err := authorize(r, []byte{}, hmacSigningMethod, []string{})
Expand All @@ -191,7 +191,7 @@ func TestAuthorizeCookieInvalidKey(t *testing.T) {
}

func TestAuthorizeCookieEmptyKeyRsa(t *testing.T) {
r, _ := http.NewRequest("GET", defaultHubURL, nil) // nolint:noctx
r, _ := http.NewRequest("GET", defaultHubURL, nil) //nolint:noctx
r.AddCookie(&http.Cookie{Name: "mercureAuthorization", Value: validEmptyHeaderRsa})

claims, err := authorize(r, []byte{}, rsaSigningMethod, []string{})
Expand Down Expand Up @@ -258,7 +258,7 @@ func TestAuthorizeCookieNoOriginNoReferer(t *testing.T) {
}

func TestAuthorizeCookieNoOriginNoRefererRsa(t *testing.T) {
r, _ := http.NewRequest("POST", defaultHubURL, nil) // nolint:noctx
r, _ := http.NewRequest("POST", defaultHubURL, nil) //nolint:noctx
r.AddCookie(&http.Cookie{Name: "mercureAuthorization", Value: validFullHeaderRsa})

claims, err := authorize(r, []byte(publicKeyRsa), rsaSigningMethod, []string{})
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestAuthorizeCookieInvalidReferer(t *testing.T) {
}

func TestAuthorizeCookieInvalidRefererRsa(t *testing.T) {
r, _ := http.NewRequest("POST", defaultHubURL, nil) // nolint:noctx
r, _ := http.NewRequest("POST", defaultHubURL, nil) //nolint:noctx
r.Header.Add("Referer", "http://192.168.0.%31/")
r.AddCookie(&http.Cookie{Name: "mercureAuthorization", Value: validFullHeaderRsa})

Expand All @@ -339,7 +339,7 @@ func TestAuthorizeCookieOriginHasPriority(t *testing.T) {
}

func TestAuthorizeCookieOriginHasPriorityRsa(t *testing.T) {
r, _ := http.NewRequest("POST", defaultHubURL, nil) // nolint:noctx
r, _ := http.NewRequest("POST", defaultHubURL, nil) //nolint:noctx
r.Header.Add("Origin", "http://example.net")
r.Header.Add("Referer", "http://example.com")
r.AddCookie(&http.Cookie{Name: "mercureAuthorization", Value: validFullHeaderRsa})
Expand Down
2 changes: 1 addition & 1 deletion hub/bolt_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (t *BoltTransport) cleanup(bucket *bolt.Bucket, lastID uint64) error {
if t.size == 0 ||
t.cleanupFrequency == 0 ||
t.size >= lastID ||
(t.cleanupFrequency != 1 && rand.Float64() < t.cleanupFrequency) { // nolint:gosec
(t.cleanupFrequency != 1 && rand.Float64() < t.cleanupFrequency) { //nolint:gosec
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion hub/hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestStartCrash(t *testing.T) {

return
}
cmd := exec.Command(os.Args[0], "-test.run=TestStartCrash") // nolint:gosec
cmd := exec.Command(os.Args[0], "-test.run=TestStartCrash") //nolint:gosec
cmd.Env = append(os.Environ(), "BE_START_CRASH=1")
err := cmd.Run()

Expand Down
48 changes: 24 additions & 24 deletions hub/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func TestForwardedHeaders(t *testing.T) {
// loop until the web server is ready
var resp *http.Response
for resp == nil {
resp, _ = client.Get(testURL) // nolint:bodyclose,noctx
resp, _ = client.Get(testURL) //nolint:bodyclose,noctx
}
defer resp.Body.Close()

body := url.Values{"topic": {"http://example.com/test-forwarded"}, "data": {"hello"}}
req, _ := http.NewRequest("POST", testURL, strings.NewReader(body.Encode())) // nolint:noctx
req, _ := http.NewRequest("POST", testURL, strings.NewReader(body.Encode())) //nolint:noctx
req.Header.Add("X-Forwarded-For", "192.0.2.1")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "Bearer "+createDummyAuthorizedJWT(h, rolePublisher, []string{}))
Expand Down Expand Up @@ -71,14 +71,14 @@ func TestSecurityOptions(t *testing.T) {

// This is a self-signed certificate
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // nolint:gosec
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec
}
client := http.Client{Transport: transport, Timeout: 100 * time.Millisecond}

// loop until the web server is ready
var resp *http.Response
for resp == nil {
resp, _ = client.Get(testSecureURL) // nolint:bodyclose,noctx
resp, _ = client.Get(testSecureURL) //nolint:bodyclose,noctx
}

assert.Equal(t, "default-src 'self' mercure.rocks cdn.jsdelivr.net", resp.Header.Get("Content-Security-Policy"))
Expand All @@ -88,7 +88,7 @@ func TestSecurityOptions(t *testing.T) {
resp.Body.Close()

// Preflight request
req, _ := http.NewRequest("OPTIONS", testSecureURL, nil) // nolint:noctx
req, _ := http.NewRequest("OPTIONS", testSecureURL, nil) //nolint:noctx
req.Header.Add("Origin", "https://example.com")
req.Header.Add("Access-Control-Request-Headers", "authorization")
req.Header.Add("Access-Control-Request-Method", "GET")
Expand All @@ -101,7 +101,7 @@ func TestSecurityOptions(t *testing.T) {
resp2.Body.Close()

// Subscriptions
req, _ = http.NewRequest("GET", testSecureURL+"/subscriptions", nil) // nolint:noctx
req, _ = http.NewRequest("GET", testSecureURL+"/subscriptions", nil) //nolint:noctx
resp3, _ := client.Do(req)
require.NotNil(t, resp3)
assert.Equal(t, http.StatusUnauthorized, resp3.StatusCode)
Expand All @@ -119,20 +119,20 @@ func TestServe(t *testing.T) {
var resp *http.Response
client := http.Client{Timeout: 100 * time.Millisecond}
for resp == nil {
resp, _ = client.Get("http://" + testAddr + "/") // nolint:bodyclose,noctx
resp, _ = client.Get("http://" + testAddr + "/") //nolint:bodyclose,noctx
}
defer resp.Body.Close()

hpBody, _ := ioutil.ReadAll(resp.Body)
assert.Contains(t, string(hpBody), "Mercure Hub")

respHealthz, err := client.Get("http://" + testAddr + "/healthz") // nolint:noctx
respHealthz, err := client.Get("http://" + testAddr + "/healthz") //nolint:noctx
require.Nil(t, err)
defer respHealthz.Body.Close()
healthzBody, _ := ioutil.ReadAll(respHealthz.Body)
assert.Contains(t, string(healthzBody), "ok")

respMetrics, err := client.Get("http://" + testAddr + "/metrics") // nolint:noctx
respMetrics, err := client.Get("http://" + testAddr + "/metrics") //nolint:noctx
require.Nil(t, err)
defer respMetrics.Body.Close()
assert.Equal(t, 404, respMetrics.StatusCode)
Expand All @@ -143,7 +143,7 @@ func TestServe(t *testing.T) {

go func() {
defer wgTested.Done()
resp, err := client.Get(testURL + "?topic=http%3A%2F%2Fexample.com%2Ffoo%2F1") // nolint:noctx
resp, err := client.Get(testURL + "?topic=http%3A%2F%2Fexample.com%2Ffoo%2F1") //nolint:noctx
require.Nil(t, err)
wgConnected.Done()

Expand All @@ -155,7 +155,7 @@ func TestServe(t *testing.T) {

go func() {
defer wgTested.Done()
resp, err := client.Get(testURL + "?topic=http%3A%2F%2Fexample.com%2Falt%2F1") // nolint:noctx
resp, err := client.Get(testURL + "?topic=http%3A%2F%2Fexample.com%2Falt%2F1") //nolint:noctx
require.Nil(t, err)
wgConnected.Done()

Expand All @@ -168,7 +168,7 @@ func TestServe(t *testing.T) {
wgConnected.Wait()

body := url.Values{"topic": {"http://example.com/foo/1", "http://example.com/alt/1"}, "data": {"hello"}, "id": {"first"}}
req, _ := http.NewRequest("POST", testURL, strings.NewReader(body.Encode())) // nolint:noctx
req, _ := http.NewRequest("POST", testURL, strings.NewReader(body.Encode())) //nolint:noctx
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "Bearer "+createDummyAuthorizedJWT(h, rolePublisher, []string{}))

Expand All @@ -192,7 +192,7 @@ func TestClientClosesThenReconnects(t *testing.T) {
var resp *http.Response
client := http.Client{Timeout: 10 * time.Second}
for resp == nil {
resp, _ = client.Get("http://" + testAddr + "/") // nolint:bodyclose,noctx
resp, _ = client.Get("http://" + testAddr + "/") //nolint:bodyclose,noctx
}
resp.Body.Close()

Expand Down Expand Up @@ -236,7 +236,7 @@ func TestClientClosesThenReconnects(t *testing.T) {
}

body := url.Values{"topic": {"http://example.com/foo/1"}, "data": {data}, "id": {data}}
req, err := http.NewRequest("POST", testURL, strings.NewReader(body.Encode())) // nolint:noctx
req, err := http.NewRequest("POST", testURL, strings.NewReader(body.Encode())) //nolint:noctx
require.Nil(t, err)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "Bearer "+createDummyAuthorizedJWT(h, rolePublisher, []string{}))
Expand Down Expand Up @@ -297,14 +297,14 @@ func TestServeAcme(t *testing.T) {

var resp *http.Response
for resp == nil {
resp, _ = client.Get("http://127.0.0.1:8080") // nolint:bodyclose,noctx
resp, _ = client.Get("http://127.0.0.1:8080") //nolint:bodyclose,noctx
}

require.NotNil(t, resp)
assert.Equal(t, 302, resp.StatusCode)
resp.Body.Close()

resp, err := client.Get("http://0.0.0.0:8080/.well-known/acme-challenge/does-not-exists") // nolint:noctx
resp, err := client.Get("http://0.0.0.0:8080/.well-known/acme-challenge/does-not-exists") //nolint:noctx
assert.Nil(t, err)
require.NotNil(t, resp)
defer resp.Body.Close()
Expand All @@ -319,7 +319,7 @@ func TestMetricsAccessWithDisableAuthentication(t *testing.T) {
server := newTestServer(t, v)
defer server.shutdown()

resp, err := server.client.Get("http://" + testAddr + "/metrics") // nolint:noctx
resp, err := server.client.Get("http://" + testAddr + "/metrics") //nolint:noctx
require.Nil(t, err)
defer resp.Body.Close()

Expand All @@ -334,7 +334,7 @@ func TestMetricsAccessWithRequiredAuthentication(t *testing.T) {
server := newTestServer(t, v)
defer server.shutdown()

req, _ := http.NewRequest("GET", "http://"+testAddr+"/metrics", nil) // nolint:noctx
req, _ := http.NewRequest("GET", "http://"+testAddr+"/metrics", nil) //nolint:noctx
req.SetBasicAuth("foo", "bar")

resp, err := server.client.Do(req)
Expand All @@ -352,7 +352,7 @@ func TestMetricsAccessWithWrongAuthentication(t *testing.T) {
server := newTestServer(t, v)
defer server.shutdown()

req, _ := http.NewRequest("GET", "http://"+testAddr+"/metrics", nil) // nolint:noctx
req, _ := http.NewRequest("GET", "http://"+testAddr+"/metrics", nil) //nolint:noctx
req.SetBasicAuth("john", "doe")

resp, err := server.client.Do(req)
Expand Down Expand Up @@ -394,7 +394,7 @@ func TestMetricsVersionIsAccessible(t *testing.T) {
server := newTestServer(t, v)
defer server.shutdown()

resp, err := server.client.Get("http://" + testAddr + "/metrics") // nolint:noctx
resp, err := server.client.Get("http://" + testAddr + "/metrics") //nolint:noctx
assert.Nil(t, err)
defer resp.Body.Close()

Expand Down Expand Up @@ -424,7 +424,7 @@ func newTestServer(t *testing.T, v *viper.Viper) testServer {
var resp *http.Response
client := http.Client{Timeout: 100 * time.Millisecond}
for resp == nil {
resp, _ = client.Get("http://" + testAddr + "/") // nolint:bodyclose,noctx
resp, _ = client.Get("http://" + testAddr + "/") //nolint:bodyclose,noctx
}
defer resp.Body.Close()

Expand Down Expand Up @@ -453,7 +453,7 @@ func (s *testServer) newSubscriber(topic string, keepAlive bool) {

go func() {
defer s.wgTested.Done()
resp, err := s.client.Get(testURL + "?topic=" + url.QueryEscape(topic)) // nolint:noctx
resp, err := s.client.Get(testURL + "?topic=" + url.QueryEscape(topic)) //nolint:noctx
require.Nil(s.t, err)
defer resp.Body.Close()
s.wgConnected.Done()
Expand All @@ -465,7 +465,7 @@ func (s *testServer) newSubscriber(topic string, keepAlive bool) {
}

func (s *testServer) publish(body url.Values) {
req, _ := http.NewRequest("POST", testURL, strings.NewReader(body.Encode())) // nolint:noctx
req, _ := http.NewRequest("POST", testURL, strings.NewReader(body.Encode())) //nolint:noctx
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "Bearer "+createDummyAuthorizedJWT(s.h, rolePublisher, []string{}))

Expand All @@ -479,7 +479,7 @@ func (s *testServer) waitSubscribers() {
}

func (s *testServer) assertMetric(metric string) {
resp, err := s.client.Get("http://" + testAddr + "/metrics") // nolint:noctx
resp, err := s.client.Get("http://" + testAddr + "/metrics") //nolint:noctx
assert.Nil(s.t, err)
defer resp.Body.Close()

Expand Down

0 comments on commit 96eefc3

Please sign in to comment.