-
Notifications
You must be signed in to change notification settings - Fork 104
149 lines (144 loc) · 4.66 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: "CI"
on: # Run the workflows on push/PR to the main branch
push:
branches: [main,monorepo]
pull_request:
branches: [main,monorepo]
jobs:
lint: # Run lint script for all workspaces
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16.15.0"
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run lint script
run: npm run lint
build: # Run build script for all workspaces
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16.15.0"
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run build script
run: npm run build
test-datalock-chaincode: # Run chaincode tests for the chaincode/datalock directory
runs-on: ubuntu-latest
needs: lint
defaults:
run:
working-directory: ./fabric/chaincode/datalock
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.18"
- name: Run chaincode tests
run: go test -v internal/*.go -count=1
test-hardhat: # Run tests for the hardhat directory
runs-on: ubuntu-latest
needs: lint
services:
postgres:
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: blockchain-carbon-accounting-test
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16.15.0"
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run data tests
run: npm run test --prefix ./data
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
- name: Run hardhat tests
run: npm run test --prefix ./hardhat
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
test-typescript-app: # Build and test the typescript_app project
runs-on: ubuntu-latest
needs: lint
services:
postgres:
image: postgres:latest
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: blockchain-carbon-accounting-test
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16.15.0"
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Download Fabric binaries
run: |
sudo chmod +x /usr/local/bin/docker-compose
cd ./fabric/docker-compose-setup/
./bootstrap.sh 2.4.2 1.5.2 -d -s
- name: Start local Hardhat network # Start local Hardhat network needed for running net emissions token network
run: |
cd ./hardhat/
echo "n" | npx hardhat node &
- name: Build emissions-data project # Add required hostnames to /etc/hosts and runs start script
run: |
cd ./fabric/docker-compose-setup/
echo "127.0.0.1 auditor1.carbonAccounting.com
127.0.0.1 auditor2.carbonAccounting.com
127.0.0.1 peer1.auditor1.carbonAccounting.com
127.0.0.1 peer1.auditor2.carbonAccounting.com
127.0.0.1 peer1.auditor1.carbonAccounting.com" | sudo tee -a /etc/hosts
DB_HOST=postgres ./startDev.sh &
- name: Run tests # Wait for the blockchain network to start up and then run the tests
run: |
cd ./fabric/typescript_app/
while ! timeout 1 bash -c "echo > /dev/tcp/localhost/8080" > /dev/null 2>&1; do sleep 10; done
npm run test:setup
npm run test:ci
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
- name: Collect Docker Logs
if: failure()
uses: jwalton/[email protected]
- uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: test-results
path: fabric/typescript_app/test-results.json