Skip to content

Commit 60be481

Browse files
committed
ci: migrate smart contract deployment to GitHub Actions
1 parent 61f77c9 commit 60be481

File tree

2 files changed

+92
-128
lines changed

2 files changed

+92
-128
lines changed

.drone.yml

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -46,135 +46,7 @@ steps:
4646
fi
4747
4848
---
49-
# deploy DataProtector smart contract to prod, dev or staging
50-
kind: pipeline
51-
type: docker
52-
name: smart-contract deploy
53-
54-
trigger:
55-
event:
56-
- promote
57-
target:
58-
# deploy and verify the DataProtector contract with the dev deployer
59-
- smart-contract-deploy-dev
60-
# deploy and verify the DataProtector contract with the dev deployer and commit the staging environment update
61-
- smart-contract-deploy-staging
62-
# deploy and verify the DataProtector contract with the prod deployer and commit the prod environment update
63-
- smart-contract-deploy-prod
64-
branch:
65-
- develop
66-
- main
67-
68-
steps:
69-
- name: install deps
70-
image: node:18.19
71-
pull: always
72-
commands:
73-
- cd packages/smart-contract
74-
- node -v
75-
- npm -v
76-
- npm ci
77-
78-
- name: check format
79-
image: node:18.19
80-
commands:
81-
- cd packages/smart-contract
82-
- npm run check-format
83-
84-
- name: check lint
85-
image: node:18.19
86-
commands:
87-
- cd packages/smart-contract
88-
- npm run lint
89-
90-
- name: compile smart contracts
91-
image: node:18.19
92-
commands:
93-
- cd packages/smart-contract
94-
- npm run compile
95-
96-
- name: test smart contracts
97-
image: node:18.19
98-
commands:
99-
- cd packages/smart-contract
100-
- npm run test
101-
102-
- name: smart-contract dev/staging deployment
103-
image: node:18.19
104-
environment:
105-
WALLET_PRIVATE_KEY:
106-
from_secret: deployer-dev-privatekey
107-
commands:
108-
- cd packages/smart-contract
109-
- npm run deploy -- --network bellecour
110-
when:
111-
target:
112-
- smart-contract-deploy-staging
113-
- smart-contract-deploy-dev
114-
branch:
115-
- develop
11649

117-
- name: smart-contract prod deployment
118-
image: node:18.19
119-
environment:
120-
WALLET_PRIVATE_KEY:
121-
from_secret: deployer-prod-privatekey
122-
commands:
123-
- cd packages/smart-contract
124-
- npm run deploy -- --network bellecour
125-
when:
126-
target:
127-
- smart-contract-deploy-prod
128-
branch:
129-
- main
130-
131-
- name: update prod env
132-
image: node:18.19
133-
environment:
134-
ENV: prod
135-
commands:
136-
- cd environments
137-
- KEY=dataprotectorContractAddress VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/address) npm run update-env
138-
- KEY=dataprotectorStartBlock VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/block) npm run update-env
139-
- git add environments.json
140-
- git commit -m "$DRONE_DEPLOY_TO deployment $DRONE_BUILD_NUMBER $DRONE_COMMIT" --author="drone-product <[email protected]>"
141-
when:
142-
target:
143-
- smart-contract-deploy-prod
144-
145-
- name: update staging env
146-
image: node:18.19
147-
environment:
148-
ENV: staging
149-
commands:
150-
- cd environments
151-
- KEY=dataprotectorContractAddress VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/address) npm run update-env
152-
- KEY=dataprotectorStartBlock VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/block) npm run update-env
153-
- git add environments.json
154-
- git commit -m "$DRONE_DEPLOY_TO deployment $DRONE_BUILD_NUMBER $DRONE_COMMIT" --author="drone-product <[email protected]>"
155-
when:
156-
target:
157-
- smart-contract-deploy-staging
158-
159-
- name: git-push
160-
image: appleboy/drone-git-push
161-
settings:
162-
remote: ssh://[email protected]/iExecBlockchainComputing/dataprotector-sdk.git
163-
branch: update-env-${DRONE_BUILD_NUMBER}
164-
ssh_key:
165-
from_secret: ssh-key-team-product-github-push
166-
when:
167-
target:
168-
- smart-contract-deploy-prod
169-
- smart-contract-deploy-staging
170-
171-
- name: verify contract
172-
image: node:18.19
173-
commands:
174-
- cd packages/smart-contract
175-
- npm run verify -- --network bellecour $(cat deployments/DataProtector/address) $(cat deployments/DataProtector/args)
176-
177-
---
17850
# deploy sharing smart contract to prod, staging or dev
17951
kind: pipeline
18052
type: docker
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
KEY=dataprotectorContractAddress VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/address) npm run update-env
68+
KEY=dataprotectorStartBlock VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/block) npm run update-env
69+
git add environments.json
70+
git commit -m "Deployment ${{ github.event.inputs.target }} run ${{ github.run_number }} commit ${{ github.sha }}" --author="drone-product <[email protected]>"
71+
72+
- name: Update staging environment
73+
if: ${{ github.event.inputs.target == 'smart-contract-deploy-staging' }}
74+
working-directory: environments
75+
run: |
76+
KEY=dataprotectorContractAddress VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/address) npm run update-env
77+
KEY=dataprotectorStartBlock VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/block) npm run update-env
78+
git add environments.json
79+
git commit -m "Deployment ${{ github.event.inputs.target }} run ${{ github.run_number }} commit ${{ github.sha }}" --author="drone-product <[email protected]>"
80+
81+
- name: Git push environment update
82+
if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' || github.event.inputs.target == 'smart-contract-deploy-staging' }}
83+
run: |
84+
git push ssh://[email protected]/iExecBlockchainComputing/dataprotector-sdk.git update-env-${{ github.run_number }}
85+
env:
86+
# Configure the SSH key to secrets GitHub
87+
SSH_KEY: ${{ secrets.SSH_KEY_TEAM_PRODUCT_GITHUB_PUSH }}
88+
shell: bash
89+
90+
- name: Verify contract
91+
working-directory: packages/smart-contract
92+
run: npm run verify -- --network bellecour $(cat deployments/DataProtector/address) $(cat deployments/DataProtector/args)

0 commit comments

Comments
 (0)