Skip to content

Commit

Permalink
Add ci workflow + LICENSE (#20)
Browse files Browse the repository at this point in the history
* tests & refactorings
  • Loading branch information
knikos authored May 17, 2024
1 parent 39323bf commit a22d8ee
Show file tree
Hide file tree
Showing 48 changed files with 1,920 additions and 515 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/check-clean-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -euo pipefail

git update-index --really-refresh >> /dev/null
git diff-index --quiet HEAD
66 changes: 66 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: CI

on:
pull_request:
tags-ignore: ["*"]
branches: [c4t, dev]
push:
branches: [c4t, dev]
workflow_dispatch:

# Cancel ongoing workflow runs if a new one is started
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
go_version: '~1.20.12'

jobs:
unit:
name: Unit Tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Update dependencies
run: git submodule update --init
- uses: actions/setup-go@v3
with:
go-version: ${{ env.go_version }}
- name: Install libolm
run: sudo apt update && sudo apt-get install -y libolm-dev
- name: build_test
shell: bash
run: ./scripts/build_test.sh
lint:
name: Static Analysis
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Update dependencies
run: git submodule update --init
- uses: actions/setup-go@v3
with:
go-version: ${{ env.go_version }}
- name: Install libolm
run: sudo apt update && sudo apt-get install -y libolm-dev
- name: GolangCI-Lint
shell: bash
run: ./scripts/lint.sh
go_mod_tidy:
name: Check state of go.mod and go.sum
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Update dependencies
run: git submodule update --init
- uses: actions/setup-go@v3
with:
go-version: ${{ env.go_version }}
- name: Go Mod Tidy
shell: bash
run: go mod tidy
- name: Check Clean Branch
shell: bash
run: .github/workflows/check-clean-branch.sh

57 changes: 57 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (C) 2024, Chain4Travel AG. All rights reserved.
# See the file LICENSE for licensing terms.

# https://golangci-lint.run/usage/configuration/
run:
skip-dirs:
- camino-matrix-go
timeout: 5m

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
# - cyclop TODO enable
- depguard
- dupl
- errcheck
- errorlint
- exportloopref
- goconst
- gocritic
- gofmt
- gofumpt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- noctx
- prealloc
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace
- revive

linters-settings:
depguard:
rules:
packages:
deny:
- pkg: "io/ioutil"
desc: io/ioutil is deprecated. Use package io or os instead.
- pkg: "github.com/stretchr/testify/assert"
desc: github.com/stretchr/testify/require should be used instead.
- pkg: "github.com/golang/mock/gomock"
desc: go.uber.org/mock/gomock should be used instead.
issues:
# Maximum count of issues with the same text. Set to 0 to disable. Default: 3.
max-same-issues: 0
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (C) 2024, Chain4Travel AG.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions LICENSE.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Copyright (C) 2024, Chain4Travel AG. All rights reserved.
See the file LICENSE for licensing terms.
4 changes: 3 additions & 1 deletion cmd/camino-messenger-bot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ func main() {
defer stop()

app, err := app.NewApp(cfg)
if err != nil {
panic(err)
}
err = app.Run(ctx)
if err != nil {
panic(err)
}

}
12 changes: 9 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type TracingConfig struct {
KeyFile string `mapstructure:"tracing_key_file"`
}
type Config struct {
AppConfig `mapstructure:",squash"` //TODO use nested yaml structure
AppConfig `mapstructure:",squash"` // TODO use nested yaml structure
MatrixConfig `mapstructure:",squash"`
RPCServerConfig `mapstructure:",squash"`
PartnerPluginConfig `mapstructure:",squash"`
Expand Down Expand Up @@ -86,7 +86,7 @@ func ReadConfig() (*Config, error) {
readAppConfig(cfg.AppConfig, fs)
readMatrixConfig(cfg.MatrixConfig, fs)
readRPCServerConfig(cfg.RPCServerConfig, fs)
readPartnerRpcServerConfig(cfg.PartnerPluginConfig, fs)
readPartnerRPCServerConfig(cfg.PartnerPluginConfig, fs)
readMessengerConfig(cfg.ProcessorConfig, fs)
readTvmConfig(cfg.TvmConfig, fs)
readTracingConfig(cfg.TracingConfig, fs)
Expand All @@ -99,7 +99,12 @@ func ReadConfig() (*Config, error) {
return nil, err
}

viper.ReadInConfig() // ignore config-file-reading-errors as we have env vars as fallback configuration
// read configuration file if provided, otherwise rely on env vars
if configFile != "" {
if err := viper.ReadInConfig(); err != nil {
return cfg, err
}
}

if err := viper.Unmarshal(cfg); err != nil {
return nil, err
Expand All @@ -110,6 +115,7 @@ func ReadConfig() (*Config, error) {
func (i *SupportedRequestTypesFlag) String() string {
return "[" + strings.Join(*i, ",") + "]"
}

func (i *SupportedRequestTypesFlag) Contains(requestType string) bool {
return slices.Contains(*i, requestType)
}
Expand Down
5 changes: 1 addition & 4 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ func readAppConfig(cfg AppConfig, fs *flag.FlagSet) {
fs.BoolVar(&cfg.DeveloperMode, DeveloperMode, false, "Sets developer mode")
fs.Var(&cfg.SupportedRequestTypes, SupportedRequestTypesKey, "The list of supported request types")
flag.Parse()

}

func readMatrixConfig(cfg MatrixConfig, fs *flag.FlagSet) {
Expand All @@ -20,15 +19,13 @@ func readRPCServerConfig(cfg RPCServerConfig, fs *flag.FlagSet) {
fs.BoolVar(&cfg.Unencrypted, RPCUnencryptedKey, false, "Whether the RPC server should be unencrypted")
fs.StringVar(&cfg.ServerCertFile, RPCServerCertFileKey, "", "The server certificate file")
fs.StringVar(&cfg.ServerKeyFile, RPCServerKeyFileKey, "", "The server key file")

}

func readPartnerRpcServerConfig(cfg PartnerPluginConfig, fs *flag.FlagSet) {
func readPartnerRPCServerConfig(cfg PartnerPluginConfig, fs *flag.FlagSet) {
fs.StringVar(&cfg.Host, PartnerPluginHostKey, "", "The partner plugin RPC server host")
fs.IntVar(&cfg.Port, PartnerPluginPortKey, 50051, "The partner plugin RPC server port")
fs.BoolVar(&cfg.Unencrypted, PartnerPluginUnencryptedKey, false, "Whether the RPC client should initiate an unencrypted connection with the server")
fs.StringVar(&cfg.CACertFile, PartnerPluginCAFileKey, "", "The partner plugin RPC server CA certificate file")

}

func readMessengerConfig(cfg ProcessorConfig, fs *flag.FlagSet) {
Expand Down
14 changes: 7 additions & 7 deletions examples/rpc/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
typesv1alpha "buf.build/gen/go/chain4travel/camino-messenger-protocol/protocolbuffers/go/cmp/types/v1alpha"
"context"
"encoding/csv"
"flag"
Expand All @@ -12,6 +11,8 @@ import (
"sync"
"time"

typesv1alpha "buf.build/gen/go/chain4travel/camino-messenger-protocol/protocolbuffers/go/cmp/types/v1alpha"

"buf.build/gen/go/chain4travel/camino-messenger-protocol/grpc/go/cmp/services/accommodation/v1alpha/accommodationv1alphagrpc"
accommodationv1alpha "buf.build/gen/go/chain4travel/camino-messenger-protocol/protocolbuffers/go/cmp/services/accommodation/v1alpha"
internalmetadata "github.com/chain4travel/camino-messenger-bot/internal/metadata"
Expand Down Expand Up @@ -74,15 +75,14 @@ func createClientAndRunRequest(i int, ppConfig config.PartnerPluginConfig, sLogg
request := &accommodationv1alpha.AccommodationSearchRequest{
Header: nil,
SearchParametersGeneric: &typesv1alpha.SearchParameters{
Currency: typesv1alpha.Currency_CURRENCY_EUR,
Language: typesv1alpha.Language_LANGUAGE_UG,
Market: 1,
MaxOptions: 2,
},
Queries: []*accommodationv1alpha.AccommodationSearchQuery{
{
SearchParametersAccommodation: &accommodationv1alpha.AccommodationSearchParameters{
RatePlan: []*typesv1alpha.RatePlan{{RatePlan: "economy"}},
SupplierCodes: []*typesv1alpha.SupplierProductCode{{SupplierCode: "supplier1"}},
},
},
},
Expand Down Expand Up @@ -139,12 +139,11 @@ func addToDataset(counter int64, totalTime int64, resp *accommodationv1alpha.Acc

if entry.Key == "request-gateway-request" {
lastValue = entry.Value
continue //skip
continue // skip
}
if entry.Key == "processor-request" {

//lastValue = entry.Value
continue //skip
// lastValue = entry.Value
continue // skip
}
fmt.Printf("%d|%s|%s|%d|%.2f\n", entry.Value, entry.Key, resp.Metadata.SearchId.GetValue(), entry.Value-lastValue, float32(entry.Value-lastValue)/float32(totalTime))

Expand All @@ -156,6 +155,7 @@ func addToDataset(counter int64, totalTime int64, resp *accommodationv1alpha.Acc
loadTestData[counter] = data
mu.Unlock()
}

func persistToCSV(dataset [][]string) {
// Open a new CSV file
file, err := os.Create("load_test_data.csv")
Expand Down
19 changes: 12 additions & 7 deletions examples/rpc/partner-plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type partnerPlugin struct {
transportv1alphagrpc.TransportSearchServiceServer
}

func (p *partnerPlugin) Mint(ctx context.Context, request *bookv1alpha.MintRequest) (*bookv1alpha.MintResponse, error) {
func (p *partnerPlugin) Mint(ctx context.Context, _ *bookv1alpha.MintRequest) (*bookv1alpha.MintResponse, error) {
md := metadata.Metadata{}
err := md.ExtractMetadata(ctx)
if err != nil {
Expand All @@ -64,7 +64,7 @@ func (p *partnerPlugin) Mint(ctx context.Context, request *bookv1alpha.MintReque
return &response, nil
}

func (p *partnerPlugin) Validation(ctx context.Context, request *bookv1alpha.ValidationRequest) (*bookv1alpha.ValidationResponse, error) {
func (p *partnerPlugin) Validation(ctx context.Context, _ *bookv1alpha.ValidationRequest) (*bookv1alpha.ValidationResponse, error) {
md := metadata.Metadata{}
err := md.ExtractMetadata(ctx)
if err != nil {
Expand All @@ -82,7 +82,7 @@ func (p *partnerPlugin) Validation(ctx context.Context, request *bookv1alpha.Val
return &response, nil
}

func (p *partnerPlugin) ActivitySearch(ctx context.Context, request *activityv1alpha.ActivitySearchRequest) (*activityv1alpha.ActivitySearchResponse, error) {
func (p *partnerPlugin) ActivitySearch(ctx context.Context, _ *activityv1alpha.ActivitySearchRequest) (*activityv1alpha.ActivitySearchResponse, error) {
md := metadata.Metadata{}
err := md.ExtractMetadata(ctx)
if err != nil {
Expand All @@ -98,7 +98,8 @@ func (p *partnerPlugin) ActivitySearch(ctx context.Context, request *activityv1a
grpc.SendHeader(ctx, md.ToGrpcMD())
return &response, nil
}
func (p *partnerPlugin) AccommodationProductInfo(ctx context.Context, request *accommodationv1alpha.AccommodationProductInfoRequest) (*accommodationv1alpha.AccommodationProductInfoResponse, error) {

func (p *partnerPlugin) AccommodationProductInfo(ctx context.Context, _ *accommodationv1alpha.AccommodationProductInfoRequest) (*accommodationv1alpha.AccommodationProductInfoResponse, error) {
md := metadata.Metadata{}
err := md.ExtractMetadata(ctx)
if err != nil {
Expand All @@ -113,7 +114,8 @@ func (p *partnerPlugin) AccommodationProductInfo(ctx context.Context, request *a
grpc.SendHeader(ctx, md.ToGrpcMD())
return &response, nil
}
func (p *partnerPlugin) AccommodationProductList(ctx context.Context, request *accommodationv1alpha.AccommodationProductListRequest) (*accommodationv1alpha.AccommodationProductListResponse, error) {

func (p *partnerPlugin) AccommodationProductList(ctx context.Context, _ *accommodationv1alpha.AccommodationProductListRequest) (*accommodationv1alpha.AccommodationProductListResponse, error) {
md := metadata.Metadata{}
err := md.ExtractMetadata(ctx)
if err != nil {
Expand All @@ -128,7 +130,8 @@ func (p *partnerPlugin) AccommodationProductList(ctx context.Context, request *a
grpc.SendHeader(ctx, md.ToGrpcMD())
return &response, nil
}
func (p *partnerPlugin) AccommodationSearch(ctx context.Context, request *accommodationv1alpha.AccommodationSearchRequest) (*accommodationv1alpha.AccommodationSearchResponse, error) {

func (p *partnerPlugin) AccommodationSearch(ctx context.Context, _ *accommodationv1alpha.AccommodationSearchRequest) (*accommodationv1alpha.AccommodationSearchResponse, error) {
md := metadata.Metadata{}
err := md.ExtractMetadata(ctx)
if err != nil {
Expand Down Expand Up @@ -163,6 +166,7 @@ func (p *partnerPlugin) GetNetworkFee(ctx context.Context, request *networkv1alp
grpc.SendHeader(ctx, md.ToGrpcMD())
return &response, nil
}

func (p *partnerPlugin) GetPartnerConfiguration(ctx context.Context, request *partnerv1alpha.GetPartnerConfigurationRequest) (*partnerv1alpha.GetPartnerConfigurationResponse, error) {
md := metadata.Metadata{}
err := md.ExtractMetadata(ctx)
Expand Down Expand Up @@ -194,7 +198,8 @@ func (p *partnerPlugin) Ping(ctx context.Context, request *pingv1alpha.PingReque
PingMessage: fmt.Sprintf("Ping response to [%s] with request ID: %s", request.PingMessage, md.RequestID),
}, nil
}
func (p *partnerPlugin) TransportSearch(ctx context.Context, request *transportv1alpha.TransportSearchRequest) (*transportv1alpha.TransportSearchResponse, error) {

func (p *partnerPlugin) TransportSearch(ctx context.Context, _ *transportv1alpha.TransportSearchRequest) (*transportv1alpha.TransportSearchResponse, error) {
md := metadata.Metadata{}
err := md.ExtractMetadata(ctx)
if err != nil {
Expand Down
Loading

0 comments on commit a22d8ee

Please sign in to comment.