Skip to content

Commit

Permalink
refactor: update main workflow
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sripwoud committed Jul 10, 2024
1 parent a4bd9d3 commit 81d050b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 53 deletions.
84 changes: 33 additions & 51 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,39 @@ 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:
- uses: actions/checkout@v4
- 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
Expand All @@ -77,50 +79,45 @@ 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
key: ${{ needs.deps.outputs.cache-key }}

- 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:
Expand All @@ -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
Expand All @@ -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/[email protected]
id: slither
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ coverage.json
# Dependency directories
node_modules/

# Forge build output
# Forge
out
lcov.info

# Hardhat
artifacts
Expand Down
3 changes: 3 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -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)"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 81d050b

Please sign in to comment.