From 81d050b3b0c06f3bc18fb40bc87a87798189b689 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Wed, 10 Jul 2024 09:53:33 +0200 Subject: [PATCH] refactor: update main workflow ci: restore deps in compile job ci: restore node_modules in tests job chore: format ci: debug ci: fix output name in if check ci: debug ci: debug ci: fix coveralls step chore: remove debug test: exclude some packages from coverage ci: debug ci: have slither job wait for compile ci: debug ci: debug --- .github/workflows/main.yml | 84 +++++++++++++++----------------------- .gitignore | 3 +- foundry.toml | 3 ++ package.json | 2 +- 4 files changed, 39 insertions(+), 53 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a6736f0..92da946 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,18 +37,18 @@ jobs: changed-files: runs-on: ubuntu-latest outputs: - any_changed: ${{ steps.changed-files.outputs.any_changed }} - modified_files: ${{ steps.changed-files.outputs.modified_files }} + any_sol_changed: ${{ steps.changed-files.outputs.any_changed }} + changed_files: ${{ steps.changed-files.outputs.all_changed_and_modified_files }} steps: - uses: actions/checkout@v4 - name: Get changed files id: changed-files uses: tj-actions/changed-files@v44 with: - files: packages/**/*.{sol,json,ts} + files: packages/**/*.sol compile: - if: needs.changed-files.outputs.any_changed == 'true' + if: needs.changed-files.outputs.any_sol_changed == 'true' needs: [changed-files, deps] runs-on: ubuntu-latest steps: @@ -56,18 +56,20 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 20 + # forge needs some deps coming from node_modules, so we need to restore it - uses: actions/cache/restore@v4 with: path: node_modules key: ${{ needs.deps.outputs.cache-key }} - - - run: yarn compile - + - uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + - run: forge compile - name: Upload compilation results uses: actions/upload-artifact@v4 with: - name: all-artifacts - path: packages/**/artifacts/** + name: out + path: out/** style: needs: deps @@ -77,6 +79,9 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 20 + - uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly - uses: actions/cache/restore@v4 with: path: node_modules @@ -84,43 +89,35 @@ jobs: - run: yarn format tests: - if: needs.changed-files.outputs.any_changed == 'true' - needs: [changed-files, set-matrix, deps, compile] + if: needs.changed-files.outputs.any_sol_changed == 'true' + needs: [changed-files, deps, compile] runs-on: ubuntu-latest - strategy: - matrix: - dir: ${{ fromJson(needs.set-matrix.outputs.matrix) }} - steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/download-artifact@v4 with: - node-version: 20 + name: out + path: out/ + # forge needs some deps coming from node_modules, so we need to restore it - uses: actions/cache/restore@v4 with: path: node_modules key: ${{ needs.deps.outputs.cache-key }} - - uses: actions/download-artifact@v4 + - uses: foundry-rs/foundry-toolchain@v1 with: - name: all-artifacts - path: packages/ + version: nightly - - if: contains(needs.changed-files.outputs.modified_files, matrix.dir) - name: Test - run: | - workspace=$(jq -r '.name' packages/${{ matrix.dir }}/package.json) - yarn workspace "$workspace" run test:coverage + - run: forge coverage --report lcov - - if: contains(needs.changed-files.outputs.modified_files, matrix.dir) && github.event_name == 'push' && github.ref == 'refs/heads/main' + - if: github.event_name == 'pull_request' && github.ref == 'refs/pull/32/merge' # TODO: switch back to push & refs/heads/main checks name: Coveralls uses: coverallsapp/github-action@v2 with: github-token: ${{ secrets.GITHUB_TOKEN }} - parallel: true - flag-name: run ${{ join(matrix.*, '-') }} + file: lcov.info set-matrix: - if: needs.changed-files.outputs.any_changed == 'true' + if: needs.changed-files.outputs.any_sol_changed == 'true' needs: changed-files runs-on: ubuntu-latest outputs: @@ -134,8 +131,8 @@ jobs: echo "matrix=$matrix" >> $GITHUB_OUTPUT slither: - if: needs.changed-files.outputs.any_changed == 'true' - needs: [changed-files, set-matrix, deps] + if: needs.changed-files.outputs.any_sol_changed == 'true' + needs: [changed-files, compile, set-matrix] runs-on: ubuntu-latest permissions: contents: read @@ -145,27 +142,12 @@ jobs: dir: ${{ fromJson(needs.set-matrix.outputs.matrix) }} steps: - uses: actions/checkout@v4 - - # FIXME this does not work as a way to restore compilation results for slither job but it does for the compile job ?? - #- uses: actions/download-artifact@v4 - # with: - # name: all-artifacts - # path: packages/ - - - uses: actions/setup-node@v4 - with: - node-version: 20 - - uses: actions/cache/restore@v4 + - uses: actions/download-artifact@v4 with: - path: node_modules - key: ${{ needs.deps.outputs.cache-key }} - - if: contains(needs.changed-files.outputs.modified_files, matrix.dir) - name: Compile contracts - run: | - workspace=$(jq -r '.name' packages/${{ matrix.dir }}/package.json) - yarn workspace "$workspace" run compile + name: out + path: out/ - - if: contains(needs.changed-files.outputs.modified_files, matrix.dir) + - if: contains(needs.changed-files.outputs.changed_files, matrix.dir) name: Run slither uses: crytic/slither-action@v0.4.0 id: slither @@ -177,7 +159,7 @@ jobs: slither-args: --filter-paths "test" --exclude-dependencies --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/ target: packages/${{ matrix.dir }} - - if: contains(needs.changed-files.outputs.modified_files, matrix.dir) + - if: contains(needs.changed-files.outputs.changed_files, matrix.dir) name: Upload SARIF files uses: github/codeql-action/upload-sarif@v3 with: diff --git a/.gitignore b/.gitignore index 1a87bb5..c106522 100644 --- a/.gitignore +++ b/.gitignore @@ -17,8 +17,9 @@ coverage.json # Dependency directories node_modules/ -# Forge build output +# Forge out +lcov.info # Hardhat artifacts diff --git a/foundry.toml b/foundry.toml index 699b6f5..9d0e2a3 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,3 +1,6 @@ [profile.default] src = 'packages' test = 'packages' + +# TODO: update, temporarily ignoring all except lean-imt +no_match_coverage = "^packages/(excubiae|imt|lazy-imt|lazytower)" diff --git a/package.json b/package.json index 4b2147f..fd6fdc1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "bugs": "https://github.com/privacy-scaling-explorations/zk-kit.solidity/issues", "private": true, "scripts": { - "test": "yarn workspaces foreach -Ap run test:coverage", + "test": "forge test", "version:bump": "yarn workspace @zk-kit/${0}.sol version ${1} && yarn remove:stable-version-field ${0} && NO_HOOK=1 git commit -am \"chore(${0}): v${1}\" && git tag ${0}.sol-v${1}", "version:publish": "yarn workspaces foreach -A --no-private npm publish --tolerate-republish --access public", "version:release": "changelogithub",