Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
canercidam committed Jan 8, 2025
0 parents commit 2d052c1
Show file tree
Hide file tree
Showing 18 changed files with 2,162 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .github/actions/go/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Go
description: Validate and test Go code
inputs:
COVERAGE_THRESHOLD:
description: "Acceptable percentage difference of code coverage"
required: true
runs:
using: composite
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-validate-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-validate
- name: Vet
shell: bash
run: |
go vet $(go list -f '{{ .Dir }}' ./...)
- name: Lint
uses: golangci/golangci-lint-action@v2
with:
skip-go-installation: true
skip-pkg-cache: true
skip-build-cache: true
version: v1.47
- name: Build
shell: bash
run: go build -v ./...
- name: Test
shell: bash
run: |
make test
- name: Code coverage
shell: bash
id: coverage
run: |
echo "total=$(make -s coverage)" >> $GITHUB_OUTPUT
- name: Checkout master branch
uses: actions/checkout@v2
with:
ref: master
path: master
- name: Master branch code coverage
shell: bash
id: master-coverage
run: |
make test
echo "total=$(make -s coverage)" >> $GITHUB_OUTPUT
working-directory: ./master
- name: Coverage threshold check
shell: bash
run: |
COVERAGE=${{ steps.coverage.outputs.total }}
MASTER_COVERAGE=${{ steps.master-coverage.outputs.total }}
COVERAGE_THRESHOLD=${{ inputs.COVERAGE_THRESHOLD }}
if (( $(echo "$MASTER_COVERAGE - $COVERAGE > $COVERAGE_THRESHOLD" | bc -l) )) ; then
echo "coverage fell by more than $COVERAGE_THRESHOLD%"
exit 1
fi
19 changes: 19 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Merge

on:
push:
branches: [master]
workflow_dispatch:

jobs:
go:
name: Validate Go code
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Validate and test Go code
id: go
uses: ./.github/actions/go
with:
COVERAGE_THRESHOLD: ${{ vars.COVERAGE_THRESHOLD }}
17 changes: 17 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Pull Request

on:
pull_request:

jobs:
go:
name: Validate Go code
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Validate and test Go code
id: go
uses: ./.github/actions/go
with:
COVERAGE_THRESHOLD: ${{ vars.COVERAGE_THRESHOLD }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
toolbin
run.sh
*coverage.*
43 changes: 43 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Forta Network License
## Definitions

**Additional Use Grant:** Any uses agreed upon under written contract with the Forta Foundation.

**Change Date:** The earlier of January 1, 2026 or a date specified by the Forta Foundation.

**Change License:** GNU General Public License 3.0 or later

**Licensed Work:** `core-go` located at https://github.com/forta-network/core-go. The Licensed Work is Copyright (c) 2022 Forta Foundation

**Licensor:** Forta Foundation

## Notice
For information regarding licensing the Licensed Work under alternative licensing arrangements including Additional Use Grants, please see https://https://forta.org/.


This Forta Network License (the “License”) does not meet the Open Source Definition as maintained by the Open Source Initiative, however the source code of the Licensed Work is made available under this License.

## Terms

Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work in accordance with the terms of this License. The Licensor may make an Additional Use Grant, above, permitting limited production use.


Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.


If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.


All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.


You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.


Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.


This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License).


TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE.
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
export GOBIN = $(shell pwd)/toolbin

LINT = $(GOBIN)/golangci-lint
FORMAT = $(GOBIN)/goimports

MOCKGEN = $(GOBIN)/mockgen

.PHONY: require-tools
require-tools: tools
@echo 'Checking installed tools...'
@file $(LINT) > /dev/null
@file $(FORMAT) > /dev/null

@echo "All tools found in $(GOBIN)!"

.PHONY: tools
tools:
@echo 'Installing tools...'
@rm -rf toolbin
@go install github.com/golangci/golangci-lint/cmd/[email protected]
@go install golang.org/x/tools/cmd/[email protected]

@go install github.com/golang/mock/mockgen@5b455625bd2c8ffbcc0de6a0873f864ba3820904

.PHONY: fmt
fmt: require-tools
@go mod tidy
@$(FORMAT) -w $$(go list -f {{.Dir}} ./...)

.PHONY: lint
lint: require-tools fmt
@$(LINT) run ./...

.PHONY: mocks
mocks:
$(MOCKGEN) -source ethereum/client.go -destination ethereum/mocks/mock_client.go

.PHONY: test
test:
go test -v -count=1 -short -coverprofile=coverage.out ./...

.PHONY: coverage
coverage:
go tool cover -func=coverage.out | grep total | awk '{print substr($$3, 1, length($$3)-1)}'

.PHONY: coverage-func
coverage-func:
go tool cover -func=coverage.out

.PHONY: coverage-html
coverage-html:
go tool cover -html=coverage.out -o=coverage.html

.PHONY: pull-contracts
pull-contracts:
./scripts/pull-contracts.sh forta-contracts 59ae488

.PHONY: swagger
swagger: require-tools
@rm -rf clients/webhook/swagger
@$(SWAGGER) generate client \
-f protocol/webhook/swagger.yml \
-c clients/webhook/client \
-m clients/webhook/client/models
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
![Go](https://github.com/forta-network/core-go/actions/workflows/merge.yml/badge.svg)
# core-go

This contains key golang libraries for Forta services.

## Bug Bounty

We have a [bug bounty program on Immunefi](https://immunefi.com/bounty/forta). Please report any security issues you find through the Immunefi dashboard, or reach out to [[email protected]](mailto:[email protected])
Loading

0 comments on commit 2d052c1

Please sign in to comment.