Skip to content
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
117 changes: 117 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: CI

on:
push:
pull_request:

jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: [amd64, arm64, arm]
exclude:
- goos: darwin
goarch: arm
- goos: windows
goarch: arm
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'

- name: Install Protoc
uses: arduino/setup-protoc@v3

- name: Install Protoc Gen Go
run: |
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

- name: Generate Protos
run: make proto

- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
VERSION=${{ github.sha }}
COMMIT=${{ github.sha }}
BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS="-X 'github.com/MINIOpenSource/CIMS-backend/internal/pkg/version.Version=$VERSION' -X 'github.com/MINIOpenSource/CIMS-backend/internal/pkg/version.CommitHash=$COMMIT' -X 'github.com/MINIOpenSource/CIMS-backend/internal/pkg/version.BuildTime=$BUILD_TIME' -s -w"

OUTPUT_NAME=cims-backend-${{ matrix.goos }}-${{ matrix.goarch }}
if [ "${{ matrix.goos }}" = "windows" ]; then
OUTPUT_NAME+='.exe'
fi
go build -ldflags "$LDFLAGS" -o $OUTPUT_NAME ./cmd/cims/main.go

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: cims-backend-${{ matrix.goos }}-${{ matrix.goarch }}
path: cims-backend-*
retention-days: 1

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'

- name: Install Protoc
uses: arduino/setup-protoc@v3

- name: Install Protoc Gen Go
run: |
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

- name: Generate Protos
run: make proto

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=5m

test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'

- name: Install Protoc
uses: arduino/setup-protoc@v3

- name: Install Protoc Gen Go
run: |
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

- name: Generate Protos
run: make proto

- name: Run tests
run: go test -v ./...
15 changes: 10 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: [amd64, arm64, 386, arm]
goarch: [amd64, arm64, arm]
exclude:
- goos: darwin
goarch: 386
- goos: darwin
goarch: arm
- goos: windows
goarch: arm
steps:
- name: Checkout code
Expand All @@ -25,7 +25,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.24'

- name: Install Protoc
uses: arduino/setup-protoc@v3
Expand All @@ -44,11 +44,16 @@ jobs:
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
VERSION=${{ github.ref_name }}
COMMIT=${{ github.sha }}
BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS="-X 'github.com/MINIOpenSource/CIMS-backend/internal/pkg/version.Version=$VERSION' -X 'github.com/MINIOpenSource/CIMS-backend/internal/pkg/version.CommitHash=$COMMIT' -X 'github.com/MINIOpenSource/CIMS-backend/internal/pkg/version.BuildTime=$BUILD_TIME' -s -w"

OUTPUT_NAME=cims-backend-${{ matrix.goos }}-${{ matrix.goarch }}
if [ "${{ matrix.goos }}" = "windows" ]; then
OUTPUT_NAME+='.exe'
fi
go build -o $OUTPUT_NAME ./cmd/cims/main.go
go build -ldflags "$LDFLAGS" -o $OUTPUT_NAME ./cmd/cims/main.go

- name: Upload Artifact
uses: actions/upload-artifact@v4
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,13 @@ proto:
clean:
rm -rf internal/proto

VERSION := $(shell git describe --tags --always --dirty || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD || echo "none")
BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")

LDFLAGS := -X 'github.com/MINIOpenSource/CIMS-backend/internal/pkg/version.Version=$(VERSION)' \
-X 'github.com/MINIOpenSource/CIMS-backend/internal/pkg/version.CommitHash=$(COMMIT)' \
-X 'github.com/MINIOpenSource/CIMS-backend/internal/pkg/version.BuildTime=$(BUILD_TIME)'

build:
go build -o cims_server ./cmd/cims/main.go
go build -ldflags "$(LDFLAGS)" -o cims_server ./cmd/cims/main.go
13 changes: 12 additions & 1 deletion cmd/cims/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/MINIOpenSource/CIMS-backend/internal/api/grpc"
v1 "github.com/MINIOpenSource/CIMS-backend/internal/api/http/v1"
"github.com/MINIOpenSource/CIMS-backend/internal/data"
"github.com/MINIOpenSource/CIMS-backend/internal/pkg/version"
"github.com/MINIOpenSource/CIMS-backend/internal/proto/Protobuf/Service"
"github.com/gin-gonic/gin"
"github.com/kardianos/service"
Expand All @@ -18,7 +19,6 @@ import (
)

var (
cfgFile string
dbPath string
port int
grpcPort int
Expand Down Expand Up @@ -168,9 +168,20 @@ func main() {
},
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of CIMS",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("CIMS-backend Version: %s\n", version.Version)
fmt.Printf("Git Commit: %s\n", version.CommitHash)
fmt.Printf("Build Time: %s\n", version.BuildTime)
},
}

rootCmd.AddCommand(startCmd)
rootCmd.AddCommand(serviceCmd)
rootCmd.AddCommand(initCmd)
rootCmd.AddCommand(versionCmd)

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/api/grpc/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *ClientCommandDeliverServer) ListenCommand(stream Service.ClientCommandD
}

if req.Type == Enum.CommandTypes_Ping {
s.clientService.UpdateHeartbeat(clientID, clientIP)
_ = s.clientService.UpdateHeartbeat(clientID, clientIP)
pong := &Server.ClientCommandDeliverScRsp{
RetCode: Enum.Retcode_Success,
Type: Enum.CommandTypes_Pong,
Expand Down
10 changes: 10 additions & 0 deletions internal/pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package version

var (
// Version is the current version of the application.
Version = "dev"
// CommitHash is the git commit hash of the build.
CommitHash = "none"
// BuildTime is the time when the application was built.
BuildTime = "unknown"
)
4 changes: 1 addition & 3 deletions internal/service/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ func (s *CommandService) RegisterClientChannel(clientID string, ch chan *Server.
func (s *CommandService) UnregisterClientChannel(clientID string) {
s.mu.Lock()
defer s.mu.Unlock()
if _, ok := s.clientChans[clientID]; ok {
delete(s.clientChans, clientID)
}
delete(s.clientChans, clientID)
}

// SendCommand sends a command to a specific client
Expand Down