Skip to content

Commit

Permalink
Project improvements (#813)
Browse files Browse the repository at this point in the history
* migrate CI to github actions

* add binaries to gitignore

* update linter configuration

* update go version to 1.17

* create new useful commands and set default one on makefile

* create working drand network on docker compose

* update go version on generate CI workflow

* set go and go grpc protobuf version on Makefile

* update golangci-lint version

* fix issues reported by linter

* add build/test job to be run on PRs too
  • Loading branch information
emmanuelm41 committed Sep 27, 2021
1 parent a2ba475 commit eeaae0a
Show file tree
Hide file tree
Showing 24 changed files with 436 additions and 142 deletions.
93 changes: 0 additions & 93 deletions .circleci/config.yml

This file was deleted.

9 changes: 5 additions & 4 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ jobs:
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
- uses: actions/setup-go@v2
with:
go-version: '^1.17'
- name: Fetch Dependencies
run: go get ./...
-
name: Install Protoc
- name: Install Protoc
uses: arduino/setup-protoc@v1.1.2
with:
version: '3.14.0'
-
name: Install Protoc-gen-go
- name: Install Protoc-gen-go
run: |
go get github.com/golang/protobuf/protoc-gen-go@v1.4.3
go get google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2.3.0
with:
version: v1.29
version: v1.41
args: --timeout 5m
35 changes: 35 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Publish image"

on:
push:
branches:
- master
- main

jobs:
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-go@v2
with:
go-version: '^1.16'
- uses: actions/cache@v2
id: cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build and push Docker image
run: |
docker build --build-arg version=`git describe --tags` --build-arg gitCommit=`git rev-parse HEAD` -t drandorg/go-drand:latest .
echo $DOCKER_PWD | docker login -u $DOCKER_LOGIN --password-stdin
docker push drandorg/go-drand:latest
env:
DOCKER_PWD: ${{ secrets.DOCKER_PWD }}
DOCKER_LOGIN: ${{ secrets.DOCKER_LOGIN }}
35 changes: 35 additions & 0 deletions .github/workflows/publish_tagged.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Publish tagged image"

on:
release:
types:
- created
tags:
- "v[0-9]+(\\.[0-9]+)*"

jobs:
tagged-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-go@v2
with:
go-version: '^1.16'
- uses: actions/cache@v2
id: cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build and push tagged Docker image
run: |
docker build --build-arg version=`git describe --tags` --build-arg gitCommit=`git rev-parse HEAD` -t drandorg/go-drand:`git describe --tags` .
echo $DOCKER_PWD | docker login -u $DOCKER_LOGIN --password-stdin
docker push drandorg/go-drand:`git describe --tags`
env:
DOCKER_PWD: ${{ secrets.DOCKER_PWD }}
DOCKER_LOGIN: ${{ secrets.DOCKER_LOGIN }}
76 changes: 76 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: "Build/Tests"
on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '^1.16'
- uses: actions/cache@v2
id: cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build
run: |
export PATH=$PATH:$(go env GOPATH)/bin
make drand
make drand-client
make drand-relay-http
make drand-relay-gossip
make drand-relay-s3
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-go@v2
with:
go-version: '^1.16'
- uses: actions/cache@v2
id: cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: go get -v -t -d ./...
- name: Unit tests
run: make test-unit
- run: make test-integration

coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-go@v2
with:
go-version: '^1.16'
- uses: actions/cache@v2
id: cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: go get -u github.com/ory/go-acc
- run: go get -v -t -d ./...
- run: go-acc ./...
- run: bash <(curl -s https://codecov.io/bash)
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ gh-md-toc
web/public/
/drand
cover*
.idea
drand
drand-client
drand-relay-gossip
drand-relay-http
drand-relay-s3
docker/data*
4 changes: 1 addition & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ linters:
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- gocyclo
- bodyclose
- deadcode
- depguard
Expand All @@ -36,20 +37,17 @@ linters:
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- nolintlint
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
Expand Down
56 changes: 54 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
.PHONY: test test-unit test-integration demo deploy-local linter install build client drand relay-http relay-gossip relay-s3

drand: build

#################### Lint and fmt process ##################

install_lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.41.1

lint:
golangci-lint --version
golangci-lint run -E gofmt -E gosec -E goconst -E gocritic --timeout 5m

lint-todo:
golangci-lint run -E stylecheck -E gosec -E goconst -E godox -E gocritic

fmt:
@echo "Checking (& upgrading) formatting of files. (if this fail, re-run until success)"
@{ \
files=$$( go fmt ./... ); \
if [ -n "$$files" ]; then \
echo "Files not properly formatted: $$files"; \
exit 1; \
fi; \
}

check-modtidy:
go mod tidy
git diff --exit-code -- go.mod go.sum

clean:
go clean

############################################ Test ############################################

test: test-unit test-integration

test-unit:
Expand All @@ -26,6 +59,13 @@ demo:
cd demo && go build && ./demo -build
#cd demo && sudo ./run.sh

############################################ Build ############################################

build_proto:
go get -u github.com/golang/protobuf/protoc-gen-go@v1.4.3
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc@1.1.0
cd protobuf && sh ./compile_proto.sh

# create the "drand" binary and install it in $GOBIN
install:
go install -ldflags "-X github.com/drand/drand/cmd/drand-cli.version=`git describe --tags` -X github.com/drand/drand/cmd/drand-cli.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` -X github.com/drand/drand/cmd/drand-cli.gitCommit=`git rev-parse HEAD`"
Expand All @@ -34,8 +74,6 @@ install:
build:
go build -o drand -mod=readonly -ldflags "-X github.com/drand/drand/cmd/drand-cli.version=`git describe --tags` -X github.com/drand/drand/cmd/drand-cli.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` -X github.com/drand/drand/cmd/drand-cli.gitCommit=`git rev-parse HEAD`"

drand: build

# create the "drand-client" binary in the current folder
client:
go build -o drand-client -mod=readonly -ldflags "-X main.version=`git describe --tags` -X main.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` -X main.gitCommit=`git rev-parse HEAD`" ./cmd/client
Expand All @@ -55,3 +93,17 @@ drand-relay-gossip: relay-gossip
relay-s3:
go build -o drand-relay-s3 -mod=readonly -ldflags "-X main.version=`git describe --tags` -X main.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` -X main.gitCommit=`git rev-parse HEAD`" ./cmd/relay-s3
drand-relay-s3: relay-s3

build_all: drand drand-client drand-relay-http drand-relay-gossip drand-relay-s3

############################################ Deps ############################################

install_deps_linux:
PROTOC_ZIP=protoc-3.14.0-linux-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
rm -f $PROTOC_ZIP

install_deps_darwin:
brew install protobuf
Loading

0 comments on commit eeaae0a

Please sign in to comment.