Skip to content

Commit cfb8651

Browse files
committed
Merge branch 'main' into fix/dataProtector-sharing-fix-ci
2 parents 5c95528 + 5ca5d6c commit cfb8651

File tree

6 files changed

+92
-40
lines changed

6 files changed

+92
-40
lines changed

.github/workflows/core-smart-contract-ci.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ 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 }}-core-smart-contract-ci
19+
cancel-in-progress: true
20+
1721
jobs:
18-
deploy:
22+
build-and-test:
1923
runs-on: ubuntu-latest
2024
steps:
2125
- uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
2228

2329
- uses: actions/setup-node@v4
2430
with:
2531
node-version: ${{ inputs.node-version }}
2632
cache: 'npm'
33+
cache-dependency-path: 'packages/smart-contract'
2734

2835
- name: Install dependencies
2936
working-directory: packages/smart-contract

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

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ 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'
1725

18-
concurrency:
19-
group: ${{ github.ref }}-core-smart-contract-ci
20-
cancel-in-progress: true
2126

2227
jobs:
2328
build-and-test:
@@ -26,19 +31,47 @@ jobs:
2631
node-version: 20
2732

2833
deploy:
34+
needs: build-and-test
2935
runs-on: ubuntu-latest
36+
env:
37+
CI: true
38+
permissions:
39+
contents: write # Required to commit deployment files.
40+
environment: ${{ inputs.network }}
3041
steps:
3142
- uses: actions/checkout@v4
43+
with:
44+
fetch-depth: 0
3245

3346
- uses: actions/setup-node@v4
3447
with:
3548
node-version: 20
3649
cache: 'npm'
50+
cache-dependency-path: 'packages/smart-contract'
3751

3852
- name: Install dependencies
3953
working-directory: packages/smart-contract
4054
run: npm ci
4155

56+
- name: Validate deployment environment and prepare variables
57+
if: inputs.network != 'hardhat'
58+
run: |
59+
NETWORK="${{ inputs.network }}"
60+
ENVIRONMENT="${{ inputs.environment }}"
61+
62+
case "$NETWORK" in
63+
arbitrum|bellecour)
64+
if [ "$ENVIRONMENT" = "dev" ]; then
65+
echo "Error: Cannot deploy to mainnet ($NETWORK) with dev environment"
66+
exit 1
67+
fi
68+
echo "IS_MAINNET=true" >> $GITHUB_ENV
69+
;;
70+
*)
71+
echo "IS_MAINNET=false" >> $GITHUB_ENV
72+
;;
73+
esac
74+
4275
- name: Deploy contract
4376
working-directory: packages/smart-contract
4477
env:
@@ -48,35 +81,26 @@ jobs:
4881
DATASET_REGISTRY_ADDRESS: ${{ vars.DATASET_REGISTRY_ADDRESS }}
4982
# For Verification
5083
EXPLORER_API_KEY: ${{ secrets.EXPLORER_API_KEY }}
51-
run: npm run deploy -- --network ${{ inputs.network }} --deployment-id ${{ inputs.network }} --verify
52-
53-
- name: Update production environment
54-
if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' }}
55-
working-directory: environments
56-
run: |
57-
ADDRESS=$(jq -r '.contractAddress' ../packages/smart-contract/ignition/deployments/chain-134/journal.jsonl)
58-
BLOCK=$(jq -r '.blockNumber' ../packages/smart-contract/ignition/deployments/chain-134/journal.jsonl)
59-
KEY=dataprotectorContractAddress VALUE=$ADDRESS npm run update-env
60-
KEY=dataprotectorStartBlock VALUE=$BLOCK npm run update-env
61-
git add environments.json
62-
git commit -m "Deployment ${{ github.event.inputs.target }} run ${{ github.run_number }} commit ${{ github.sha }}" --author="drone-product <[email protected]>"
63-
64-
- name: Update staging environment
65-
if: ${{ github.event.inputs.target == 'smart-contract-deploy-staging' }}
66-
working-directory: environments
84+
IS_VERIFICATION_API_V2: ${{ vars.IS_VERIFICATION_API_V2 }}
6785
run: |
68-
ADDRESS=$(jq -r '.contractAddress' ../packages/smart-contract/ignition/deployments/chain-134/journal.json)
69-
BLOCK=$(jq -r '.blockNumber' ../packages/smart-contract/ignition/deployments/chain-134/journal.json)
70-
KEY=dataprotectorContractAddress VALUE=$ADDRESS npm run update-env
71-
KEY=dataprotectorStartBlock VALUE=$BLOCK npm run update-env
72-
git add environments.json
73-
git commit -m "Deployment ${{ github.event.inputs.target }} run ${{ github.run_number }} commit ${{ github.sha }}" --author="drone-product <[email protected]>"
86+
if [ "${{ inputs.network }}" = "hardhat" ]; then
87+
npm run deploy -- --network ${{ inputs.network }}
88+
else
89+
# For testnets, use network-environment; for mainnets, use network only
90+
if [ "$IS_MAINNET" = false ]; then
91+
DEPLOYMENT_ID="${{ inputs.network }}-${{ inputs.environment }}"
92+
else
93+
DEPLOYMENT_ID="${{ inputs.network }}"
94+
fi
95+
npm run deploy -- --network ${{ inputs.network }} --deployment-id "$DEPLOYMENT_ID" --verify
96+
fi
7497
75-
- name: Git push environment update
76-
if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' || github.event.inputs.target == 'smart-contract-deploy-staging' }}
77-
run: |
78-
git push ssh://[email protected]/iExecBlockchainComputing/dataprotector-sdk.git update-env-${{ github.run_number }}
79-
env:
80-
# Configure the SSH key to secrets GitHub
81-
SSH_KEY: ${{ secrets.SSH_KEY_TEAM_PRODUCT_GITHUB_PUSH }}
82-
shell: bash
98+
- name: Save deployment artifacts
99+
if: inputs.network != 'hardhat'
100+
uses: stefanzweifel/git-auto-commit-action@v5
101+
with:
102+
commit_message: 'chore: save deployment artifacts for ${{ inputs.network }} ${{ inputs.environment }} (${{ github.run_id }})'
103+
file_pattern: 'packages/smart-contract/ignition/deployments/*'
104+
commit_user_name: 'GitHub Actions Bot'
105+
commit_user_email: 'github-actions[bot]@users.noreply.github.com'
106+
commit_author: 'GitHub Actions Bot <github-actions[bot]@users.noreply.github.com>'

packages/smart-contract/.env.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ MNEMONIC=
1212

1313
## API key to verify contracts
1414
EXPLORER_API_KEY=
15+
16+
## Whether to use API V2 verification format
17+
IS_VERIFICATION_API_V2=

packages/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
### Added
88

9+
- Fix CIs and Support for Arbitrum mainnet (#468)
910
- Support for Arbitrum and Avalanche Fuji testnets (#429).
1011

1112
### Changed

packages/smart-contract/config/env.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ const envSchema = z.object({
2727

2828
// Arbiscan API key
2929
EXPLORER_API_KEY: z.string().optional().or(z.literal('')),
30+
31+
// Whether to use API V2 verification format
32+
IS_VERIFICATION_API_V2: z
33+
.string()
34+
.optional()
35+
.default('true')
36+
.refine((val) => val === 'true' || val === 'false', {
37+
message: 'IS_VERIFICATION_API_V2 must be "true" or "false"',
38+
})
39+
.transform((val) => val === 'true'),
3040
});
3141

3242
export const env = envSchema.parse(process.env);

packages/smart-contract/hardhat.config.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ const config: HardhatUserConfig = {
3232
blockGasLimit: 30_000_000, // Arbitrum has higher block gas limits
3333
chainId: 421614,
3434
},
35+
arbitrum: {
36+
url: env.RPC_URL || 'https://arb1.arbitrum.io/rpc',
37+
accounts: privateKey ? [privateKey] : [],
38+
blockGasLimit: 30_000_000, // Arbitrum has higher block gas limits
39+
chainId: 42161,
40+
},
3541
// poco-chain native config
3642
'dev-native': {
3743
chainId: 65535,
@@ -44,11 +50,12 @@ const config: HardhatUserConfig = {
4450
},
4551
//to verify contract on Blockscout
4652
etherscan: {
47-
apiKey: {
48-
bellecour: 'nothing', // a non-empty string is needed by the plugin.
49-
avalancheFuji: 'nothing', // a non-empty string is needed by the plugin.
50-
arbitrumSepolia: env.EXPLORER_API_KEY || '',
51-
},
53+
apiKey: env.IS_VERIFICATION_API_V2
54+
? env.EXPLORER_API_KEY
55+
: {
56+
bellecour: env.EXPLORER_API_KEY || 'nothing', // a non-empty string is needed by the plugin.
57+
avalancheFuji: env.EXPLORER_API_KEY || 'nothing', // a non-empty string is needed by the plugin.
58+
},
5259
customChains: [
5360
{
5461
network: 'bellecour',

0 commit comments

Comments
 (0)