Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add golangci-lint and fix lint issues; add ci for macOS and windows #36

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 125 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: CI
on: [push, pull_request]

jobs:
build:
golang-lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
Expand All @@ -22,34 +22,74 @@ jobs:
gofmt-path: './'
gofmt-flags: '-l -d'

- name: Go Mod
run: go mod tidy

- name: Clone Tongsuo
uses: actions/checkout@v3
with:
repository: Tongsuo-Project/Tongsuo
path: tongsuo
path: Tongsuo
ref: 8.3-stable

- name: Build Tongsuo
run: |
cd tongsuo
./config --prefix=/opt/tongsuo --libdir=/opt/tongsuo/lib enable-ntls
cd Tongsuo
./config --prefix=${RUNNER_TEMP}/tongsuo --libdir=${RUNNER_TEMP}/tongsuo/lib enable-ntls
make -j4
make install

- name: Go Mod
run: go mod tidy
- name: Golang lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin v1.61.0
LD_LIBRARY_PATH=${RUNNER_TEMP}/tongsuo/lib CGO_CFLAGS="-Wall -I${RUNNER_TEMP}/tongsuo/include -Wno-deprecated-declarations" CGO_LDFLAGS="-L${RUNNER_TEMP}/tongsuo/lib" golangci-lint run ./...

- name: Go vet Check
run: LD_LIBRARY_PATH=/opt/tongsuo/lib CGO_CFLAGS="-Wall -I/opt/tongsuo/include -Wno-deprecated-declarations" CGO_LDFLAGS="-L/opt/tongsuo/lib" go vet ./...

- name: Build
run: CGO_CFLAGS="-Wall -I/opt/tongsuo/include -Wno-deprecated-declarations" CGO_LDFLAGS="-L/opt/tongsuo/lib" go build
build-and-test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3

- name: Test
run: LD_LIBRARY_PATH=/opt/tongsuo/lib CGO_CFLAGS="-Wall -I/opt/tongsuo/include -Wno-deprecated-declarations" CGO_LDFLAGS="-L/opt/tongsuo/lib" go test ./...
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

build_static:
runs-on: ubuntu-22.04
- name: Clone Tongsuo
uses: actions/checkout@v3
with:
repository: Tongsuo-Project/Tongsuo
path: Tongsuo
ref: 8.3-stable

- name: Build Tongsuo
run: |
cd Tongsuo
./config --prefix=${RUNNER_TEMP}/tongsuo --libdir=${RUNNER_TEMP}/tongsuo/lib enable-ntls
make -j4
make install

- name: Build
run: CGO_CFLAGS="-Wall -I${RUNNER_TEMP}/tongsuo/include -Wno-deprecated-declarations" CGO_LDFLAGS="-L${RUNNER_TEMP}/tongsuo/lib" go build

- name: Test on Ubuntu
run: LD_LIBRARY_PATH=${RUNNER_TEMP}/tongsuo/lib CGO_CFLAGS="-Wall -I${RUNNER_TEMP}/tongsuo/include -Wno-deprecated-declarations" CGO_LDFLAGS="-L${RUNNER_TEMP}/tongsuo/lib" go test ./...
if: matrix.os == 'ubuntu-latest'

- name: Test on macOS
run: DYLD_LIBRARY_PATH=${RUNNER_TEMP}/tongsuo/lib CGO_CFLAGS="-Wall -I${RUNNER_TEMP}/tongsuo/include -Wno-deprecated-declarations" CGO_LDFLAGS="-L${RUNNER_TEMP}/tongsuo/lib" go test ./...
if: matrix.os == 'macos-latest'

build-static:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3

Expand All @@ -68,9 +108,77 @@ jobs:
- name: Build Tongsuo Static
run: |
cd tongsuo
./config --prefix=/opt/tongsuo --libdir=/opt/tongsuo/lib enable-ntls no-shared
./config --prefix=${RUNNER_TEMP}/tongsuo --libdir=${RUNNER_TEMP}/tongsuo/lib enable-ntls no-shared
make -j4
make install

- name: Test
run: LD_LIBRARY_PATH=/opt/tongsuo/lib CGO_CFLAGS="-Wall -I/opt/tongsuo/include -Wno-deprecated-declarations" CGO_LDFLAGS="-L/opt/tongsuo/lib" go test ./...
- name: Build
run: CGO_CFLAGS="-Wall -I${RUNNER_TEMP}/tongsuo/include -Wno-deprecated-declarations" CGO_LDFLAGS="-L${RUNNER_TEMP}/tongsuo/lib" go build

- name: Test on Ubuntu
run: LD_LIBRARY_PATH=${RUNNER_TEMP}/tongsuo/lib CGO_CFLAGS="-Wall -I${RUNNER_TEMP}/tongsuo/include -Wno-deprecated-declarations" CGO_LDFLAGS="-L${RUNNER_TEMP}/tongsuo/lib" go test ./...
if: matrix.os == 'ubuntu-latest'

- name: Test on macOS
run: DYLD_LIBRARY_PATH=${RUNNER_TEMP}/tongsuo/lib CGO_CFLAGS="-Wall -I${RUNNER_TEMP}/tongsuo/include -Wno-deprecated-declarations" CGO_LDFLAGS="-L${RUNNER_TEMP}/tongsuo/lib" go test ./...
if: matrix.os == 'macos-latest'

build-on-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Clone Tongsuo
uses: actions/checkout@v3
with:
repository: Tongsuo-Project/Tongsuo
path: Tongsuo
ref: 8.3-stable
- uses: ilammy/msvc-dev-cmd@v1
- uses: ilammy/setup-nasm@v1
- uses: shogo82148/actions-setup-perl@v1
- name: Build Tongsuo
shell: cmd
run: |
mkdir _build
cd _build
perl ..\Configure VC-WIN64A no-makedepend --prefix=%RUNNER_TEMP%\tongsuo enable-ntls
nmake /S
nmake install
working-directory: Tongsuo

- name: Build
shell: cmd
run: |
set CGO_CFLAGS=-Wall -I%RUNNER_TEMP%\tongsuo\include -Wno-deprecated-declarations
set CGO_LDFLAGS=-L%RUNNER_TEMP%\tongsuo\lib"
go build

- name: Set PATH for go test runtime library search
shell: perl {0}
run: |
use Actions::Core;
add_path("$ENV{RUNNER_TEMP}\\tongsuo\\bin");
add_path("$ENV{RUNNER_TEMP}\\tongsuo\\lib");

- name: Test on Windows
shell: cmd
run: |
copy /y %RUNNER_TEMP%\tongsuo\bin\*.dll "C:\Program Files\MySQL\MySQL Server 8.0\bin"
copy /y %RUNNER_TEMP%\tongsuo\bin\*.dll "C:\Program Files\OpenSSL\bin"
copy /y %RUNNER_TEMP%\tongsuo\bin\*.dll C:\Windows\system32
copy /y %RUNNER_TEMP%\tongsuo\bin\*.dll C:\Strawberry\c\bin
copy /y %RUNNER_TEMP%\tongsuo\bin\*.dll "C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code"
copy /y %RUNNER_TEMP%\tongsuo\bin\*.dll "C:\Program Files\Git\mingw64\bin"
copy /y %RUNNER_TEMP%\tongsuo\bin\*.dll c:\tools\php
copy /y %RUNNER_TEMP%\tongsuo\bin\*.dll "C:\Program Files\Amazon\AWSCLIV2"
set CGO_CFLAGS=-Wall -I%RUNNER_TEMP%\tongsuo\include -Wno-deprecated-declarations
set CGO_LDFLAGS=-L%RUNNER_TEMP%\tongsuo\lib
go env
echo %PATH%
go test ./...
89 changes: 89 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
linters:
enable-all: true
disable:
- ireturn
- gochecknoinits
- exhaustruct
- nlreturn

linters-settings:
cyclop:
max-complexity: 20
interfacebloat:
max: 11
lll:
line-length: 120
funlen:
lines: 120
statements: 80
ignore-comments: true
depguard:
rules:
main:
allow:
- $gostd
- github.com/tongsuo-project/tongsuo-go-sdk
- github.com/tongsuo-project/tongsuo-go-sdk/crypto
- github.com/tongsuo-project/tongsuo-go-sdk/utils

issues:
exclude:
- "variable name '(i|e|n|wg|md|ok|ca|bn|iv|ip|rv|rc|fn)' is too short for the scope of its usage"
- "parameter name '(e|r|s|ok|in|ip|iv|fn|rv)' is too short for the scope of its usage"
exclude-rules:
- path: crypto/sha1/sha1_test.go
linters:
- gosec
- path: crypto/md5/md5_test.go
linters:
- gosec
- path: conn.go
text: "Error return value of `c.flushOutputBuffer` is not checked"
- path: utils/errors.go
text: "do not define dynamic errors, use wrapped static errors instead:"
- path: ntls_test.go
text: "Error return value of `server.(Run|RunForALPN)` is not checked"
- path: ssl_test.go
text: "G402: TLS InsecureSkipVerify set true."
- path: crypto/key_test.go
text: "G101: Potential hardcoded credentials: (RSA|SSH \\(EC\\)) private key"
- path: ssl_test.go
text: "G101: Potential hardcoded credentials: (RSA|SSH \\(EC\\)) private key"
- path: ssl_test.go
text: "G402: TLS MinVersion too low."
- path: ctx.go
text: "Consider pre-allocating `protoList`"
- path: crypto/ciphers_gcm.go
text: "Magic number: (128|192|256), in <case> detected"
- path: .*\.go
text: "dupSubExpr: suspicious identical LHS and RHS for `==` operator"
- path: crypto/sm2/sm2.go
text: "return with no blank line before"
- path: crypto/bio.go
text: "return with no blank line before"
- path: crypto/bio.go
text: "(readBioMapping|writeBioMapping) is a global variable"
- path: crypto/key_test.go
text: "Function '(TestMarshal|TestMarshalEC)' has too many statements"
- path: ctx.go
text: "sslCtxIdx is a global variable"
- path: ssl.go
text: "sslIdx is a global variable"
- path: .*_test\.go
text: "cognitive complexity (.*) of func `(TestMarshalEC|TestMarshal|TestSessionReuse|TestNTLS)` is high"
- path: .*_test\.go
text: "cyclomatic complexity (.*) of func `(TestMarshalEC|TestMarshal)` is high"
- path: .*_test\.go
text: "calculated cyclomatic complexity for function (TestMarshal|TestMarshalEC) is (.*), max is (.*)"
- path: .*_test\.go
text: "error returned from external package is unwrapped"
- path: crypto/key.go
text: "`if curve == SM2Curve` has complex nested blocks \\(complexity: 6\\)"
- path: crypto/init.go
text: "do not define dynamic errors, use wrapped static errors instead:"
- path: http.go
text: "http.go:(.*): Line contains TODO/BUG/FIXME: \"TODO: http client integration\""
- path: ctx.go
text: "errorf: should replace errors.New"
- path: ctx.go
text: "do not define dynamic errors, use wrapped static errors instead:"
6 changes: 3 additions & 3 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

package tongsuogo

// #cgo linux LDFLAGS: -lssl -lcrypto
// #cgo darwin LDFLAGS: -lssl -lcrypto
// #cgo linux LDFLAGS: -lssl
// #cgo darwin LDFLAGS: -lssl
// #cgo windows CFLAGS: -DWIN32_LEAN_AND_MEAN
// #cgo windows pkg-config: libssl libcrypto
// #cgo windows LDFLAGS: -lssl
import "C"
6 changes: 3 additions & 3 deletions build_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

package tongsuogo

// #cgo linux LDFLAGS: -extldflags -static -lssl -lcrypto
// #cgo darwin LDFLAGS: -extldflags -static -lssl -lcrypto
// #cgo linux LDFLAGS: -extldflags -static -lssl
// #cgo darwin LDFLAGS: -extldflags -static -lssl
// #cgo windows CFLAGS: -DWIN32_LEAN_AND_MEAN
// #cgo windows pkg-config: libssl libcrypto
// #cgo windows LDFLAGS: -extldflags -static -lssl
import "C"
Loading
Loading