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
2227jobs :
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>'
0 commit comments