|
| 1 | +name: Smart Contract Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: # Manually trigger the workflow OR trigger with tags or releases ? |
| 5 | + inputs: |
| 6 | + target: |
| 7 | + description: "Deployment target (smart-contract-deploy-dev, smart-contract-deploy-staging, smart-contract-deploy-prod)" |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - smart-contract-deploy-dev |
| 12 | + - smart-contract-deploy-staging |
| 13 | + - smart-contract-deploy-prod |
| 14 | + default: smart-contract-deploy-dev |
| 15 | + |
| 16 | +jobs: |
| 17 | + deploy: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: '18' |
| 25 | + |
| 26 | + - name: Install dependencies |
| 27 | + working-directory: packages/smart-contract |
| 28 | + run: | |
| 29 | + node -v |
| 30 | + npm -v |
| 31 | + npm ci |
| 32 | +
|
| 33 | + - name: Check code format |
| 34 | + working-directory: packages/smart-contract |
| 35 | + run: npm run check-format |
| 36 | + |
| 37 | + - name: Run lint |
| 38 | + working-directory: packages/smart-contract |
| 39 | + run: npm run lint |
| 40 | + |
| 41 | + - name: Compile smart contracts |
| 42 | + working-directory: packages/smart-contract |
| 43 | + run: npm run compile |
| 44 | + |
| 45 | + - name: Run tests |
| 46 | + working-directory: packages/smart-contract |
| 47 | + run: npm run test |
| 48 | + |
| 49 | + - name: Deploy to dev/staging |
| 50 | + if: ${{ (github.event.inputs.target == 'smart-contract-deploy-dev' || github.event.inputs.target == 'smart-contract-deploy-staging') && startsWith(github.ref, 'refs/heads/develop') }} |
| 51 | + working-directory: packages/smart-contract |
| 52 | + env: |
| 53 | + WALLET_PRIVATE_KEY: ${{ secrets.DEPLOYER_DEV_PRIVATEKEY }} |
| 54 | + run: npm run deploy -- --network bellecour |
| 55 | + |
| 56 | + - name: Deploy to prod |
| 57 | + if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' && github.ref == 'refs/heads/main' }} |
| 58 | + working-directory: packages/smart-contract |
| 59 | + env: |
| 60 | + WALLET_PRIVATE_KEY: ${{ secrets.DEPLOYER_PROD_PRIVATEKEY }} |
| 61 | + run: npm run deploy -- --network bellecour |
| 62 | + |
| 63 | + - name: Update production environment |
| 64 | + if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' }} |
| 65 | + working-directory: environments |
| 66 | + run: | |
| 67 | + KEY=dataprotectorContractAddress VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/address) npm run update-env |
| 68 | + KEY=dataprotectorStartBlock VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/block) npm run update-env |
| 69 | + git add environments.json |
| 70 | + git commit -m "Deployment ${{ github.event.inputs.target }} run ${{ github.run_number }} commit ${{ github.sha }}" --author="drone-product <[email protected]>" |
| 71 | +
|
| 72 | + - name: Update staging environment |
| 73 | + if: ${{ github.event.inputs.target == 'smart-contract-deploy-staging' }} |
| 74 | + working-directory: environments |
| 75 | + run: | |
| 76 | + KEY=dataprotectorContractAddress VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/address) npm run update-env |
| 77 | + KEY=dataprotectorStartBlock VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/block) npm run update-env |
| 78 | + git add environments.json |
| 79 | + git commit -m "Deployment ${{ github.event.inputs.target }} run ${{ github.run_number }} commit ${{ github.sha }}" --author="drone-product <[email protected]>" |
| 80 | +
|
| 81 | + - name: Git push environment update |
| 82 | + if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' || github.event.inputs.target == 'smart-contract-deploy-staging' }} |
| 83 | + run: | |
| 84 | + git push ssh://[email protected]/iExecBlockchainComputing/dataprotector-sdk.git update-env-${{ github.run_number }} |
| 85 | + env: |
| 86 | + # Configure the SSH key to secrets GitHub |
| 87 | + SSH_KEY: ${{ secrets.SSH_KEY_TEAM_PRODUCT_GITHUB_PUSH }} |
| 88 | + shell: bash |
| 89 | + |
| 90 | + - name: Verify contract |
| 91 | + working-directory: packages/smart-contract |
| 92 | + run: npm run verify -- --network bellecour $(cat deployments/DataProtector/address) $(cat deployments/DataProtector/args) |
0 commit comments