diff --git a/.github/workflows/core-contracts-storage-check.yml b/.github/workflows/core-contracts-storage-check.yml index 085e4d3bb..917e14e95 100644 --- a/.github/workflows/core-contracts-storage-check.yml +++ b/.github/workflows/core-contracts-storage-check.yml @@ -11,10 +11,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive - + - name: Install Foundry uses: onbjerg/foundry-toolchain@v1 with: @@ -35,10 +35,25 @@ jobs: env: CHANGED_CONTRACTS: ${{ steps.changed-contracts.outputs.contracts_all_changed_files }} run: | - for CONTRACT in "$CHANGED_CONTRACTS"; do - echo ${CONTRACT} | xargs basename -a | cut -d'.' -f1 | xargs -I{} echo src/dollar/core/{}.sol:{} >> contracts.txt + touch contracts.txt + + # Fetch the latest state of the development branch to compare + git fetch origin development + + # Iterate through changed contracts and check if they existed in the development branch + for CONTRACT in $CHANGED_CONTRACTS; do + if git show origin/development:$CONTRACT > /dev/null 2>&1; then + # If the contract existed in the development branch, add it to the list for storage check + echo ${CONTRACT} | xargs basename -a | cut -d'.' -f1 | xargs -I{} echo src/dollar/core/{}.sol:{} >> contracts.txt + else + echo "$CONTRACT is a new contract, skipping storage check." + fi done - echo "matrix=$(cat contracts.txt | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT + + # Set the matrix only if there are contracts to check + if [ -s contracts.txt ]; then + echo "matrix=$(cat contracts.txt | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT + fi outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} @@ -67,5 +82,4 @@ jobs: with: workingDirectory: packages/contracts contract: ${{ matrix.contract }} - failOnRemoval: true - + failOnRemoval: true \ No newline at end of file diff --git a/.github/workflows/diamond-storage-check.yml b/.github/workflows/diamond-storage-check.yml index d4f869098..0626adf5f 100644 --- a/.github/workflows/diamond-storage-check.yml +++ b/.github/workflows/diamond-storage-check.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive @@ -39,10 +39,25 @@ jobs: env: CHANGED_LIBS: ${{ steps.changed-libraries.outputs.libraries_all_changed_files }} run: | - for DIAMOND_LIB in "$CHANGED_LIBS"; do - echo ${DIAMOND_LIB} | xargs basename -a | cut -d'.' -f1 | xargs -I{} echo src/dollar/libraries/{}.sol:{} >> contracts.txt + touch contracts.txt + + # Fetch the latest state of the development branch to compare + git fetch origin development + + # Iterate through changed libraries and check if they existed in the development branch + for DIAMOND_LIB in $CHANGED_LIBS; do + if git show origin/development:$DIAMOND_LIB > /dev/null 2>&1; then + # If the library existed in the development branch, add it to the list for storage check + echo ${DIAMOND_LIB} | xargs basename -a | cut -d'.' -f1 | xargs -I{} echo src/dollar/libraries/{}.sol:{} >> contracts.txt + else + echo "$DIAMOND_LIB is a new library, skipping storage check." + fi done - echo "matrix=$(cat contracts.txt | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT + + # Set the matrix only if there are libraries to check + if [ -s contracts.txt ]; then + echo "matrix=$(cat contracts.txt | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT + fi outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} @@ -71,5 +86,4 @@ jobs: with: workingDirectory: packages/contracts contract: ${{ matrix.contract }} - failOnRemoval: true - failOnLabelDiff: true + failOnRemoval: true \ No newline at end of file diff --git a/.github/workflows/generate-storage-artifacts.yml b/.github/workflows/generate-storage-artifacts.yml new file mode 100644 index 000000000..35a78a680 --- /dev/null +++ b/.github/workflows/generate-storage-artifacts.yml @@ -0,0 +1,64 @@ +name: Generate Storage Artifacts + +on: + workflow_dispatch + +jobs: + provide_contracts: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install Foundry + uses: onbjerg/foundry-toolchain@v1 + with: + version: nightly + + - name: Set contracts matrix for all matching contracts + id: set-matrix + working-directory: packages/contracts + run: | + # Collect all contracts from core and libraries + CONTRACTS="$(find src/dollar/core/*.sol src/dollar/libraries/Lib*.sol -type f)" + + for CONTRACT in $CONTRACTS; do + # Extract the contract name without the .sol extension + CONTRACT_NAME=$(basename "$CONTRACT" .sol) + + # Write : to contracts.txt + echo "${CONTRACT}:${CONTRACT_NAME}" >> contracts.txt + done + + # Set the matrix output + echo "matrix=$(cat contracts.txt | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT + + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + + check_storage_layout: + needs: provide_contracts + runs-on: ubuntu-latest + if: ${{ needs.provide_contracts.outputs.matrix != '[]' && needs.provide_contracts.outputs.matrix != '' }} + + strategy: + matrix: + contract: ${{ fromJSON(needs.provide_contracts.outputs.matrix) }} + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Install Foundry + uses: onbjerg/foundry-toolchain@v1 + with: + version: nightly + + - name: Check For Core Contracts Storage Changes + uses: Rubilmax/foundry-storage-check@main + with: + workingDirectory: packages/contracts + contract: ${{ matrix.contract }} \ No newline at end of file