From 18623bbc28d39abfe9bb0b38143b77ec2f149ec1 Mon Sep 17 00:00:00 2001 From: zugdev Date: Fri, 4 Oct 2024 19:40:35 -0300 Subject: [PATCH] feat: fix storage check workflow to check against development branch --- .../core-contracts-storage-check.yml | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/.github/workflows/core-contracts-storage-check.yml b/.github/workflows/core-contracts-storage-check.yml index 93914729c..9f2af63c7 100644 --- a/.github/workflows/core-contracts-storage-check.yml +++ b/.github/workflows/core-contracts-storage-check.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - fetch-depth: 2 + fetch-depth: 2 # Ensure we can access the previous commit - name: Install Foundry uses: onbjerg/foundry-toolchain@v1 @@ -29,33 +29,32 @@ jobs: contracts: - packages/contracts/src/dollar/core/*.sol - - name: Remove newly added contracts from the list - id: filter-new-contracts + - name: Set contracts matrix + id: set-matrix + working-directory: packages/contracts + if: steps.changed-contracts.outputs.contracts_any_changed == 'true' + env: + CHANGED_CONTRACTS: ${{ steps.changed-contracts.outputs.contracts_all_changed_files }} run: | touch contracts.txt - CHANGED_CONTRACTS="${{ steps.changed-contracts.outputs.contracts_all_changed_files }}" - - # Iterate through changed contracts and check if they existed in the previous commit + + # 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 HEAD~1:$CONTRACT > /dev/null 2>&1; then - # If the contract existed in the previous commit, add it to the list + 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 - - name: Set contracts matrix - id: set-matrix - working-directory: packages/contracts - if: steps.changed-contracts.outputs.contracts_any_changed == 'true' - 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 - 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 }}