Skip to content

Commit e3655ff

Browse files
authored
doc: add ci-cd folder and add github-actions to the folder (#1326)
1 parent 2e37c3e commit e3655ff

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

src/ci-cd/github-actions.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Overview of `foundry-toolchain`
2+
3+
`foundry-toolchain` can be used to install Foundry for GitHub Actions build processes.
4+
5+
### Example workflow
6+
7+
```
8+
on: [push]
9+
10+
name: test
11+
12+
jobs:
13+
check:
14+
name: Foundry project
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
with:
19+
submodules: recursive
20+
21+
- name: Install Foundry
22+
uses: foundry-rs/foundry-toolchain@v1
23+
24+
- name: Run tests
25+
run: forge test -vvv
26+
27+
- name: Run snapshot
28+
run: forge snapshot
29+
```
30+
31+
### Inputs
32+
33+
| Name | Required | Default | Description | Type |
34+
|---|---|---|---|---|
35+
| cache | No | true | Whether to cache RPC responses or not. | bool |
36+
| version | No | nightly | Version to install, e.g. nightly or 1.8.8. Note: Foundry only has nightly builds for the time being. | string |
37+
| cache-key | No | `${{ github.job }}` | The cache key to use for caching. | string |
38+
| cache-restore-keys | No | `[${{ github.job }}]` | The cache keys to use for restoring the cache. | string[] |
39+
40+
### RPC Caching
41+
42+
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.
43+
44+
The logic of the caching is as follows:
45+
46+
- Always load the latest valid cache, and always create a new one with the updated cache.
47+
- When there are no changes to the fork tests, the cache does not change but the key does, since the key is based on the commit hash.
48+
- When the fork tests are changed, both the cache and the key are updated.
49+
50+
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:
51+
52+
```
53+
- name: Install Foundry
54+
uses: foundry-rs/foundry-toolchain@v1
55+
with:
56+
cache: false
57+
```
58+
59+
### Custom Cache Keys
60+
61+
You have the ability to define custom cache keys by utilizing the `cache-key` and `cache-restore-keys` inputs. This feature is particularly beneficial when you aim to tailor the cache-sharing strategy across multiple jobs. It is important to ensure that the cache-key is unique for each execution to prevent conflicts and guarantee successful cache saving.
62+
63+
For instance, if you wish to utilize a shared cache between two distinct jobs, the following configuration can be applied:
64+
65+
```
66+
- name: Install Foundry
67+
uses: foundry-rs/foundry-toolchain@v1
68+
with:
69+
cache-key: custom-seed-test-${{ github.sha }}
70+
cache-restore-keys: |-
71+
custom-seed-test-
72+
custom-seed-
73+
---
74+
- name: Install Foundry
75+
uses: foundry-rs/foundry-toolchain@v1
76+
with:
77+
cache-key: custom-seed-coverage-${{ github.sha }}
78+
cache-restore-keys: |-
79+
custom-seed-coverage-
80+
custom-seed-
81+
```
82+
83+
#### Deleting Caches
84+
85+
You can delete caches via the GitHub Actions user interface. Just go to your repo's "Actions" page:
86+
87+
`https://github.com/<OWNER>/<REPO>/actions/caches`
88+
89+
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.
90+
91+
#### Fuzzing
92+
93+
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).
94+
95+
### Summaries
96+
97+
You can add the output of Forge and Cast commands to GitHub step summaries. The summaries support GitHub flavored Markdown.
98+
99+
For example, to add the output of `forge snapshot` to a summary, you would change the snapshot step to:
100+
101+
```
102+
- name: Run snapshot
103+
run: NO_COLOR=1 forge snapshot >> $GITHUB_STEP_SUMMARY
104+
```

0 commit comments

Comments
 (0)