From 297de4b1ed1784e3bcca32beed571a918bc903b9 Mon Sep 17 00:00:00 2001 From: Eray Date: Thu, 21 Nov 2024 12:25:58 +0300 Subject: [PATCH] chore: build github action --- .github/workflows/build.yml | 39 +++++++++++++++++++++++++++++++++++++ Makefile | 18 ++++++++++------- 2 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..18a0a4a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +name: Build + +on: + push: + branches: [master] + pull_request: + branches: [master] + types: [opened, reopened, synchronize] + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.23' + + - name: Prepare + run: | + make init + make lint + make proto + + - name: Install dependencies + run: go get . + + - name: Build + run: make build \ No newline at end of file diff --git a/Makefile b/Makefile index ebab51d..4e92ca5 100644 --- a/Makefile +++ b/Makefile @@ -6,12 +6,13 @@ PROTOBUF_INSTALL_CMD = brew install protobuf ifeq ($(OS),Windows_NT) PROTOBUF_INSTALL_CMD = choco install protoc +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + PROTOBUF_INSTALL_CMD = sudo apt install -y protobuf-compiler + endif endif -windows: - go mod tidy - go build -o main.exe cmd/main.go - init: $(PROTOBUF_INSTALL_CMD) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.0 @@ -19,15 +20,18 @@ init: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.35.2 go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1 -proto: - protoc --go_out=. --go-grpc_out=. agent/agent.proto api/api.proto cluster/cluster.proto multipass/multipass.proto - +lint: + fieldalignment ./... + golangci-lint run -c .golangci.yml --timeout=5m -v linter: go mod tidy fieldalignment -fix ./... golangci-lint run -c .golangci.yml --timeout=5m -v --fix +proto: + protoc --go_out=. --go-grpc_out=. agent/agent.proto api/api.proto cluster/cluster.proto multipass/multipass.proto + build: go build cmd/main.go