Skip to content

Commit b3d33ee

Browse files
ci: migrate smart contract deployment to GitHub Actions (#412)
Co-authored-by: Le-Caignec <[email protected]>
1 parent 68e05f5 commit b3d33ee

File tree

2 files changed

+123
-107
lines changed

2 files changed

+123
-107
lines changed

.drone.yml

Lines changed: 27 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,52 @@
1-
# deploy DataProtector smart contract to prod, dev or staging
21
kind: pipeline
32
type: docker
4-
name: smart-contract deploy
3+
name: root checks
54

65
trigger:
76
event:
8-
- promote
9-
target:
10-
# deploy and verify the DataProtector contract with the dev deployer
11-
- smart-contract-deploy-dev
12-
# deploy and verify the DataProtector contract with the dev deployer and commit the staging environment update
13-
- smart-contract-deploy-staging
14-
# deploy and verify the DataProtector contract with the prod deployer and commit the prod environment update
15-
- smart-contract-deploy-prod
16-
branch:
17-
- develop
18-
- main
7+
- pull_request
198

209
steps:
21-
- name: install deps
22-
image: node:18.19
23-
pull: always
24-
commands:
25-
- cd packages/smart-contract
26-
- node -v
27-
- npm -v
28-
- npm ci
29-
30-
- name: check format
31-
image: node:18.19
32-
commands:
33-
- cd packages/smart-contract
34-
- npm run check-format
35-
36-
- name: check lint
37-
image: node:18.19
38-
commands:
39-
- cd packages/smart-contract
40-
- npm run lint
41-
42-
- name: compile smart contracts
43-
image: node:18.19
44-
commands:
45-
- cd packages/smart-contract
46-
- npm run compile
47-
48-
- name: test smart contracts
10+
- name: cat-drone-consider
4911
image: node:18.19
5012
commands:
51-
- cd packages/smart-contract
52-
- npm run test
53-
54-
- name: smart-contract dev/staging deployment
55-
image: node:18.19
56-
environment:
57-
WALLET_PRIVATE_KEY:
58-
from_secret: deployer-dev-privatekey
59-
commands:
60-
- cd packages/smart-contract
61-
- npm run deploy -- --network bellecour
62-
when:
63-
target:
64-
- smart-contract-deploy-staging
65-
- smart-contract-deploy-dev
66-
branch:
67-
- develop
13+
- cat .drone-consider
6814

69-
- name: smart-contract prod deployment
15+
- name: check-sdk-abi
7016
image: node:18.19
71-
environment:
72-
WALLET_PRIVATE_KEY:
73-
from_secret: deployer-prod-privatekey
7417
commands:
75-
- cd packages/smart-contract
76-
- npm run deploy -- --network bellecour --verify
77-
when:
78-
target:
79-
- smart-contract-deploy-prod
80-
branch:
81-
- main
18+
- cd packages/sdk
19+
- npm run refresh-abis
20+
- |
21+
if [ -n "$(git diff --name-only)" ]; then
22+
echo "ABIs not up-to-date in packages/sdk, need to run 'npm run refresh-abis'"
23+
exit 1
24+
fi
8225
83-
- name: update prod env
26+
- name: check-subgraph-abi
8427
image: node:18.19
85-
environment:
86-
ENV: prod
8728
commands:
88-
- cd environments
29+
- cd packages/subgraph
30+
- npm run refresh-abis
8931
- |
90-
ADDRESS=$(jq -r '.contractAddress' ../packages/smart-contract/ignition/deployments/chain-134/journal.jsonl)
91-
BLOCK=$(jq -r '.blockNumber' ../packages/smart-contract/ignition/deployments/chain-134/journal.jsonl)
92-
KEY=dataprotectorContractAddress VALUE=$ADDRESS npm run update-env
93-
KEY=dataprotectorStartBlock VALUE=$BLOCK npm run update-env
94-
- git add environments.json
95-
- git commit -m "$DRONE_DEPLOY_TO deployment $DRONE_BUILD_NUMBER $DRONE_COMMIT" --author="drone-product <[email protected]>"
96-
when:
97-
target:
98-
- smart-contract-deploy-prod
32+
if [ -n "$(git diff --name-only)" ]; then
33+
echo "ABIs not up-to-date in packages/subgraph, need to run 'npm run refresh-abis'"
34+
exit 1
35+
fi
9936
100-
- name: update staging env
37+
- name: check-dapp-abi
10138
image: node:18.19
102-
environment:
103-
ENV: staging
10439
commands:
105-
- cd environments
40+
- cd packages/protected-data-delivery-dapp/deployment
41+
- npm run refresh-abis
10642
- |
107-
ADDRESS=$(jq -r '.contractAddress' ../packages/smart-contract/ignition/deployments/chain-134/journal.json)
108-
BLOCK=$(jq -r '.blockNumber' ../packages/smart-contract/ignition/deployments/chain-134/journal.json)
109-
KEY=dataprotectorContractAddress VALUE=$ADDRESS npm run update-env
110-
KEY=dataprotectorStartBlock VALUE=$BLOCK npm run update-env
111-
- git add environments.json
112-
- git commit -m "$DRONE_DEPLOY_TO deployment $DRONE_BUILD_NUMBER $DRONE_COMMIT" --author="drone-product <[email protected]>"
113-
when:
114-
target:
115-
- smart-contract-deploy-staging
116-
117-
- name: git-push
118-
image: appleboy/drone-git-push
119-
settings:
120-
remote: ssh://[email protected]/iExecBlockchainComputing/dataprotector-sdk.git
121-
branch: update-env-${DRONE_BUILD_NUMBER}
122-
ssh_key:
123-
from_secret: ssh-key-team-product-github-push
124-
when:
125-
target:
126-
- smart-contract-deploy-prod
127-
- smart-contract-deploy-staging
43+
if [ -n "$(git diff --name-only)" ]; then
44+
echo "ABIs not up-to-date in protected-data-delivery-dapp/abis, need to run 'npm run refresh-abis'"
45+
exit 1
46+
fi
12847
12948
---
49+
13050
# deploy sharing smart contract to prod, staging or dev
13151
kind: pipeline
13252
type: docker
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Smart Contract Deploy
2+
3+
on:
4+
workflow_dispatch: # Manually trigger the workflow OR trigger with tags or releases ?
5+
inputs:
6+
target:
7+
description: "Deployment target (smart-contract-deploy-dev, smart-contract-deploy-staging, smart-contract-deploy-prod)"
8+
required: true
9+
type: choice
10+
options:
11+
- smart-contract-deploy-dev
12+
- smart-contract-deploy-staging
13+
- smart-contract-deploy-prod
14+
default: smart-contract-deploy-dev
15+
16+
jobs:
17+
deploy:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: '18'
25+
26+
- name: Install dependencies
27+
working-directory: packages/smart-contract
28+
run: |
29+
node -v
30+
npm -v
31+
npm ci
32+
33+
- name: Check code format
34+
working-directory: packages/smart-contract
35+
run: npm run check-format
36+
37+
- name: Run lint
38+
working-directory: packages/smart-contract
39+
run: npm run lint
40+
41+
- name: Compile smart contracts
42+
working-directory: packages/smart-contract
43+
run: npm run compile
44+
45+
- name: Run tests
46+
working-directory: packages/smart-contract
47+
run: npm run test
48+
49+
- name: Deploy to dev/staging
50+
if: ${{ (github.event.inputs.target == 'smart-contract-deploy-dev' || github.event.inputs.target == 'smart-contract-deploy-staging') && startsWith(github.ref, 'refs/heads/develop') }}
51+
working-directory: packages/smart-contract
52+
env:
53+
WALLET_PRIVATE_KEY: ${{ secrets.DEPLOYER_DEV_PRIVATEKEY }}
54+
run: npm run deploy -- --network bellecour
55+
56+
- name: Deploy to prod
57+
if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' && github.ref == 'refs/heads/main' }}
58+
working-directory: packages/smart-contract
59+
env:
60+
WALLET_PRIVATE_KEY: ${{ secrets.DEPLOYER_PROD_PRIVATEKEY }}
61+
run: npm run deploy -- --network bellecour
62+
63+
- name: Update production environment
64+
if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' }}
65+
working-directory: environments
66+
run: |
67+
ADDRESS=$(jq -r '.contractAddress' ../packages/smart-contract/ignition/deployments/chain-134/journal.jsonl)
68+
BLOCK=$(jq -r '.blockNumber' ../packages/smart-contract/ignition/deployments/chain-134/journal.jsonl)
69+
KEY=dataprotectorContractAddress VALUE=$ADDRESS npm run update-env
70+
KEY=dataprotectorStartBlock VALUE=$BLOCK npm run update-env
71+
git add environments.json
72+
git commit -m "Deployment ${{ github.event.inputs.target }} run ${{ github.run_number }} commit ${{ github.sha }}" --author="drone-product <[email protected]>"
73+
74+
- name: Update staging environment
75+
if: ${{ github.event.inputs.target == 'smart-contract-deploy-staging' }}
76+
working-directory: environments
77+
run: |
78+
ADDRESS=$(jq -r '.contractAddress' ../packages/smart-contract/ignition/deployments/chain-134/journal.json)
79+
BLOCK=$(jq -r '.blockNumber' ../packages/smart-contract/ignition/deployments/chain-134/journal.json)
80+
KEY=dataprotectorContractAddress VALUE=$ADDRESS npm run update-env
81+
KEY=dataprotectorStartBlock VALUE=$BLOCK npm run update-env
82+
git add environments.json
83+
git commit -m "Deployment ${{ github.event.inputs.target }} run ${{ github.run_number }} commit ${{ github.sha }}" --author="drone-product <[email protected]>"
84+
85+
- name: Git push environment update
86+
if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' || github.event.inputs.target == 'smart-contract-deploy-staging' }}
87+
run: |
88+
git push ssh://[email protected]/iExecBlockchainComputing/dataprotector-sdk.git update-env-${{ github.run_number }}
89+
env:
90+
# Configure the SSH key to secrets GitHub
91+
SSH_KEY: ${{ secrets.SSH_KEY_TEAM_PRODUCT_GITHUB_PUSH }}
92+
shell: bash
93+
94+
- name: Verify contract
95+
working-directory: packages/smart-contract
96+
run: npm run verify -- --network bellecour $(cat deployments/DataProtector/address) $(cat deployments/DataProtector/args)

0 commit comments

Comments
 (0)