Skip to content

Commit

Permalink
add workflows | Makefile | update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
whonion committed May 16, 2023
1 parent 4101920 commit 942d55e
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 9 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build
on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Install dependencies
run: go get .
- name: Build
run: go build main.go
- name: Test with the Go CLI
run: go test main.go
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Lint

on: [ push, pull_request ]

jobs:
lint:
strategy:
matrix:
platform: [ "ubuntu-latest" ]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Lint
run: make lint-go
17 changes: 17 additions & 0 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Makefile
on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Install dependencies
run: go get .
- name: Build Go Project
run: make build
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test

on: [ push, pull_request ]

jobs:
test:
strategy:
matrix:
go-version: [ "1.17", "1.18", "1.19","1.20" ]
platform: [ "ubuntu-latest" ]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: make test GOFLAGS="-v" GO_VERSION=${{ matrix.go-version }}
98 changes: 98 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
GOCMD=go
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
BINARY_NAME=refueler
VERSION?=1.0.0
SERVICE_PORT?=3000
DOCKER_REGISTRY?= #if set it should finished by /
EXPORT_RESULT?=false # for CI please set EXPORT_RESULT to true

GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)

.PHONY: all test build vendor

all: help

## Build:
build: ## Build your project and put the output binary in out/bin/
mkdir -p bin
$(GOCMD) build main.go

clean: ## Remove build related file
rm -fr ./bin
rm -fr ./out
rm -f ./junit-report.xml checkstyle-report.xml ./coverage.xml ./profile.cov yamllint-checkstyle.xml

vendor: ## Copy of all packages needed to support builds and tests in the vendor directory
$(GOCMD) mod vendor

watch: ## Run the code with cosmtrek/air to have automatic reload on changes
$(eval PACKAGE_NAME=$(shell head -n 1 go.mod | cut -d ' ' -f2))
docker run -it --rm -w /go/src/$(PACKAGE_NAME) -v $(shell pwd):/go/src/$(PACKAGE_NAME) -p $(SERVICE_PORT):$(SERVICE_PORT) cosmtrek/air

## Test:
test: ## Run the tests of the project
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/jstemmer/go-junit-report
$(eval OUTPUT_OPTIONS = | tee /dev/tty | go-junit-report -set-exit-code > junit-report.xml)
endif
$(GOTEST) -v -race ./... $(OUTPUT_OPTIONS)

coverage: ## Run the tests of the project and export the coverage
$(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./...
$(GOCMD) tool cover -func profile.cov
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/AlekSi/gocov-xml
GO111MODULE=off go get -u github.com/axw/gocov/gocov
gocov convert profile.cov | gocov-xml > coverage.xml
endif

## Lint:
lint: lint-go lint-dockerfile lint-yaml ## Run all available linters

lint-dockerfile: ## Lint your Dockerfile
# If dockerfile is present we lint it.
ifeq ($(shell test -e ./Dockerfile && echo -n yes),yes)
$(eval CONFIG_OPTION = $(shell [ -e $(shell pwd)/.hadolint.yaml ] && echo "-v $(shell pwd)/.hadolint.yaml:/root/.config/hadolint.yaml" || echo "" ))
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--format checkstyle" || echo "" ))
$(eval OUTPUT_FILE = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "| tee /dev/tty > checkstyle-report.xml" || echo "" ))
docker run --rm -i $(CONFIG_OPTION) hadolint/hadolint hadolint $(OUTPUT_OPTIONS) - < ./Dockerfile $(OUTPUT_FILE)
endif

lint-go: ## Use golintci-lint on your project
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--out-format checkstyle ./... | tee /dev/tty > checkstyle-report.xml" || echo "" ))
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --deadline=65s $(OUTPUT_OPTIONS)

lint-yaml: ## Use yamllint on the yaml file of your projects
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/thomaspoignant/yamllint-checkstyle
$(eval OUTPUT_OPTIONS = | tee /dev/tty | yamllint-checkstyle > yamllint-checkstyle.xml)
endif
docker run --rm -it -v $(shell pwd):/data cytopia/yamllint -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)

## Docker:
docker-build: ## Use the dockerfile to build the container
docker build --rm --tag $(BINARY_NAME) .

docker-release: ## Release the container with tag latest and version
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)$(BINARY_NAME):latest
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)$(BINARY_NAME):$(VERSION)
# Push the docker images
docker push $(DOCKER_REGISTRY)$(BINARY_NAME):latest
docker push $(DOCKER_REGISTRY)$(BINARY_NAME):$(VERSION)

## Help:
help: ## Show this help.
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@

[![build-status]![Go version][go-badge]][go-url] [![HitCount](https://hits.dwyl.com/whonion//whonion/SmartContractBatchDeployer.svg)](https://hits.dwyl.com/whonion/go-client-faucet-request)

[![Go version][go-badge]][go-url] [![Test](https://github.com/whonion/SmartContractBatchDeployer/actions/workflows/test.yml/badge.svg)](https://github.com/whonion/SmartContractBatchDeployer/actions/workflows/test.yml) [![Build](https://github.com/whonion/SmartContractBatchDeployer/actions/workflows/build.yml/badge.svg)](https://github.com/whonion/SmartContractBatchDeployer/actions/workflows/build.yml)[![Makefile](https://github.com/whonion/SmartContractBatchDeployer/actions/workflows/makefile.yml/badge.svg)](https://github.com/whonion/SmartContractBatchDeployer/actions/workflows/makefile.yml) [![Lint](https://github.com/whonion/SmartContractBatchDeployer/actions/workflows/lint.yml/badge.svg)](https://github.com/whonion/SmartContractBatchDeployer/actions/workflows/lint.yml) [![HitCount](https://hits.dwyl.com/whonion//SmartContractBatchDeployer.svg)](https://hits.dwyl.com/whonion/SmartContractBatchDeployer)</br>

# Example of batch deployment smart contracts to EVM using Go Lang</br>

Implementation with go-ethereum

## Package description:
## Package description

- main.go - main executable or build file
- contracts/ - folder for compiled and deployable contract files in *.sol format
- bin/ - a folder for storing binary files of compiled contracts and ABIs
- .env - file to store variables such as `RPC-node` or `private_key`

## Description of required files:
## Description of required files

- Installed NodeJS and `solcjs`

- Installed `Go Lang`



## Setup Dependencies :
## Setup Dependencies

```sh
ver="1.20" && \
Expand All @@ -38,14 +34,17 @@ sudo apt-get install -y npm \
npm install -g npm \
npm install solc \
```

## Launch with `tmux`

Add to `.env` your variables: `PRIVATE_KEY` (without **0x**),`RPC_PROVIDER` and `CHAIN_ID`

```sh
CHAIN_ID = 5
PRIVATE_KEY = '0x.......................................................'
RPC_PROVIDER='https://eth-goerli.g.alchemy.com/v2/{YOUR_API_KEY}'
```

Add correct files *.sol to the `contacts` folder for deployment on the required chain

```sh
Expand All @@ -54,6 +53,6 @@ git clone https://github.com/whonion/SmartContractBatchDeployer.git \
cd SmartContractBatchDeployer \
go run main.go
```

[go-badge]: https://img.shields.io/badge/go-1.20-blue.svg
[go-url]: https://go.dev
[build-status]: https://github.com/tendermint/tendermint/actions/workflows/tests.yml/badge.svg?branch=main

0 comments on commit 942d55e

Please sign in to comment.