Skip to content

Commit 4ab8e35

Browse files
committed
ci: Prepare upgrade action
1 parent 402590f commit 4ab8e35

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

.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)