Skip to content

Commit a12d199

Browse files
authored
ci: Migrate sharing contract upgrade CI from Drone to GHA (#519)
* ci: Remove upgrade section from drone file * ci: Prepare upgrade action
1 parent 1aa357a commit a12d199

File tree

3 files changed

+48
-103
lines changed

3 files changed

+48
-103
lines changed

.drone.yml

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -33,91 +33,3 @@ steps:
3333
echo "ABIs not up-to-date in packages/subgraph, need to run 'npm run refresh-abis'"
3434
exit 1
3535
fi
36-
37-
---
38-
# pipeline to upgrade the DataProtectorSharing SC
39-
kind: pipeline
40-
type: docker
41-
name: sharing-smart-contract upgrade
42-
43-
trigger:
44-
event:
45-
- promote
46-
target:
47-
# upgrade the staging DataProtectorSharing contract with the new implementation
48-
- sharing-smart-contract-upgrade-staging
49-
# # upgrade the prod DataProtectorSharing contract with the new implementation
50-
# - sharing-smart-contract-upgrade-prod
51-
branch:
52-
- main
53-
54-
steps:
55-
- name: install-deps
56-
image: node:18.19
57-
pull: always
58-
commands:
59-
- cd packages/sharing-smart-contract
60-
- npm ci
61-
62-
- name: install-forge
63-
image: node:18.19
64-
pull: always
65-
commands:
66-
- export XDG_CONFIG_HOME=/drone/src
67-
- curl -L https://foundry.paradigm.xyz | bash
68-
- export PATH="$PATH:/drone/src/.foundry/bin"
69-
- foundryup
70-
- forge install foundry-rs/forge-std --no-git
71-
72-
- name: smart-contract-staging-upgrade
73-
image: node:18.19
74-
environment:
75-
WALLET_PRIVATE_KEY:
76-
# TODO replace by dataprotector-admin-dev-privatekey
77-
from_secret: deployer-dev-privatekey
78-
ENV: staging
79-
MANIFEST_DEFAULT_DIR: .openzeppelin/staging
80-
commands:
81-
- cd packages/sharing-smart-contract
82-
- export PATH="$PATH:/drone/src/.foundry/bin"
83-
- npm run upgrade -- --network bellecour
84-
- git add .openzeppelin
85-
- git commit -m "$DRONE_DEPLOY_TO deployment $DRONE_BUILD_NUMBER $DRONE_COMMIT" --author="drone-product <[email protected]>"
86-
depends_on:
87-
- install-forge
88-
- install-deps
89-
when:
90-
target:
91-
- sharing-smart-contract-upgrade-staging
92-
93-
# - name: smart-contract-prod-upgrade
94-
# image: node:18.19
95-
# environment:
96-
# WALLET_PRIVATE_KEY:
97-
# # TODO replace by dataprotector-admin-prod-privatekey
98-
# from_secret: deployer-prod-privatekey
99-
# ENV: prod
100-
# MANIFEST_DEFAULT_DIR: .openzeppelin/prod
101-
# commands:
102-
# - cd packages/sharing-smart-contract
103-
# - export PATH="$PATH:/drone/src/.foundry/bin"
104-
# - npm run upgrade -- --network bellecour
105-
# - git add .openzeppelin
106-
# - git commit -m "$DRONE_DEPLOY_TO deployment $DRONE_BUILD_NUMBER $DRONE_COMMIT" --author="drone-product <[email protected]>"
107-
# depends_on:
108-
# - install-forge
109-
# - install-deps
110-
# when:
111-
# target:
112-
# - sharing-smart-contract-upgrade-prod
113-
114-
- name: git-push
115-
image: appleboy/drone-git-push
116-
settings:
117-
remote: ssh://[email protected]/iExecBlockchainComputing/dataprotector-sdk.git
118-
branch: update-env-${DRONE_BUILD_NUMBER}
119-
ssh_key:
120-
from_secret: ssh-key-team-product-github-push
121-
depends_on:
122-
- smart-contract-staging-upgrade
123-
# - smart-contract-prod-upgrade

.github/workflows/sharing-smart-contract-deploy.yml

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
name: Sharing Smart Contract - Deploy
1+
name: Sharing Smart Contract - Deploy or Upgrade
22

33
on:
4-
workflow_dispatch: # Manual trigger
4+
workflow_dispatch: # Manually triggered
55
inputs:
66
network:
77
description: 'Network'
@@ -15,34 +15,41 @@ on:
1515
- bellecour
1616
default: 'hardhat'
1717
stage:
18-
description: 'Deployment stage'
18+
description: 'Target stage'
1919
required: true
2020
type: choice
2121
options:
2222
- dev
2323
- prod
2424
default: 'dev'
25+
operation:
26+
description: 'Which operation to execute (deploy or upgrade)'
27+
required: true
28+
type: choice
29+
options:
30+
- deploy
31+
- upgrade
32+
default: 'deploy'
2533

2634
jobs:
2735
build-and-test:
2836
uses: ./.github/workflows/sharing-smart-contracts-ci.yml
2937
with:
3038
node-version: 20
3139

32-
deploy:
40+
deploy-or-upgrade:
3341
needs: build-and-test
3442
runs-on: ubuntu-latest
3543
environment: ${{ inputs.network }}
3644
permissions:
37-
contents: write # Required to commit deployment files.
45+
contents: write # Required to commit artifacts.
3846
pull-requests: write # Required to create pull requests.
3947
env:
4048
CI: true
4149
# For commit action
42-
COMMIT_MESSAGE: 'chore: Save deployment artifacts - ${{ inputs.network }} ${{ inputs.stage }} (${{ github.run_id }})'
50+
COMMIT_MESSAGE: 'chore: Save artifacts - ${{ inputs.network }} ${{ inputs.stage }} (${{ github.run_id }})'
4351
GHA_BOT_NAME: 'GitHub Actions Bot'
4452
GHA_BOT_EMAIL: 'github-actions[bot]@users.noreply.github.com'
45-
4653
steps:
4754
- name: Validate target environment
4855
id: validate-env
@@ -89,6 +96,7 @@ jobs:
8996
cache: true
9097

9198
- name: Deploy contracts
99+
if: inputs.operation == 'deploy'
92100
working-directory: packages/sharing-smart-contract
93101
env:
94102
DEPLOYMENT_ID: ${{ steps.validate-env.outputs.deployment-id }}
@@ -97,11 +105,24 @@ jobs:
97105
ADMIN_PRIVATE_KEY: ${{ secrets.DATAPROTECTOR_OWNER_PRIVATEKEY }} # TODO Fix secret name
98106
POCO_ADDRESS: ${{ vars.POCO_ADDRESS }}
99107
DATASET_REGISTRY_ADDRESS: ${{ vars.DATASET_REGISTRY_ADDRESS }}
100-
run: |
101-
DEPLOYMENT_ID="$DEPLOYMENT_ID" \
102-
npm run deploy -- --network ${{ inputs.network }}
108+
run: DEPLOYMENT_ID="$DEPLOYMENT_ID" npm run deploy -- --network ${{ inputs.network }}
109+
110+
- name: Upgrade contracts
111+
if: inputs.operation == 'upgrade'
112+
working-directory: packages/sharing-smart-contract
113+
env:
114+
DEPLOYMENT_ID: ${{ steps.validate-env.outputs.deployment-id }}
115+
RPC_URL: ${{ secrets.RPC_URL }}
116+
ADMIN_PRIVATE_KEY: ${{ secrets.DATAPROTECTOR_OWNER_PRIVATEKEY }} # TODO Fix secret name
117+
POCO_ADDRESS: ${{ vars.POCO_ADDRESS }}
118+
DATASET_REGISTRY_ADDRESS: ${{ vars.DATASET_REGISTRY_ADDRESS }}
119+
# ENV: staging or prod
120+
# MANIFEST_DEFAULT_DIR: .openzeppelin/staging or .openzeppelin/prod
121+
# ADD_ONLY_APP_WHITELIST_REGISTRY_ADDRESS: '0xabc...'
122+
# TODO implement upgrade script.
123+
run: DEPLOYMENT_ID="$DEPLOYMENT_ID" npm run upgrade -- --network ${{ inputs.network }}
103124

104-
- name: Push deployment artifacts to the current branch
125+
- name: Push artifacts to the current branch
105126
if: inputs.network != 'hardhat' && github.ref != 'refs/heads/main'
106127
uses: stefanzweifel/git-auto-commit-action@v5
107128
with:
@@ -113,8 +134,8 @@ jobs:
113134
commit_user_email: ${{ env.GHA_BOT_EMAIL }}
114135
commit_author: '${{ env.GHA_BOT_NAME }} <${{ env.GHA_BOT_EMAIL }}>'
115136

116-
# Since `main` branch is protected, create a PR to push deployment files.
117-
- name: Push deployment artifacts through a pull request
137+
# Since the `main` branch is protected, create a PR to push artifacts.
138+
- name: Push artifacts through a pull request
118139
if: inputs.network != 'hardhat' && github.ref == 'refs/heads/main'
119140
uses: peter-evans/create-pull-request@v7
120141
with:
@@ -124,9 +145,9 @@ jobs:
124145
packages/sharing-smart-contract/.openzeppelin/
125146
committer: '${{ env.GHA_BOT_NAME }} <${{ env.GHA_BOT_EMAIL }}>'
126147
author: '${{ env.GHA_BOT_NAME }} <${{ env.GHA_BOT_EMAIL }}>'
127-
branch: chore/save-deployment-artifacts
148+
branch: chore/save-artifacts
128149
title: ${{ env.COMMIT_MESSAGE }}
129-
body: 'PR created by "Create Pull Request" action.'
150+
body: 'PR created by "Create Pull Request" GitHub Action.'
130151
draft: true
131152

132153
- name: Verify contracts

packages/sharing-smart-contract/scripts/upgrade.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ import env from '../config/env.js';
44

55
const { ethers, upgrades } = hre;
66

7+
// This script is under construction.
8+
// TODO implement the upgrade logic and remove the throw below.
9+
// Questions:
10+
// - How to get DATA_PROTECTOR_SHARING_ADDRESS and ADD_ONLY_APP_WHITELIST_REGISTRY_ADDRESS?
11+
12+
function throwAndExitTemporarily() {
13+
throw new Error('Not implemented yet.');
14+
}
15+
716
async function main() {
17+
// ⚠️
18+
throwAndExitTemporarily();
19+
820
const dataprotectorSharingContractAddress = env.DATA_PROTECTOR_SHARING_ADDRESS;
921
const addOnlyAppWhitelistRegistryContractAddress = env.ADD_ONLY_APP_WHITELIST_REGISTRY_ADDRESS;
1022

0 commit comments

Comments
 (0)