Skip to content

Commit 236ec0d

Browse files
committed
feat: enhance deployment workflow with environment selection and Arbitrum support
1 parent cfb8651 commit 236ec0d

File tree

6 files changed

+95
-22
lines changed

6 files changed

+95
-22
lines changed

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

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,40 @@ on:
1414
- arbitrum
1515
- bellecour
1616
default: 'hardhat'
17+
environment:
18+
description: 'Environment'
19+
required: true
20+
type: choice
21+
options:
22+
- dev
23+
- prod
24+
default: 'dev'
25+
1726

1827
jobs:
19-
# Build and test before deploying.
2028
build-and-test:
2129
uses: ./.github/workflows/sharing-smart-contracts-ci.yml
2230
with:
2331
node-version: 20
2432

25-
# Deploy and verify contract.
2633
deploy:
2734
needs: build-and-test
2835
runs-on: ubuntu-latest
36+
env:
37+
CI: true
2938
permissions:
3039
contents: write # Required to commit deployment files.
3140
environment: ${{ inputs.network }}
3241
steps:
3342
- uses: actions/checkout@v4
3443
with:
35-
submodules: recursive
44+
fetch-depth: 0
3645

3746
- uses: actions/setup-node@v4
3847
with:
3948
node-version: 20
4049
cache: 'npm'
50+
cache-dependency-path: 'packages/sharing-smart-contract'
4151

4252
- name: Install dependencies
4353
working-directory: packages/sharing-smart-contract
@@ -49,23 +59,56 @@ jobs:
4959
version: stable
5060
cache: true
5161

62+
- name: Validate deployment environment and prepare variables
63+
if: inputs.network != 'hardhat'
64+
run: |
65+
NETWORK="${{ inputs.network }}"
66+
ENVIRONMENT="${{ inputs.environment }}"
67+
68+
case "$NETWORK" in
69+
arbitrum|bellecour)
70+
if [ "$ENVIRONMENT" = "dev" ]; then
71+
echo "Error: Cannot deploy to mainnet ($NETWORK) with dev environment"
72+
exit 1
73+
fi
74+
echo "IS_MAINNET=true" >> $GITHUB_ENV
75+
;;
76+
*)
77+
echo "IS_MAINNET=false" >> $GITHUB_ENV
78+
;;
79+
esac
80+
5281
- name: Deploy contracts
5382
working-directory: packages/sharing-smart-contract
5483
env:
5584
# For Deployment
5685
RPC_URL: ${{ secrets.RPC_URL }}
5786
DEPLOYER_PRIVATE_KEY: ${{ secrets.DEPLOYER_PRIVATE_KEY }}
58-
POCO_ADDRESS: ${{ env.POCO_ADDRESS }}
59-
DATASET_REGISTRY_ADDRESS: ${{ env.DATASET_REGISTRY_ADDRESS }}
87+
POCO_ADDRESS: ${{ vars.POCO_ADDRESS }}
88+
DATASET_REGISTRY_ADDRESS: ${{ vars.DATASET_REGISTRY_ADDRESS }}
6089
# For Verification
61-
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
62-
run: npm run deploy -- --network ${{ inputs.network }} --deployment-id ${{ inputs.network }} --verify
90+
EXPLORER_API_KEY: ${{ secrets.EXPLORER_API_KEY }}
91+
IS_VERIFICATION_API_V2: ${{ vars.IS_VERIFICATION_API_V2 }}
92+
run: |
93+
if [ "${{ inputs.network }}" = "hardhat" ]; then
94+
npm run deploy -- --network ${{ inputs.network }}
95+
else
96+
# For testnets, use network-environment; for mainnets, use network only
97+
if [ "$IS_MAINNET" = false ]; then
98+
DEPLOYMENT_ID="${{ inputs.network }}-${{ inputs.environment }}"
99+
else
100+
DEPLOYMENT_ID="${{ inputs.network }}"
101+
fi
102+
POCO_ADDRESS="${{ vars.POCO_ADDRESS }}" \
103+
DATASET_REGISTRY_ADDRESS="${{ vars.DATASET_REGISTRY_ADDRESS }}" \
104+
npm run deploy -- --network ${{ inputs.network }} --deployment-id "$DEPLOYMENT_ID" --verify
105+
fi
63106
64107
- name: Save deployment artifacts
65108
if: inputs.network != 'hardhat'
66109
uses: stefanzweifel/git-auto-commit-action@v5
67110
with:
68-
commit_message: 'chore: save deployment artifacts for ${{ inputs.network }} (${{ inputs.environment }}, ${{ github.run_id }})'
111+
commit_message: 'chore: save deployment artifacts for ${{ inputs.network }} ${{ inputs.environment }} (${{ github.run_id }})'
69112
file_pattern: 'packages/sharing-smart-contract/ignition/deployments/* packages/sharing-smart-contract/.openzeppelin/*'
70113
commit_user_name: 'GitHub Actions Bot'
71114
commit_user_email: 'github-actions[bot]@users.noreply.github.com'

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ on:
1010
inputs:
1111
node-version:
1212
description: Node.js version to use
13-
required: true
13+
required: false
1414
type: number
1515
default: 20
1616

17-
concurrency:
18-
group: ${{ github.ref }}-sharing-smart-contract-ci
19-
cancel-in-progress: true
20-
2117
jobs:
2218
build-and-test:
2319
runs-on: ubuntu-latest
@@ -52,7 +48,7 @@ jobs:
5248
working-directory: packages/sharing-smart-contract
5349
run: npm run check-format
5450

55-
- name: Lint
51+
- name: Check Lint
5652
working-directory: packages/sharing-smart-contract
5753
run: npm run lint
5854

packages/sharing-smart-contract/.env.template

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ RPC_URL=
1616
## Mnemonic for the network
1717
MNEMONIC=
1818

19-
ETHERSCAN_API_KEY=
19+
## API key to verify contracts
20+
EXPLORER_API_KEY=
21+
22+
## Whether to use API V2 verification format
23+
IS_VERIFICATION_API_V2=

packages/sharing-smart-contract/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
66

77
### Changed
88

9+
- CI fixes and add support for Arbitrum mainnet deployment (#)
910
- Deploy on testnet and save artifacts (#444, #445)
1011
- Deploy DPS contract using Github action (#443)
1112
- Refactor sharing contract CI to use reusable workflows (#442)

packages/sharing-smart-contract/config/env.cjs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const privateKeyRegex = /(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/;
99

1010
const envSchema = z.object({
1111
// Private key of the wallet used for transactions
12-
PRIVATE_KEY: z
12+
DEPLOYER_PRIVATE_KEY: z
1313
.string()
1414
.regex(privateKeyRegex, 'Invalid private key format')
1515
.optional()
@@ -45,7 +45,18 @@ const envSchema = z.object({
4545
.url('ARBITRUM_SEPOLIA_RPC_URL must be a valid URL')
4646
.optional(),
4747

48-
ETHERSCAN_API_KEY: z.string().optional(),
48+
// API key for contract verification
49+
EXPLORER_API_KEY: z.string().optional().or(z.literal('')),
50+
51+
// Whether to use API V2 verification format
52+
IS_VERIFICATION_API_V2: z
53+
.string()
54+
.optional()
55+
.default('true')
56+
.refine((val) => val === 'true' || val === 'false', {
57+
message: 'IS_VERIFICATION_API_V2 must be "true" or "false"',
58+
})
59+
.transform((val) => val === 'true'),
4960
});
5061

5162
module.exports = envSchema.parse(process.env);

packages/sharing-smart-contract/hardhat.config.cjs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ module.exports = {
5555
],
5656
blockGasLimit: 30_000_000,
5757
},
58+
arbitrum: {
59+
chainId: 42161,
60+
url: env.RPC_URL || 'https://arb1.arbitrum.io/rpc',
61+
accounts: env.DEPLOYER_PRIVATE_KEY ? [env.DEPLOYER_PRIVATE_KEY] : [],
62+
blockGasLimit: 30_000_000,
63+
},
5864
// poco-chain native config
5965
'dev-native': {
6066
chainId: 65535,
@@ -71,11 +77,14 @@ module.exports = {
7177
},
7278
// to verify smart-contract on Blockscout
7379
etherscan: {
74-
apiKey: {
75-
bellecour: 'nothing', // a non-empty string is needed by the plugin.
76-
avalancheFujiTestnet: 'nothing', // a non-empty string is needed by the plugin.
77-
arbitrumSepolia: env.ETHERSCAN_API_KEY || '',
78-
},
80+
apiKey: env.IS_VERIFICATION_API_V2
81+
? env.EXPLORER_API_KEY
82+
: {
83+
bellecour: env.EXPLORER_API_KEY || 'nothing', // a non-empty string is needed by the plugin.
84+
avalancheFujiTestnet: env.EXPLORER_API_KEY || 'nothing', // a non-empty string is needed by the plugin.
85+
arbitrumSepolia: env.EXPLORER_API_KEY || '',
86+
arbitrum: env.EXPLORER_API_KEY || '',
87+
},
7988
customChains: [
8089
{
8190
network: 'bellecour',
@@ -85,6 +94,15 @@ module.exports = {
8594
browserURL: 'https://blockscout.bellecour.iex.ec',
8695
},
8796
},
97+
{
98+
network: 'avalancheFujiTestnet',
99+
chainId: 43113,
100+
urls: {
101+
// Snowtrace explorer.
102+
apiURL: 'https://api.routescan.io/v2/network/testnet/evm/43113/etherscan/api',
103+
browserURL: 'https://testnet.snowtrace.io/',
104+
},
105+
},
88106
],
89107
},
90108
sourcify: {

0 commit comments

Comments
 (0)