Skip to content

Commit 95973ff

Browse files
authored
refactor: Refactor sharing contract deployer action (#515)
* refactor: Clean action files * ci: Migrate deserializer CI from Drone to GHA * fix: Restaure non-migrated sharing contract upgrade drone ci * ci: Remove migrated file * ci: Fix CI * ci: Clean and fix ci * ci: Rename CI parameter for better clarity * ci: Refactor environment check * ci: Move check earlier * ci: Create pull requests for main branch * ci: Fix pull request step
1 parent 490fe94 commit 95973ff

File tree

2 files changed

+65
-57
lines changed

2 files changed

+65
-57
lines changed

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

Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ on:
1414
- arbitrum
1515
- bellecour
1616
default: 'hardhat'
17-
environment:
18-
description: 'Environment'
17+
stage:
18+
description: 'Deployment stage'
1919
required: true
2020
type: choice
2121
options:
@@ -32,12 +32,42 @@ jobs:
3232
deploy:
3333
needs: build-and-test
3434
runs-on: ubuntu-latest
35-
env:
36-
CI: true
35+
environment: ${{ inputs.network }}
3736
permissions:
3837
contents: write # Required to commit deployment files.
39-
environment: ${{ inputs.network }}
38+
pull-requests: write # Required to create pull requests.
39+
env:
40+
CI: true
41+
# For commit action
42+
COMMIT_MESSAGE: 'chore: Save deployment artifacts - ${{ inputs.network }} ${{ inputs.stage }} (${{ github.run_id }})'
43+
GHA_BOT_NAME: 'GitHub Actions Bot'
44+
GHA_BOT_EMAIL: 'github-actions[bot]@users.noreply.github.com'
45+
4046
steps:
47+
- name: Validate target environment
48+
id: validate-env
49+
if: inputs.network != 'hardhat'
50+
env:
51+
NETWORK: ${{ inputs.network }}
52+
STAGE: ${{ inputs.stage }}
53+
run: |
54+
DEPLOYMENT_ID=""
55+
case "$NETWORK" in
56+
arbitrum|bellecour)
57+
if [ "$STAGE" = "dev" ]; then
58+
echo "Error: Cannot use 'dev' stage with mainnet ($NETWORK)"
59+
exit 1
60+
fi
61+
# Use <network> as deployment id for mainnets.
62+
DEPLOYMENT_ID="${{ inputs.network }}"
63+
;;
64+
*)
65+
# Use <network>-<stage> as deployment id for testnets.
66+
DEPLOYMENT_ID="${{ inputs.network }}-${{ inputs.stage }}"
67+
;;
68+
esac
69+
echo "deployment-id=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT
70+
4171
- uses: actions/checkout@v4
4272
with:
4373
fetch-depth: 0
@@ -58,74 +88,52 @@ jobs:
5888
version: stable
5989
cache: true
6090

61-
- name: Validate deployment environment and prepare variables
62-
if: inputs.network != 'hardhat'
63-
run: |
64-
NETWORK="${{ inputs.network }}"
65-
ENVIRONMENT="${{ inputs.environment }}"
66-
67-
case "$NETWORK" in
68-
arbitrum|bellecour)
69-
if [ "$ENVIRONMENT" = "dev" ]; then
70-
echo "Error: Cannot deploy to mainnet ($NETWORK) with dev environment"
71-
exit 1
72-
fi
73-
echo "IS_MAINNET=true" >> $GITHUB_ENV
74-
;;
75-
*)
76-
echo "IS_MAINNET=false" >> $GITHUB_ENV
77-
;;
78-
esac
79-
8091
- name: Deploy contracts
81-
id: deploy
8292
working-directory: packages/sharing-smart-contract
8393
env:
84-
# For Deployment
94+
DEPLOYMENT_ID: ${{ steps.validate-env.outputs.deployment-id }}
8595
RPC_URL: ${{ secrets.RPC_URL }}
8696
DEPLOYER_PRIVATE_KEY: ${{ secrets.DEPLOYER_PRIVATE_KEY }}
87-
ADMIN_PRIVATE_KEY: ${{ secrets.DATAPROTECTOR_OWNER_PRIVATEKEY }} # Fix secret name
97+
ADMIN_PRIVATE_KEY: ${{ secrets.DATAPROTECTOR_OWNER_PRIVATEKEY }} # TODO Fix secret name
8898
POCO_ADDRESS: ${{ vars.POCO_ADDRESS }}
8999
DATASET_REGISTRY_ADDRESS: ${{ vars.DATASET_REGISTRY_ADDRESS }}
90100
run: |
91-
if [ "${{ inputs.network }}" = "hardhat" ]; then
92-
npm run deploy -- --network ${{ inputs.network }}
93-
else
94-
# For testnets, use network-environment; for mainnets, use network only
95-
if [ "$IS_MAINNET" = false ]; then
96-
DEPLOYMENT_ID="${{ inputs.network }}-${{ inputs.environment }}"
97-
else
98-
DEPLOYMENT_ID="${{ inputs.network }}"
99-
fi
100-
echo "deployment-id=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT
101101
DEPLOYMENT_ID="$DEPLOYMENT_ID" \
102102
npm run deploy -- --network ${{ inputs.network }}
103-
fi
104103
105-
- name: Save deployment artifacts
106-
if: inputs.network != 'hardhat'
104+
- name: Push deployment artifacts to the current branch
105+
if: inputs.network != 'hardhat' && github.ref != 'refs/heads/main'
107106
uses: stefanzweifel/git-auto-commit-action@v5
108107
with:
109-
commit_message: 'chore: save deployment artifacts for ${{ inputs.network }} ${{ inputs.environment }} (${{ github.run_id }})'
110-
file_pattern: 'packages/sharing-smart-contract/ignition/deployments/* packages/sharing-smart-contract/.openzeppelin/*'
111-
commit_user_name: 'GitHub Actions Bot'
112-
commit_user_email: 'github-actions[bot]@users.noreply.github.com'
113-
commit_author: 'GitHub Actions Bot <github-actions[bot]@users.noreply.github.com>'
108+
commit_message: ${{ env.COMMIT_MESSAGE }}
109+
file_pattern: |
110+
packages/sharing-smart-contract/ignition/deployments/*
111+
packages/sharing-smart-contract/.openzeppelin/*
112+
commit_user_name: ${{ env.GHA_BOT_NAME }}
113+
commit_user_email: ${{ env.GHA_BOT_EMAIL }}
114+
commit_author: '${{ env.GHA_BOT_NAME }} <${{ env.GHA_BOT_EMAIL }}>'
115+
116+
# Since `main` branch is protected, create a PR to push deployment files.
117+
- name: Push deployment artifacts through a pull request
118+
if: inputs.network != 'hardhat' && github.ref == 'refs/heads/main'
119+
uses: peter-evans/create-pull-request@v7
120+
with:
121+
commit-message: ${{ env.COMMIT_MESSAGE }}
122+
add-paths: |
123+
packages/sharing-smart-contract/ignition/deployments/
124+
packages/sharing-smart-contract/.openzeppelin/
125+
committer: '${{ env.GHA_BOT_NAME }} <${{ env.GHA_BOT_EMAIL }}>'
126+
author: '${{ env.GHA_BOT_NAME }} <${{ env.GHA_BOT_EMAIL }}>'
127+
branch: chore/save-deployment-artifacts
128+
title: ${{ env.COMMIT_MESSAGE }}
129+
body: 'PR created by "Create Pull Request" action.'
130+
draft: true
114131

115132
- name: Verify contracts
116133
if: inputs.network != 'hardhat'
117134
continue-on-error: true
118135
working-directory: packages/sharing-smart-contract
119136
env:
120-
# For Verification
121137
EXPLORER_API_KEY: ${{ secrets.EXPLORER_API_KEY }}
122138
IS_VERIFICATION_API_V2: ${{ vars.IS_VERIFICATION_API_V2 }}
123-
run: |
124-
# For testnets, use network-environment; for mainnets, use network only
125-
if [ "$IS_MAINNET" = false ]; then
126-
DEPLOYMENT_ID="${{ inputs.network }}-${{ inputs.environment }}"
127-
else
128-
DEPLOYMENT_ID="${{ inputs.network }}"
129-
fi
130-
npm run verify -- "$DEPLOYMENT_ID"
131-
139+
run: npm run verify -- "$DEPLOYMENT_ID"

.github/workflows/sharing-smart-contracts-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ jobs:
8989
- name: Upgrade test
9090
working-directory: packages/sharing-smart-contract
9191
env:
92-
DATA_PROTECTOR_SHARING_ADDRESS: 0x1390c3c6a545198809F1C7c5Dd2600ef74D60925
93-
ADD_ONLY_APP_WHITELIST_REGISTRY_ADDRESS: 0x498D324F711b8998Be81818742e268dEE30347c6
92+
DATA_PROTECTOR_SHARING_ADDRESS: '0x1390c3c6a545198809F1C7c5Dd2600ef74D60925'
93+
ADD_ONLY_APP_WHITELIST_REGISTRY_ADDRESS: '0x498D324F711b8998Be81818742e268dEE30347c6'
9494
run: npm run upgrade-local-fork -- --network local-bellecour-fork
9595

9696
# TODO check why the CI does not fail when the following error occurs

0 commit comments

Comments
 (0)