Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit 35a0efc

Browse files
authored
feat(ci/cd): add workflows for ci & release (#3)
* Github actions * Fix linter issues. Upgrade to go v1.20 * Add linting for TS * Add release workflow
1 parent 737094e commit 35a0efc

File tree

13 files changed

+906
-2429
lines changed

13 files changed

+906
-2429
lines changed

.github/workflows/ci.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Lint and Test
2+
on: [ pull_request, workflow_dispatch, create ]
3+
4+
jobs:
5+
lint-go:
6+
name: Lint Golang
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
11+
- uses: actions/setup-go@v4
12+
with:
13+
go-version: '1.20'
14+
cache: false
15+
16+
- name: golangci-lint
17+
uses: golangci/golangci-lint-action@v3
18+
with:
19+
version: v1.53.3
20+
args: --config=.golangci.yml
21+
22+
lint-ui-payment:
23+
name: Lint Payment UI
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v3
27+
28+
- name: Install dependencies
29+
run: npm ci --ignore-scripts
30+
working-directory: ui-payment
31+
32+
- name: ESLint
33+
run: npx eslint src --ext .js,.jsx,.ts,.tsx
34+
working-directory: ui-payment
35+
36+
- name: TS Verify
37+
run: npx tsc --noEmit --skipLibCheck -p ./tsconfig.json
38+
working-directory: ui-payment
39+
40+
lint-ui-dashboard:
41+
name: Lint Dashboard UI
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v3
45+
46+
- name: Install dependencies
47+
run: npm ci --ignore-scripts
48+
working-directory: ui-dashboard
49+
50+
- name: ESLint
51+
run: npx eslint src --ext .js,.jsx,.ts,.tsx
52+
working-directory: ui-dashboard
53+
54+
- name: TS Verify
55+
run: npx tsc --noEmit --skipLibCheck -p ./tsconfig.json
56+
working-directory: ui-dashboard

.github/workflows/release.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Build Oxygen
2+
on:
3+
release:
4+
types: [ created ]
5+
6+
env:
7+
REGISTRY: ghcr.io
8+
9+
jobs:
10+
build-ui-payment:
11+
name: Build Payment UI
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install dependencies
17+
run: npm ci --ignore-scripts
18+
working-directory: ui-payment
19+
20+
- name: Build
21+
run: npx tsc && npx vite build --base=${{ env.VITE_ROOTPATH }}
22+
working-directory: ui-payment
23+
env:
24+
VITE_BACKEND_HOST: '//'
25+
VITE_SUPPORT_EMAIL: 'help@site.com'
26+
VITE_ROOTPATH: '/p/'
27+
28+
- name: Publish dist
29+
uses: actions/upload-artifact@v3
30+
with:
31+
name: ui-payment-artifact
32+
path: ui-payment/dist/
33+
34+
build-ui-dashboard:
35+
name: Build Dashboard UI
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v3
39+
40+
- name: Install dependencies
41+
run: npm ci
42+
working-directory: ui-dashboard
43+
44+
- name: Build
45+
run: npx tsc && npx vite build --base=${{ env.VITE_ROOTPATH }}
46+
working-directory: ui-dashboard
47+
env:
48+
VITE_BACKEND_HOST: '//'
49+
VITE_ROOTPATH: '/dashboard/'
50+
51+
- name: Publish dist
52+
uses: actions/upload-artifact@v3
53+
with:
54+
name: ui-dashboard-artifact
55+
path: ui-dashboard/dist/
56+
57+
build-docker-image:
58+
name: Build Docker Image
59+
needs: [ build-ui-payment, build-ui-dashboard ]
60+
runs-on: ubuntu-latest
61+
# allow job to upload container images to ghcr
62+
permissions: write-all
63+
steps:
64+
- name: Checkout repository
65+
uses: actions/checkout@v3
66+
67+
- name: Set up Docker Buildx
68+
uses: docker/setup-buildx-action@v1
69+
70+
- name: Copy UI Payment UI artifact
71+
uses: actions/download-artifact@v3
72+
with:
73+
name: ui-payment-artifact
74+
path: ui-payment/dist/
75+
76+
- name: Copy Dashboard UI artifact
77+
uses: actions/download-artifact@v3
78+
with:
79+
name: ui-dashboard-artifact
80+
path: ui-dashboard/dist/
81+
82+
- name: Login to GitHub container registry
83+
uses: docker/login-action@v2
84+
with:
85+
registry: ${{ env.REGISTRY }}
86+
username: ${{ github.actor }}
87+
password: ${{ secrets.GITHUB_TOKEN }}
88+
89+
- name: Build and push image
90+
run: |
91+
# refs/tags/*
92+
TAG=${GITHUB_REF:10}
93+
echo "TAG=$TAG"
94+
95+
docker build -t $REGISTRY/$IMAGE:$TAG -t $REGISTRY/$IMAGE:latest .
96+
docker push $REGISTRY/$IMAGE:$TAG
97+
docker push $REGISTRY/$IMAGE:latest
98+
env:
99+
IMAGE: ${{ github.repository }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ bin/
55
config/*.yml
66
!config/*example.yml
77
web/redoc/**/*.json
8-
docker.env
8+
docker.env
9+
.actrc

.golangci.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
run:
2-
go: '1.18'
2+
go: '1.20'
3+
timeout: 5m
34
skip-dirs:
45
- ./api/proto
56
- ./bin
@@ -59,7 +60,6 @@ linters:
5960
disable-all: true
6061
enable:
6162
- bodyclose
62-
- depguard
6363
- dogsled
6464
- errcheck
6565
- funlen
@@ -85,7 +85,4 @@ linters:
8585
- unused
8686
- whitespace
8787
- prealloc
88-
- nonamedreturns
89-
90-
service:
91-
golangci-lint-version: 1.45.x # use the fixed version to not introduce new linters unexpectedly
88+
- nonamedreturns

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ require-deps: ## Require cli tools for development
7474
go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
7575
go install github.com/cespare/reflex@latest
7676
go install github.com/vektra/mockery/v2@latest
77-
# todo linter
77+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3
7878
# todo go-swagger as swagger
7979

8080
docker-build: ## Build docker image for Oxygen

internal/provider/trongrid/provider.go

Lines changed: 72 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,21 @@ func (p *Provider) CallContract(
186186
}
187187

188188
// BroadcastResponse. Examples:
189-
// {
190-
// "code": "CONTRACT_VALIDATE_ERROR",
191-
// "txid": "50d52436163be5c38af269bbdee0a7e258e94cfa9cc05f975e543b98c6994f2e",
192-
// "message": "Contract validate error : account [TDVEJbSyEtk8L4htanm8h5mp2sNutRm5ou] does not exist"
193-
// }
194-
// {
195-
// "code": "DUP_TRANSACTION_ERROR",
196-
// "txid": "fbb158948b240f88b188c65f5a623b562fe4d7a9a90eecef4495146acf87a484",
197-
// "message": "Dup transaction."
198-
// }
199-
// {
200-
// "result": true,
201-
// "txid": "fbb158948b240f88b188c65f5a623b562fe4d7a9a90eecef4495146acf87a484"
202-
// }
189+
//
190+
// {
191+
// "code": "CONTRACT_VALIDATE_ERROR",
192+
// "txid": "50d52436163be5c38af269bbdee0a7e258e94cfa9cc05f975e543b98c6994f2e",
193+
// "message": "Contract validate error : account [TDVEJbSyEtk8L4htanm8h5mp2sNutRm5ou] does not exist"
194+
// }
195+
// {
196+
// "code": "DUP_TRANSACTION_ERROR",
197+
// "txid": "fbb158948b240f88b188c65f5a623b562fe4d7a9a90eecef4495146acf87a484",
198+
// "message": "Dup transaction."
199+
// }
200+
// {
201+
// "result": true,
202+
// "txid": "fbb158948b240f88b188c65f5a623b562fe4d7a9a90eecef4495146acf87a484"
203+
// }
203204
type BroadcastResponse struct {
204205
Result bool `json:"result"`
205206
Code string `json:"code"`
@@ -354,22 +355,22 @@ func (p *Provider) GetTransactionReceipt(
354355
}, nil
355356
}
356357

357-
// {
358-
// "id": "a53122608dbe423c713f9a93b1511d56278df98659aeb12c0c544dc7a88e43c5",
359-
// "fee": 36909560,
360-
// "blockNumber": 31349959,
361-
// "blockTimeStamp": 1676147655000,
362-
// "contractResult": [ "..." ],
363-
// "contract_address": "41ba221311e9f3ab22c27a2ad48e49f8ca56721da9",
364-
// "receipt": {
365-
// "energy_usage": 18612,
366-
// "energy_fee": 36274560,
367-
// "energy_usage_total": 148164,
368-
// "net_fee": 635000,
369-
// },
370-
// "log": [ ... ],
371-
// "internal_transactions": [ ... ]
372-
//}
358+
// {
359+
// "id": "a53122608dbe423c713f9a93b1511d56278df98659aeb12c0c544dc7a88e43c5",
360+
// "fee": 36909560,
361+
// "blockNumber": 31349959,
362+
// "blockTimeStamp": 1676147655000,
363+
// "contractResult": [ "..." ],
364+
// "contract_address": "41ba221311e9f3ab22c27a2ad48e49f8ca56721da9",
365+
// "receipt": {
366+
// "energy_usage": 18612,
367+
// "energy_fee": 36274560,
368+
// "energy_usage_total": 148164,
369+
// "net_fee": 635000,
370+
// },
371+
// "log": [ ... ],
372+
// "internal_transactions": [ ... ]
373+
// }
373374
func (p *Provider) getTransactionInfoByID(ctx context.Context, txID string, isTest bool) ([]byte, error) {
374375
payload := map[string]string{"value": txID}
375376

@@ -400,20 +401,20 @@ func (p *Provider) getTransactionInfoByID(ctx context.Context, txID string, isTe
400401
return body, nil
401402
}
402403

403-
// {
404-
// "blockID": "...",
405-
// "block_header": {
406-
// "raw_data": {
407-
// "number": 31579273,
408-
// "txTrieRoot": "...",
409-
// "witness_address": "41711cf6683d28621ae12030fd541b288c61d682cd",
410-
// "parentHash": "0000000001e1dc88cbc3e4224d61fd349bcbcae3a7f7bccd5cc616b45fea7cef",
411-
// "version": 26,
412-
// "timestamp": 1676929908000
413-
// },
414-
// "witness_signature": "..."
415-
// }
416-
//}
404+
// {
405+
// "blockID": "...",
406+
// "block_header": {
407+
// "raw_data": {
408+
// "number": 31579273,
409+
// "txTrieRoot": "...",
410+
// "witness_address": "41711cf6683d28621ae12030fd541b288c61d682cd",
411+
// "parentHash": "0000000001e1dc88cbc3e4224d61fd349bcbcae3a7f7bccd5cc616b45fea7cef",
412+
// "version": 26,
413+
// "timestamp": 1676929908000
414+
// },
415+
// "witness_signature": "..."
416+
// }
417+
// }
417418
func (p *Provider) getLatestBlock(ctx context.Context, isTest bool) ([]byte, error) {
418419
req, err := p.newRequest(ctx, http.MethodGet, "/walletsolidity/getnowblock", nil, isTest)
419420
if err != nil {
@@ -441,33 +442,33 @@ func (p *Provider) getLatestBlock(ctx context.Context, isTest bool) ([]byte, err
441442
return body, nil
442443
}
443444

444-
// {
445-
// "ret": [
446-
// { "contractRet": "SUCCESS" }
447-
// ],
448-
// "signature": [ "..." ],
449-
// "txID": "0471ef93ae986f8c73900787e429c570d96c161b7b25c59271083e80b1d460fc",
450-
// "raw_data": {
451-
// "contract": [
452-
// {
453-
// "parameter": {
454-
// "value": {
455-
// "amount": 5000000000,
456-
// "owner_address": "41b3dcf27c251da9363f1a4888257c16676cf54edf",
457-
// "to_address": "4199409c7014a738224159a8d3e12cc90163ce6db2"
458-
// },
459-
// "type_url": "type.googleapis.com/protocol.TransferContract"
460-
// },
461-
// "type": "TransferContract"
462-
// }
463-
// ],
464-
// "ref_block_bytes": "6828",
465-
// "ref_block_hash": "9bdfb56481721d3e",
466-
// "expiration": 1676157717000,
467-
// "timestamp": 1676157659717
468-
// },
469-
// "raw_data_hex": "..."
470-
//}
445+
// {
446+
// "ret": [
447+
// { "contractRet": "SUCCESS" }
448+
// ],
449+
// "signature": [ "..." ],
450+
// "txID": "0471ef93ae986f8c73900787e429c570d96c161b7b25c59271083e80b1d460fc",
451+
// "raw_data": {
452+
// "contract": [
453+
// {
454+
// "parameter": {
455+
// "value": {
456+
// "amount": 5000000000,
457+
// "owner_address": "41b3dcf27c251da9363f1a4888257c16676cf54edf",
458+
// "to_address": "4199409c7014a738224159a8d3e12cc90163ce6db2"
459+
// },
460+
// "type_url": "type.googleapis.com/protocol.TransferContract"
461+
// },
462+
// "type": "TransferContract"
463+
// }
464+
// ],
465+
// "ref_block_bytes": "6828",
466+
// "ref_block_hash": "9bdfb56481721d3e",
467+
// "expiration": 1676157717000,
468+
// "timestamp": 1676157659717
469+
// },
470+
// "raw_data_hex": "..."
471+
// }
471472
func (p *Provider) getTransactionByID(ctx context.Context, txID string, isTest bool) ([]byte, error) {
472473
payload := map[string]string{"value": txID}
473474

internal/service/blockchain/currencies.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (r *CurrencyResolver) GetUSDMinimalInternalTransferByTicker(ticker string)
8787

8888
// GetCurrencyByBlockchainAndContract searches currency by blockchain
8989
// and contract address across both mainnet & testnet.
90+
//
9091
//nolint:gocritic
9192
func (r *CurrencyResolver) GetCurrencyByBlockchainAndContract(bc money.Blockchain, networkID, addr string) (money.CryptoCurrency, error) {
9293
if bc == "" || networkID == "" || addr == "" {

internal/service/blockchain/currencies_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
)
1212

13-
func TestNew(t *testing.T) {
13+
func TestNew(_ *testing.T) {
1414
// todo returns sorted list
1515
// todo returns sorted by blockchain
1616
// todo add token to two different blockchain

internal/service/blockchain/service_convertor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func (s *Service) GetExchangeRate(ctx context.Context, from, to string) (Exchang
9797
// Convert Converts currencies according to automatically resolved ConversionType. This method parses amount as float64,
9898
// please don't use it internally as output would contain huge error rate when dealing with 18 eth decimals.
9999
// Suitable for API responses.
100+
//
100101
//nolint:gocyclo
101102
func (s *Service) Convert(ctx context.Context, from, to, amount string) (Conversion, error) {
102103
switch {

0 commit comments

Comments
 (0)