Skip to content

Commit

Permalink
add lint and update tests for solidity foundry gha (#11184)
Browse files Browse the repository at this point in the history
* add lint and update tests for solidity foundry gha

* fix typo

* fix typo

* refactor conditional into individual steps

* remove if statement for checkout repo and add comment
  • Loading branch information
momentmaker authored Nov 7, 2023
1 parent 5af9bca commit 647ce13
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/solidity-foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ jobs:
matrix:
product: [vrf, automation, llo-feeds, functions, shared]
needs: [changes]
if: needs.changes.outputs.changes == 'true'
name: Tests
name: Foundry Tests ${{ matrix.product }} ${{ fromJSON('["(skipped)", ""]')[needs.changes.outputs.changes == 'true'] }}
# See https://github.com/foundry-rs/foundry/issues/3827
runs-on: ubuntu-22.04

# The if statements for steps after checkout repo is workaround for
# passing required check for PRs that don't have filtered changes.
steps:
- name: Checkout the repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
Expand All @@ -49,15 +50,18 @@ jobs:
# and not native Foundry. This is to make sure the dependencies
# stay in sync.
- name: Setup NodeJS
if: needs.changes.outputs.changes == 'true'
uses: ./.github/actions/setup-nodejs

- name: Install Foundry
if: needs.changes.outputs.changes == 'true'
uses: foundry-rs/foundry-toolchain@v1
with:
# Has to match the `make foundry` version.
version: nightly-5be158ba6dc7c798a6f032026fe60fc01686b33b

- name: Run Forge build
if: needs.changes.outputs.changes == 'true'
run: |
forge --version
forge build
Expand All @@ -67,6 +71,7 @@ jobs:
FOUNDRY_PROFILE: ${{ matrix.product }}

- name: Run Forge tests
if: needs.changes.outputs.changes == 'true'
run: |
forge test -vvv
id: test
Expand All @@ -75,7 +80,7 @@ jobs:
FOUNDRY_PROFILE: ${{ matrix.product }}

- name: Run Forge snapshot
if: ${{ !contains(fromJson('["vrf"]'), matrix.product) && !contains(fromJson('["automation"]'), matrix.product) }}
if: ${{ !contains(fromJson('["vrf"]'), matrix.product) && !contains(fromJson('["automation"]'), matrix.product) && needs.changes.outputs.changes == 'true' }}
run: |
forge snapshot --nmt "testFuzz_\w{1,}?" --check gas-snapshots/${{ matrix.product }}.gas-snapshot
id: snapshot
Expand All @@ -84,7 +89,7 @@ jobs:
FOUNDRY_PROFILE: ${{ matrix.product }}

- name: Collect Metrics
if: always()
if: needs.changes.outputs.changes == 'true'
id: collect-gha-metrics
uses: smartcontractkit/push-gha-metrics-action@d1618b772a97fd87e6505de97b872ee0b1f1729a # v2.0.2
with:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/solidity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
src:
- 'contracts/**/*'
- '.github/workflows/solidity.yml'
- '.github/workflows/solidity-foundry.yml'
prepublish-test:
needs: [changes]
Expand Down Expand Up @@ -91,24 +92,29 @@ jobs:
this-job-name: Native Compilation
continue-on-error: true

# The if statements for steps after checkout repo is a workaround for
# passing required check for PRs that don't have filtered changes.
lint:
defaults:
run:
working-directory: contracts
needs: [changes]
if: needs.changes.outputs.changes == 'true'
name: Lint ${{ fromJSON('["(skipped)", ""]')[needs.changes.outputs.changes == 'true'] }}
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup NodeJS
if: needs.changes.outputs.changes == 'true'
uses: ./.github/actions/setup-nodejs
- name: Run pnpm lint
if: needs.changes.outputs.changes == 'true'
run: pnpm lint
- name: Run solhint
if: needs.changes.outputs.changes == 'true'
run: pnpm solhint
- name: Collect Metrics
if: needs.changes.outputs.changes == 'true'
id: collect-gha-metrics
uses: smartcontractkit/push-gha-metrics-action@d1618b772a97fd87e6505de97b872ee0b1f1729a # v2.0.2
with:
Expand Down

0 comments on commit 647ce13

Please sign in to comment.