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

RSDK-9305 Add CI #10

Merged
merged 13 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
16 changes: 16 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: viamrobotics/build-action@v1
with:
version: ${{ github.ref_name }}
ref: ${{ github.sha }}
key-id: ${{ secrets.viam_key_id }}
key-value: ${{ secrets.viam_key_value }}
35 changes: 35 additions & 0 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: run linter and unit tests on each commit

on:
push:
branches:
- main
paths:
- '**/**.go'
pull_request:
paths:
- '**/**.go'
- 'Makefile'
- '.github/workflows/lint-test.yml'

jobs:
quality-checks:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be go 1.23.


- name: Install dependencies
run: |
sudo apt-get update

- name: Run unit tests
run: make test

- name: Run linter
run: make lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mymod
bin
39 changes: 34 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@

BUILD_DIR = ./sx1302
CGO_BUILD_LDFLAGS := -L$(shell pwd)/$(BUILD_DIR)/libloragw -L$(shell pwd)/$(BUILD_DIR)libloragw/lib -L$(shell pwd)/$(BUILD_DIR)/libtools
BIN_OUTPUT_PATH = bin
TOOL_BIN = bin/gotools/$(shell uname -s)-$(shell uname -m)
UNAME_S ?= $(shell uname -s)

.PHONY: all
all:
CGO_LDFLAGS="$$CGO_LDFLAGS $(CGO_BUILD_LDFLAGS)" go build $(GO_BUILD_LDFLAGS) -o mymod main.go
.PHONY: build
build:
rm -f $(BIN_OUTPUT_PATH)/lorawan
CGO_LDFLAGS="$$CGO_LDFLAGS $(CGO_BUILD_LDFLAGS)" go build $(GO_BUILD_LDFLAGS) -o $(BIN_OUTPUT_PATH)/lorawan main.go

module.tar.gz: build
rm -f $(BIN_OUTPUT_PATH)/module.tar.gz
tar czf $(BIN_OUTPUT_PATH)/module.tar.gz $(BIN_OUTPUT_PATH)/lorawan

test: sx1302 build
sudo apt install libnlopt-dev
CGO_LDFLAGS="$$CGO_LDFLAGS $(CGO_BUILD_LDFLAGS)" go test -race -v ./...


sx1302: submodule
cd sx1302/libtools && make
cd sx1302/libloragw && make

submodule:
git submodule init
git submodule update

tool-install:
GOBIN=`pwd`/$(TOOL_BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint

gofmt:
gofmt -w -s .

lint: gofmt tool-install
go mod tidy
$(TOOL_BIN)/golangci-lint run -v --fix --config=./etc/.golangci.yaml

test:
CGO_LDFLAGS="$$CGO_LDFLAGS $(CGO_BUILD_LDFLAGS)" go test -v gateway/gateway
106 changes: 106 additions & 0 deletions etc/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
service:
golangci-lint-version: 1.51.x
run:
deadline: 900s
modules-download-mode: readonly
linters:
enable-all: true
disable:
- asasalint
- mnd
- containedctx
- contextcheck
- cyclop
- deadcode
- depguard
- exhaustivestruct
- exhaustruct
- forcetypeassert
- funlen
- gocognit
- godox
- goerr113
- gochecknoglobals
- gochecknoinits
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- importas
- interfacebloat
- ireturn
- maintidx
- makezero
- musttag
- nakedret
- nestif
- nlreturn
- nonamedreturns
- nosprintfhostport
- paralleltest
- prealloc
- tagliatelle
- testpackage
- thelper # false positives
- varnamelen
- wrapcheck
- wsl
linters-settings:
errcheck:
check-blank: true
gci:
sections:
- standard
- default
gofumpt:
lang-version: "1.21"
extra-rules: true
govet:
enable-all: true
disable:
- fieldalignment
- shadow
- composites
revive:
# Unfortunately configuring a single rules disables all other rules, even
# if we set `enable-all: true`
#
# To get around this, we include default rules:
# https://github.com/mgechev/revive/blob/master/defaults.toml
rules:
- name: blank-imports
- name: context-keys-type
- name: dot-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unreachable-code
- name: var-declaration
- name: var-naming
lll:
line-length: 140
issues:
exclude-rules:
- path: _test\.go$
linters:
- dupword
- errcheck
- exhaustive
- goconst
- gosec
exclude-use-default: false
max-per-linter: 0
max-same-issues: 0
Loading
Loading