Skip to content

Commit

Permalink
split deployed layout job to parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Nov 27, 2024
1 parent df267d6 commit 8bf4f1c
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 70 deletions.
181 changes: 118 additions & 63 deletions .github/workflows/compare-layouts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ jobs:
outputs:
number: ${{ steps.pr-context.outputs.number }}
steps:
# Log the workflow trigger details for debugging.
- name: Echo workflow trigger details
run: |
echo "Workflow run event: ${{ github.event.workflow_run.event }}"
echo "Workflow run conclusion: ${{ github.event.workflow_run.conclusion }}"
echo "Workflow run name: ${{ github.event.workflow_run.name }}"
echo "Workflow run URL: ${{ github.event.workflow_run.html_url }}"
echo "Commit SHA: ${{ github.event.workflow_run.head_commit.id }}"
echo "Workflow Run ID: ${{ github.event.workflow_run.id }}"
- name: Set commit status
# trigger is no matter what, because the status should be updated
if: always()
Expand Down Expand Up @@ -85,89 +94,135 @@ jobs:
# Skip the setup job if the parent job failed.
skip-install: ${{ github.event.workflow_run.conclusion != 'success' }}

create-deployed-layouts-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
steps:
- name: Echo a message
run: echo "Creating the matrix for deployed layouts."
- name: Checkout code
uses: actions/checkout@v4
if: ${{ github.event.workflow_run.conclusion == 'success' }}
- name: Generate matrix from deployedContracts.json
id: generate-matrix
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: |
set -e
data=$(cat script/deployedContracts.json)
bootstrap=$(echo "$data" | jq -r '.clientChain.bootstrapLogic // empty')
clientGateway=$(echo "$data" | jq -r '.clientChain.clientGatewayLogic // empty')
vault=$(echo "$data" | jq -r '.clientChain.vaultImplementation // empty')
rewardVault=$(echo "$data" | jq -r '.clientChain.rewardVaultImplementation // empty')
capsule=$(echo "$data" | jq -r '.clientChain.capsuleImplementation // empty')
# Create the matrix as a JSON array
matrix=$(jq -n \
--arg bootstrap "$bootstrap" \
--arg clientGateway "$clientGateway" \
--arg vault "$vault" \
--arg rewardVault "$rewardVault" \
--arg capsule "$capsule" \
'[{name: "Bootstrap", address: $bootstrap},
{name: "ClientChainGateway", address: $clientGateway},
{name: "Vault", address: $vault},
{name: "RewardVault", address: $rewardVault},
{name: "ExoCapsule", address: $capsule}] | map(select(.address != ""))')
echo "Matrix: $matrix"
echo "matrix=$matrix" >> "${GITHUB_OUTPUT}"
fetch-deployed-layouts:
timeout-minutes: 30
strategy:
matrix:
# if the parent workflow failed, the matrix will be empty. hence, no jobs will run.
contract: ${{ fromJSON(needs.create-deployed-layouts-matrix.outputs.matrix) }}
needs:
- setup
- create-deployed-layouts-matrix
runs-on: ubuntu-latest
steps:
- name: Restore cached Foundry toolchain
uses: actions/cache/restore@v3
with:
path: ${{ needs.setup.outputs.installation-dir }}
key: ${{ needs.setup.outputs.cache-key }}
- name: Add Foundry to PATH
run: echo "${{ needs.setup.outputs.installation-dir }}" >> "$GITHUB_PATH"
- name: Fetch the deployed layout
env:
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
run: |
echo "Processing ${{ matrix.contract.name }} at address ${{ matrix.contract.address }}"
RPC_URL="https://eth-sepolia.g.alchemy.com/v2/$ALCHEMY_API_KEY"
cast storage --json "${{ matrix.contract.address }}" \
--rpc-url "$RPC_URL" \
--etherscan-api-key "$ETHERSCAN_API_KEY" > "${{ matrix.contract.name }}.deployed.json"
- name: Upload the deployed layout file as an artifact
uses: actions/upload-artifact@v4
with:
path: ${{ matrix.contract.name }}.deployed.json
name: deployed-layout-${{ matrix.contract.name }}-${{ github.event.workflow_run.head_commit.id }}

combine-deployed-layouts:
needs: fetch-deployed-layouts
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Echo a message
run: echo "Combining the deployed layouts."
- name: Download artifacts
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/download-artifact@v4
with:
path: combined
- name: Zip up the deployed layouts
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: zip -j deployed-layouts.zip combined/*/*.json
- name: Upload the deployed layout files as an artifact
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/upload-artifact@v4
with:
path: deployed-layouts.zip
name: deployed-layouts-${{ github.event.workflow_run.head_commit.id }}

# The actual job to compare the storage layouts.
compare-storage-layouts:
# Typically takes no more than 7 minutes
timeout-minutes: 30
needs:
- setup
- set-commit-status
- combine-deployed-layouts
runs-on: ubuntu-latest

env:
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}

steps:
# Log the workflow trigger details for debugging.
- name: Echo workflow trigger details
run: |
echo "Workflow run event: ${{ github.event.workflow_run.event }}"
echo "Workflow run conclusion: ${{ github.event.workflow_run.conclusion }}"
echo "Workflow run name: ${{ github.event.workflow_run.name }}"
echo "Workflow run URL: ${{ github.event.workflow_run.html_url }}"
echo "Commit SHA: ${{ github.event.workflow_run.head_commit.id }}"
echo "Workflow Run ID: ${{ github.event.workflow_run.id }}"
# The repository needs to be available for script/deployedContracts.json
# and script/compareLayouts.js. We do not restore the build data because
# the compiled layouts are restored from the artifact and not rebuilt.
# and script/compareLayouts.js.
- name: Checkout the repository
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/checkout@v4
# The toolchain is needed to run `cast storage`
- name: Restore cached Foundry toolchain
- name: Restore the compiled layout files from the artifact
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/cache/restore@v3
uses: dawidd6/action-download-artifact@v6
with:
path: ${{ needs.setup.outputs.installation-dir }}
key: ${{ needs.setup.outputs.cache-key }}
- name: Add Foundry to PATH
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: echo "${{ needs.setup.outputs.installation-dir }}" >> "$GITHUB_PATH"
- name: Fetch the deployed layouts
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: |
set -e
data=$(cat script/deployedContracts.json)
bootstrap=$(echo "$data" | jq -r '.clientChain.bootstrapLogic // empty')
clientGateway=$(echo "$data" | jq -r '.clientChain.clientGatewayLogic // empty')
vault=$(echo "$data" | jq -r '.clientChain.vaultImplementation // empty')
rewardVault=$(echo "$data" | jq -r '.clientChain.rewardVaultImplementation // empty')
capsule=$(echo "$data" | jq -r '.clientChain.capsuleImplementation // empty')
pwd=$(pwd)
cd /tmp
# Create an array of contract names and addresses
declare -A contracts=(
["Bootstrap"]="$bootstrap"
["ClientChainGateway"]="$clientGateway"
["Vault"]="$vault"
["RewardVault"]="$rewardVault"
["ExoCapsule"]="$capsule"
)
# Iterate over the array and run `cast storage` for each contract
RPC_URL="https://eth-sepolia.g.alchemy.com/v2/$ALCHEMY_API_KEY"
for contract in "${!contracts[@]}"; do
address=${contracts[$contract]}
if [[ -n $address ]]; then
echo "Processing $contract at address $address"
cast storage --json "$address" --rpc-url "$RPC_URL" \
--etherscan-api-key "$ETHERSCAN_API_KEY" > "$contract.deployed.json"
mv "$contract.deployed.json" "$pwd"
else
echo "Skipping $contract as no address is provided"
fi
done
cd "$pwd"
# Restore the layouts from the previous job
- name: Restore the layout files from the artifact
name: compiled-layouts-${{ github.event.workflow_run.head_commit.id }}
run_id: ${{ github.event.workflow_run.id }}
- name: Restore the deployed layout files from the artifact
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: dawidd6/action-download-artifact@v6
with:
name: storage-layouts-${{ github.event.workflow_run.head_commit.id }}
run_id: ${{ github.event.workflow_run.id }}
- name: Extract the restored layouts
name: deployed-layouts-${{ github.event.workflow_run.head_commit.id }}
# no run_id is needed because the artifacts are from the same run
- name: Extract the restored compiled layouts
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: unzip compiled-layouts.zip
- name: Extract the restored deployed layouts
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: unzip storage-layouts.zip
run: unzip deployed-layouts.zip
- name: Set up Node.js
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/setup-node@v4
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/forge-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
path: ExocoreGateway.base.json
name: storage-layouts-ExocoreGateway-base-${{ github.event.pull_request.base.sha || github.event.after || github.sha }}
name: compiled-layout-ExocoreGateway-base-${{ github.event.pull_request.base.sha || github.event.after || github.sha }}

extract-storage-layouts:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -179,7 +179,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
path: ${{ matrix.contract }}.compiled.json
name: storage-layouts-${{ matrix.contract}}-${{ github.event.pull_request.head.sha || github.event.after || github.sha }}
name: compiled-layout-${{ matrix.contract}}-${{ github.event.pull_request.head.sha || github.event.after || github.sha }}

combine-storage-layouts:
runs-on: ubuntu-latest
Expand All @@ -195,10 +195,10 @@ jobs:
# inside the provided path.
with:
path: combined
- name: Zip up the storage layouts
run: zip -j storage-layouts.zip combined/*/*.json
- name: Upload storage layout file as an artifact
- name: Zip up the compiled layouts
run: zip -j compiled-layouts.zip combined/*/*.json
- name: Upload the compiled layouts file as an artifact
uses: actions/upload-artifact@v4
with:
path: storage-layouts.zip
name: storage-layouts-${{ github.event.pull_request.head.sha || github.event.after || github.sha }}
path: compiled-layouts.zip
name: compiled-layouts-${{ github.event.pull_request.head.sha || github.event.after || github.sha }}

0 comments on commit 8bf4f1c

Please sign in to comment.