-
Notifications
You must be signed in to change notification settings - Fork 14
186 lines (178 loc) · 5.96 KB
/
ci-smart-contract.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: Smart Contract CI
# Smart Contract CI workflow runs CI test for checking if smart contract works well
# This workflow is run on pushes to main & every Pull Requests where a .go, .mod, .sum, ci_test/**.sh, and this file have been changed
on:
pull_request:
push:
branches:
- main
env:
TEST_DOCKER_IMAGE: finschianode:smartcontractci
GO_VERSION: "1.20"
jobs:
cleanup-runs:
runs-on: ubuntu-latest
steps:
- uses: rokroskar/workflow-run-cleanup-action@master
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/main'"
check-diffs:
runs-on: ubuntu-latest
outputs:
get_diff: ${{ steps.diff.outputs.diff }}
steps:
- uses: actions/checkout@v3
- name: Get diff
id: diff
uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.go
go.mod
go.sum
.github/workflows/ci-smart-contract.yml
ci_test/**
get-cosmwasm-releases:
runs-on: ubuntu-latest
outputs:
cosmwasm_versions: ${{ steps.releases.outputs.versions }}
steps:
- uses: actions/checkout@v3
- name: Get cosmwasm releases
id: releases
run: |
response=$(curl -s "https://api.github.com/repos/Finschia/cosmwasm/releases")
versions=$(echo "$response" | jq -r '[.[].tag_name]' | jq -c .)
echo "versions=${versions}" >> "$GITHUB_OUTPUT"
build:
runs-on: ubuntu-latest
needs: check-diffs
if: ${{ needs.check-diffs.outputs.get_diff }}
strategy:
matrix:
go-arch: ["amd64"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Build
run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false LINK_STATICALLY=true make build
- name: Upload build
uses: actions/upload-artifact@v3
with:
name: fnsad
path: ./build/fnsad
test-smart-contract-on-local-node:
runs-on: ubuntu-latest
needs: [build, get-cosmwasm-releases]
strategy:
fail-fast: false
matrix:
versions: ${{ fromJson(needs.get-cosmwasm-releases.outputs.cosmwasm_versions) }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Download smart contracts
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: 'Finschia/cosmwasm'
version: tags/${{ matrix.versions }}
regex: true
file: '.*'
target: 'contracts/'
- name: Download build
uses: actions/download-artifact@v3
with:
name: fnsad
path: ./build
- name: Build install
run: make install
- name: Set configure file
run: ./init_single.sh
shell: bash
# sleep 1 second to wait for finschia to start up
- name: Start local node
id: start
run: |
fnsad start &
sleep 1
- name: CI test
run: bash ./ci_test/queue_ci.sh
shell: bash
- name: Stop local node
if: ${{ always() && steps.start.conclusion == 'success' }}
run: kill $(ps -ef | grep "fnsad start" | grep -v grep | awk '{print $2}')
build-finschia-docker-image:
runs-on: ubuntu-latest
needs: check-diffs
if: ${{ needs.check-diffs.outputs.get_diff }}
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v3
- name: Build and export
uses: docker/build-push-action@v5
with:
file: Dockerfile
context: .
tags: ${{ env.TEST_DOCKER_IMAGE }}
outputs: type=docker,dest=/tmp/finschia-ci-test.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: finschia-ci-test
path: /tmp/finschia-ci-test.tar
test-smart-contract-in-docker-container:
runs-on: ubuntu-latest
needs: [build-finschia-docker-image, get-cosmwasm-releases]
strategy:
fail-fast: false
matrix:
versions: ${{ fromJson(needs.get-cosmwasm-releases.outputs.cosmwasm_versions) }}
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v3
- name: Download smart contracts
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: 'Finschia/cosmwasm'
version: tags/${{ matrix.versions }}
regex: true
file: '.*'
target: 'contracts/'
- name: Download docker image
uses: actions/download-artifact@v3
with:
name: finschia-ci-test
path: /tmp
- name: Load image
run: |
docker load --input /tmp/finschia-ci-test.tar
docker image ls -a
- name: Set configure file
run: |
export FNSAD="docker run -i --rm -p 26656:26656 -p 26657:26657 -v ${pwd}/.finschia:/root/.finschia ${{ env.TEST_DOCKER_IMAGE }} fnsad"
./init_single.sh
shell: bash
# sleep 5 seconds to wait for finschia to start up
- name: Start docker container
id: docker_start
run: |
container_id=$(docker run -d \
-p 26656:26656 -p 26657:26657 \
-v ${pwd}/.finschia:/root/.finschia \
-v $(pwd)/ci_test:/root/ci_test \
-v $(pwd)/contracts:/root/contracts \
${{ env.TEST_DOCKER_IMAGE }} fnsad start)
echo "container_id=$container_id" >> "$GITHUB_OUTPUT"
sleep 5
- name: CI test
run: |
docker exec ${{ steps.docker_start.outputs.container_id }} apk add --no-cache jq bash && \
docker exec ${{ steps.docker_start.outputs.container_id }} bash ./ci_test/queue_ci.sh
- name: Stop docker container
if: ${{ always() && steps.docker_start.conclusion == 'success' }}
run: docker stop ${{ steps.docker_start.outputs.container_id }}