|
| 1 | +--- |
| 2 | +name: contracts-e2e-tests-and-deploy |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + |
| 7 | +# DO NOT TOUCH THIS: |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }} |
| 10 | + cancel-in-progress: false |
| 11 | + |
| 12 | +env: |
| 13 | + CACHE_KEY: fe-benjamin-button |
| 14 | + CONTRACTS_ENVFILE: fe-benjamin |
| 15 | + NODE_VERSION: 16 |
| 16 | + S3BUCKET_PATH: contracts/fe-benjamin-button |
| 17 | + |
| 18 | +jobs: |
| 19 | + build_and_deploy_contracts: |
| 20 | + name: Deploy contracts on feature environment |
| 21 | + if: > |
| 22 | + (github.event_name == 'push' && github.ref_name == 'benjamin') || |
| 23 | + (github.event_name == 'pull_request' && |
| 24 | + github.event.action == 'labeled' && |
| 25 | + github.event.label.name == '[AZERO] DEPLOY-CONTRACTS') |
| 26 | + runs-on: ubuntu-20.04 |
| 27 | + steps: |
| 28 | + - name: Checkout repo |
| 29 | + |
| 30 | + |
| 31 | + - name: Check if environment is reachable |
| 32 | + shell: bash |
| 33 | + run: | |
| 34 | + source contracts/env/${{ env.CONTRACTS_ENVFILE }} && \ |
| 35 | + HOSTPORT=${NODE/wss:\/\//} && nc -zvw5 ${HOSTPORT/:*/} ${HOSTPORT/*:/} |
| 36 | +
|
| 37 | + - name: Get branch name and commit SHA |
| 38 | + id: get_branch |
| 39 | + uses: ./.github/actions/get-branch |
| 40 | + |
| 41 | + # Use of 'actions-rs/toolchain@v1' has been removed as it was causing some unknown problems |
| 42 | + # Also, there is a ticket to replace it with custom solution anyway |
| 43 | + |
| 44 | + - name: Setup rust toolchain |
| 45 | + run: | |
| 46 | + . "$HOME/.cargo/env" |
| 47 | + rustup target add wasm32-unknown-unknown |
| 48 | + rustup toolchain install nightly-2022-08-12-x86_64-unknown-linux-gnu |
| 49 | + rustup component add rust-src --toolchain nightly-2022-08-12-x86_64-unknown-linux-gnu |
| 50 | + rustup default nightly-2022-08-12-x86_64-unknown-linux-gnu |
| 51 | +
|
| 52 | + - name: Install jq |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + sudo apt-get install -y jq |
| 56 | +
|
| 57 | + - name: Install binaryen |
| 58 | + shell: bash |
| 59 | + # yamllint disable rule:line-length |
| 60 | + run: | |
| 61 | + wget https://github.com/WebAssembly/binaryen/releases/download/version_110/binaryen-version_110-x86_64-linux.tar.gz \ |
| 62 | + -O /tmp/binaryen-version_110-x86_64-linux.tar.gz |
| 63 | + tar -zxvf /tmp/binaryen-version_110-x86_64-linux.tar.gz -C /tmp |
| 64 | + sudo chmod +x /tmp/binaryen-version_110/bin/* |
| 65 | + sudo cp -rf /tmp/binaryen-version_110/* /usr/ |
| 66 | + # yamllint enable rule:line-length |
| 67 | + |
| 68 | + - name: Install node |
| 69 | + uses: actions/setup-node@v3 |
| 70 | + with: |
| 71 | + node-version: ${{ env.NODE_VERSION }} |
| 72 | + |
| 73 | + - name: Restore cache |
| 74 | + uses: ./.github/actions/restore-cache |
| 75 | + with: |
| 76 | + target-key: ${{ env.CACHE_KEY }} |
| 77 | + cargo-key: ${{ env.CACHE_KEY }} |
| 78 | + cache-version: v3 |
| 79 | + cargo-targets: | |
| 80 | + contracts/access_control/target/ |
| 81 | + contracts/button/target/ |
| 82 | + contracts/game_token/target/ |
| 83 | + contracts/marketplace/target/ |
| 84 | + contracts/simple_dex/target/ |
| 85 | + contracts/ticket_token/target/ |
| 86 | + contracts/wrapped_azero/target/ |
| 87 | +
|
| 88 | + - name: Install cargo additional libs |
| 89 | + run: | |
| 90 | + . "$HOME/.cargo/env" |
| 91 | + cargo install dylint-link cargo-dylint |
| 92 | +
|
| 93 | + - name: Install cargo-contract |
| 94 | + uses: baptiste0928/cargo-install@v1 |
| 95 | + with: |
| 96 | + crate: cargo-contract |
| 97 | + version: "2.0.1" |
| 98 | + |
| 99 | + - name: Configure AWS credentials |
| 100 | + uses: aws-actions/configure-aws-credentials@v1 |
| 101 | + env: |
| 102 | + AWS_REGION: us-east-1 |
| 103 | + with: |
| 104 | + aws-access-key-id: ${{ secrets.AWS_DEVNET_ACCESS_KEY_ID }} |
| 105 | + aws-secret-access-key: ${{ secrets.AWS_DEVNET_SECRET_ACCESS_KEY }} |
| 106 | + aws-region: ${{ env.AWS_REGION }} |
| 107 | + |
| 108 | + - name: Copy addresses.json file from S3 bucket |
| 109 | + shell: bash |
| 110 | + # yamllint disable rule:line-length |
| 111 | + run: | |
| 112 | + aws s3 cp s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/addresses.json contracts/addresses.json |
| 113 | + # yamllint enable rule:line-length |
| 114 | + |
| 115 | + - name: Copy metadata.json files from S3 bucket |
| 116 | + shell: bash |
| 117 | + env: |
| 118 | + DOWNLOAD_TMP_DIR: downloaded_metadata |
| 119 | + run: | |
| 120 | + mkdir -p $DOWNLOAD_TMP_DIR |
| 121 | + aws s3 sync --exclude '*' --include '*metadata.json' \ |
| 122 | + s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/ ./$DOWNLOAD_TMP_DIR/ |
| 123 | + for i in `find $DOWNLOAD_TMP_DIR -name "metadata.json" | awk -F/ '{print $2}'`; do \ |
| 124 | + mkdir -p contracts/$i/target/ink; \ |
| 125 | + cp $DOWNLOAD_TMP_DIR/$i/metadata.json contracts/$i/target/ink/metadata.json; \ |
| 126 | + done |
| 127 | +
|
| 128 | + - name: Run clean.sh script |
| 129 | + shell: bash |
| 130 | + run: | |
| 131 | + . "$HOME/.cargo/env" |
| 132 | + source contracts/env/${{ env.CONTRACTS_ENVFILE }} && ./contracts/scripts/clean.sh |
| 133 | +
|
| 134 | + - name: Run deploy.sh script |
| 135 | + shell: bash |
| 136 | + run: | |
| 137 | + . "$HOME/.cargo/env" |
| 138 | + source contracts/env/${{ env.CONTRACTS_ENVFILE }} && ./contracts/scripts/deploy.sh |
| 139 | +
|
| 140 | + - name: Copy metadata.json and addresses.json files onto S3 bucket |
| 141 | + shell: bash |
| 142 | + run: | |
| 143 | + aws s3 cp contracts/addresses.json \ |
| 144 | + s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/addresses.json |
| 145 | +
|
| 146 | + for i in `find contracts -name "metadata.json" | awk -F/ '{print $2}'`; do \ |
| 147 | + aws s3 cp contracts/"$i"/target/ink/metadata.json \ |
| 148 | + s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/"$i"/metadata.json; \ |
| 149 | + done |
| 150 | +
|
| 151 | + echo -n "${{ steps.get_branch.outputs.sha_short }}" > commit_sha.txt |
| 152 | +
|
| 153 | + aws s3 cp commit_sha.txt \ |
| 154 | + s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/commit_sha.txt |
| 155 | +
|
| 156 | + source contracts/env/${{ env.CONTRACTS_ENVFILE }} && echo -n "$NODE" > env_NODE.txt |
| 157 | + aws s3 cp env_NODE.txt \ |
| 158 | + s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/env_NODE.txt |
| 159 | +
|
| 160 | + - name: Rename metadata and addresses JSON files to artifact upload |
| 161 | + shell: bash |
| 162 | + run: | |
| 163 | + cp contracts/addresses.json addresses.${{ env.CONTRACTS_ENVFILE }}.json |
| 164 | + for i in `find contracts -name "metadata.json" | awk -F/ '{print $2}'`; do \ |
| 165 | + cp contracts/"$i"/target/ink/metadata.json \ |
| 166 | + metadata_"$i".${{ env.CONTRACTS_ENVFILE }}.json; \ |
| 167 | + done |
| 168 | +
|
| 169 | + - name: Upload artifact with contract addresses |
| 170 | + uses: actions/upload-artifact@v3 |
| 171 | + with: |
| 172 | + name: contracts-addresses |
| 173 | + path: addresses.${{ env.CONTRACTS_ENVFILE }}.json |
| 174 | + if-no-files-found: error |
| 175 | + retention-days: 90 |
| 176 | + |
| 177 | + - name: Upload artifact with contract metadata |
| 178 | + uses: actions/upload-artifact@v3 |
| 179 | + with: |
| 180 | + name: contracts-metadata |
| 181 | + path: metadata_*.${{ env.CONTRACTS_ENVFILE }}.json |
| 182 | + if-no-files-found: error |
| 183 | + retention-days: 90 |
| 184 | + |
| 185 | + - name: Remove deploy label if present |
| 186 | + uses: actions-ecosystem/[email protected] |
| 187 | + if: > |
| 188 | + github.event_name == 'pull_request' && |
| 189 | + contains( github.event.pull_request.labels.*.name, '[AZERO] DEPLOY-CONTRACTS') |
| 190 | + with: |
| 191 | + labels: '[AZERO] DEPLOY-CONTRACTS' |
| 192 | + github_token: ${{ secrets.CI_GH_TOKEN }} |
| 193 | + |
| 194 | + - name: Add label to mark that contracts have been deployed |
| 195 | + if: github.event_name == 'pull_request' |
| 196 | + uses: actions-ecosystem/[email protected] |
| 197 | + with: |
| 198 | + labels: 'DEPLOYED-CONTRACTS' |
| 199 | + github_token: ${{ secrets.CI_GH_TOKEN }} |
| 200 | + |
| 201 | + - name: Cleanup cache |
| 202 | + uses: ./.github/actions/post-cache |
| 203 | + |
| 204 | + - name: GIT | Checkout aleph-apps repo |
| 205 | + uses: actions/checkout@master |
| 206 | + with: |
| 207 | + repository: Cardinal-Cryptography/aleph-apps |
| 208 | + token: ${{ secrets.CI_GH_TOKEN }} |
| 209 | + path: "aleph-apps" |
| 210 | + ref: main |
| 211 | + |
| 212 | + - name: KUSTOMIZE | Init kustomize |
| 213 | + uses: imranismail/setup-kustomize@v1 |
| 214 | + with: |
| 215 | + kustomize-version: '3.8.6' |
| 216 | + |
| 217 | + - name: KUBECTL | Setup kubectl |
| 218 | + |
| 219 | + with: |
| 220 | + version: 'v1.23.6' |
| 221 | + |
| 222 | + - name: INDEXER | Destroy archive and squid apps |
| 223 | + shell: bash |
| 224 | + run: | |
| 225 | + aws eks --region eu-central-1 update-kubeconfig --name alephzero-devnet-eu-central-1-eks |
| 226 | + kubectl delete -n indexer-squid --ignore-not-found=true deploy squid-api |
| 227 | + kubectl delete -n indexer-squid --ignore-not-found=true deploy squid-processor |
| 228 | + kubectl delete -n indexer-archive --ignore-not-found=true deploy archive-gateway |
| 229 | + kubectl delete -n indexer-archive --ignore-not-found=true deploy archive-ingest |
| 230 | +
|
| 231 | + - name: INDEXER | Create archive db and archive apps |
| 232 | + shell: bash |
| 233 | + run: | |
| 234 | + kubectl rollout restart statefulset archive-db -n indexer-archive |
| 235 | + kubectl rollout status --watch --timeout=600s -n indexer-archive statefulset/archive-db |
| 236 | + cd aleph-apps/indexer/archive/overlays/devnet/eu-central-1 |
| 237 | + kustomize build . | kubectl apply -f - |
| 238 | + sleep 3 |
| 239 | + kubectl rollout status --watch --timeout=600s -n indexer-archive deploy/archive-ingest |
| 240 | + kubectl rollout status --watch --timeout=600s -n indexer-archive deploy/archive-gateway |
| 241 | +
|
| 242 | + - name: INDEXER | Create squid db and squid apps |
| 243 | + shell: bash |
| 244 | + run: | |
| 245 | + kubectl rollout restart statefulset squid-db -n indexer-squid |
| 246 | + kubectl rollout status --watch --timeout=600s -n indexer-squid statefulset/squid-db |
| 247 | + cd aleph-apps/indexer/squid/overlays/devnet/eu-central-1 |
| 248 | + kustomize build . | kubectl apply -f - |
| 249 | + sleep 3 |
| 250 | + kubectl rollout status --watch --timeout=600s -n indexer-squid deploy/squid-processor |
| 251 | + kubectl rollout status --watch --timeout=600s -n indexer-squid deploy/squid-api |
| 252 | +
|
| 253 | + - name: BUTTON | Restart the-button deployment |
| 254 | + shell: bash |
| 255 | + run: | |
| 256 | + kubectl rollout restart deployment the-button -n the-button |
| 257 | + kubectl rollout status --watch --timeout=600s -n the-button deploy/the-button |
0 commit comments