Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "cache" input for disabling rpc caching #25

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode
node_modules
43 changes: 36 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## `foundry-toolchain` Action

This GitHub Action installs [Foundry](https://github.com/foundry-rs/foundry), the blazing fast, portable and modular toolkit for Ethereum application development.
This GitHub Action installs [Foundry](https://github.com/foundry-rs/foundry), the blazing fast, portable and modular
toolkit for Ethereum application development.

### Example workflow

Expand Down Expand Up @@ -32,12 +33,13 @@ jobs:

| **Name** | **Required** | **Default** | **Description** | **Type** |
| --------- | ------------ | ----------- | ------------------------------------------------------------------------------------------------------------ | -------- |
| `cache` | No | `true` | Whether to cache RPC responses or not. | bool |
| `version` | No | `nightly` | Version to install, e.g. `nightly` or `1.0.0`. **Note:** Foundry only has nightly builds for the time being. | string |

### RPC Caching

This action matches Forge's behavior and caches all RPC responses in the `~/.foundry/cache/rpc` directory. This is done to
speed up the tests and avoid hitting the rate limit of your RPC provider.
By default, this action matches Forge's behavior and caches all RPC responses in the `~/.foundry/cache/rpc` directory.
This is done to speed up the tests and avoid hitting the rate limit of your RPC provider.

The logic of the caching is as follows:

Expand All @@ -46,15 +48,40 @@ The logic of the caching is as follows:
commit hash.
- When the fork tests are changed, both the cache and the key are updated.

If you would like to disable the caching (e.g. because you want to implement your own caching mechanism), you can set
the `cache` input to `false`, like this:

```yml
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
cache: false
```

#### Deleting Caches

You can delete caches via the GitHub Actions user interface. Just go to your repo's "Actions" page:

```text
https://github.com/<OWNER>/<REPO>/actions/caches
```

Then, locate the "Management" section, and click on "Caches". You will see a list of all of your current caches, which
you can delete by clicking on the trash icon.

For more detail on how to delete caches, read GitHub's docs on
[managing caches](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#managing-caches).

#### Fuzzing

Note that if you are fuzzing in your fork tests, the RPC cache strategy above will not work unless you set a
[fuzz seed](https://book.getfoundry.sh/reference/config/testing#seed). You might also want to reduce your number
of RPC calls by using [Multicall](https://github.com/mds1/multicall).
[fuzz seed](https://book.getfoundry.sh/reference/config/testing#seed). You might also want to reduce your number of RPC
calls by using [Multicall](https://github.com/mds1/multicall).

### Summaries

You can add the output of Forge and Cast commands to GitHub step summaries. The summaries support GitHub flavored Markdown.
You can add the output of Forge and Cast commands to GitHub step summaries. The summaries support GitHub flavored
Markdown.

For example, to add the output of `forge snapshot` to a summary, you would change the snapshot step to:

Expand All @@ -63,4 +90,6 @@ For example, to add the output of `forge snapshot` to a summary, you would chang
run: NO_COLOR=1 forge snapshot >> $GITHUB_STEP_SUMMARY
```

See the official [GitHub docs](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary) for more information.
See the official
[GitHub docs](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary)
for more information.
11 changes: 9 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ branding:
icon: "play-circle"

inputs:
cache:
default: "true"
description: |
Whether to cache RPC responses or not.

Caching is activated by default.
required: false
version:
default: "nightly"
description: |
Foundry version.

This version number has to match a released version of Foundry.
Alternatively you can also specify `nightly` for the latest nightly build.
The default value is `nightly`, which will pull the latest nightly build.
required: false

runs:
using: "node16"
main: "dist/index.js"
post: "dist/save/index.js"
post-if: "success()"
post-if: "github.event.inputs.cache && success()"
11 changes: 8 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68382,7 +68382,7 @@ const { getDownloadObject } = __nccwpck_require__(1608);

async function main() {
try {
// Get version
// Get version input
const version = core.getInput("version");

// Download tarball
Expand All @@ -68396,8 +68396,13 @@ async function main() {
// Expose the tool
core.addPath(path.join(pathToCLI, download.binPath));

// Restore the RPC cache, if any.
restoreRPCCache();
// Get cache input
const cache = core.getInput("cache");

if (cache) {
// Restore the RPC cache, if any.
restoreRPCCache();
}
} catch (err) {
core.setFailed(err);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { getDownloadObject } = require("./utils");

async function main() {
try {
// Get version
// Get version input
const version = core.getInput("version");

// Download tarball
Expand All @@ -21,8 +21,13 @@ async function main() {
// Expose the tool
core.addPath(path.join(pathToCLI, download.binPath));

// Restore the RPC cache, if any.
restoreRPCCache();
// Get cache input
const cache = core.getInput("cache");

if (cache) {
// Restore the RPC cache, if any.
restoreRPCCache();
}
} catch (err) {
core.setFailed(err);
}
Expand Down