Skip to content

Commit

Permalink
Merge pull request #195 from matysek/mzibrick-ccxdev12103
Browse files Browse the repository at this point in the history
[CCXDEV-12103] Add Github Actions workflows
  • Loading branch information
matysek authored Nov 2, 2023
2 parents 5c36ebe + 0895983 commit 73a14bc
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 89 deletions.
21 changes: 4 additions & 17 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
# Copyright 2022 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
- main
pull_request:
permissions:
Expand All @@ -42,8 +27,10 @@ jobs:

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
args: --timeout=3m

args: >
--enable=goimports,gosimple,nilerr,prealloc,revive,staticcheck,unconvert,unused,whitespace,zerologlint
--timeout=3m
# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/gotests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Go tests

on:
push:
branches:
- master
pull_request:

jobs:
gotests:
runs-on: ubuntu-20.04
strategy:
matrix:
go-version:
- "1.18"
- "1.19"
- "1.20"
- "1.21"
name: Tests for Go ${{ matrix.go-version}}
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Print env vars
run: env
- name: Unit tests
run: make test
- name: Check code coverage
run: ./check_coverage.sh
- name: Display code coverage
run: make coverage
- name: OpenAPI Check
run: make openapi-check
- name: REST API Tests
run: make integration_tests
29 changes: 29 additions & 0 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Go linters

on:
push:
branches:
- main
pull_request:

jobs:
golint:
runs-on: ubuntu-20.04
strategy:
matrix:
go-version:
- "1.18"
- "1.19"
- "1.20"
- "1.21"
name: Linters for Go ${{ matrix.go-version}}
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Build project
run: go build
- name: Style linters
run: make style
15 changes: 15 additions & 0 deletions .github/workflows/shellcheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Shell check

on:
push:
branches:
- main
pull_request:

jobs:
shellcheck:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Shell check
run: ./shellcheck.sh
60 changes: 0 additions & 60 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func TestLoadConfiguration(t *testing.T) {
}
})
}

}

func TestEnvVarsOverride(t *testing.T) {
Expand Down
7 changes: 3 additions & 4 deletions internal/server/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ type JWTPayload struct {
// Authentication middleware for checking auth rights
func (server *Server) Authentication(next http.Handler, noAuthURLs []string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

// for specific URLs it is ok to not use auth. mechanisms at all
// this is specific to OpenAPI JSON response and for all OPTION HTTP methods
if collections.StringInSlice(r.RequestURI, noAuthURLs) || r.Method == "OPTIONS" {
Expand Down Expand Up @@ -112,7 +111,7 @@ func (server *Server) Authentication(next http.Handler, noAuthURLs []string) htt
// if we took JWT token, it has different structure then x-rh-identity
if server.AuthConfig.Type == "jwt" {
jwtPayload := &JWTPayload{}
err = json.Unmarshal([]byte(decoded), jwtPayload)
err = json.Unmarshal(decoded, jwtPayload)
if err != nil {
// malformed token, returns with HTTP code 403 as usual
log.Error().Err(err).Msg(malformedTokenMessage)
Expand All @@ -127,7 +126,7 @@ func (server *Server) Authentication(next http.Handler, noAuthURLs []string) htt
},
}
} else {
err = json.Unmarshal([]byte(decoded), tk)
err = json.Unmarshal(decoded, tk)

if err != nil {
// malformed token, returns with HTTP code 403 as usual
Expand Down Expand Up @@ -179,7 +178,7 @@ func (server *Server) GetAuthToken(request *http.Request) (*Identity, error) {
return &identity, nil
}

func (server *Server) getAuthTokenHeader(w http.ResponseWriter, r *http.Request) (string, error) {
func (server *Server) getAuthTokenHeader(_ http.ResponseWriter, r *http.Request) (string, error) {
var tokenHeader string
// In case of testing on local machine we don't take x-rh-identity
// header, but instead Authorization with JWT token in it
Expand Down
2 changes: 1 addition & 1 deletion internal/server/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ var configAuth2 = server.AuthConfig{
}

// dummy HTTP request handler
func dummyHandler(w http.ResponseWriter, r *http.Request) {
func dummyHandler(_ http.ResponseWriter, _ *http.Request) {
}

// start new HTTP server, perform request, check response, and stop HTTP server
Expand Down
1 change: 0 additions & 1 deletion internal/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func TestServer(t *testing.T) {
}

for _, tc := range testCases {

t.Run(tc.name, func(t *testing.T) {
testServer := server.New(tc.config, tc.authConfig, mux.NewRouter())
go func() {
Expand Down
6 changes: 3 additions & 3 deletions internal/service/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func (mw mockedWriter) Header() http.Header {
return make(http.Header)
}

func (mw mockedWriter) Write(buf []byte) (int, error) {
return 0, errors.New("Write error!")
func (mw mockedWriter) Write(_ []byte) (int, error) {
return 0, errors.New("write error")
}

func (mw mockedWriter) WriteString(str string) (int, error) {
func (mw mockedWriter) WriteString(_ string) (int, error) {
return 0, nil
}

Expand Down
2 changes: 0 additions & 2 deletions internal/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func TestService(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for _, version := range versions {

store := mockStorage{
mockData: tc.mockData,
}
Expand Down Expand Up @@ -91,5 +90,4 @@ func TestService(t *testing.T) {
}
})
}

}

0 comments on commit 73a14bc

Please sign in to comment.