Skip to content

Commit

Permalink
build(ci): merge workflows and use cache
Browse files Browse the repository at this point in the history
We now have a multi-job workflow, which means it will run the jobs in
parallel. Between jobs, we cache the artifacts generated by Foundry so
they can be reused. The artifacts cached are the result of compilation
by Foundry, and hence, they can be reused across jobs. The `build` job
is responsible for generating them, while the `test` and `fmt` jobs can
reuse them, which is why they `need` the `build` job.
  • Loading branch information
MaxMustermann2 committed Jun 4, 2024
1 parent c82d71d commit 0429b22
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 112 deletions.
56 changes: 0 additions & 56 deletions .github/workflows/fmt.yml

This file was deleted.

136 changes: 136 additions & 0 deletions .github/workflows/forge-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Forge CI to build, test and format

on:
pull_request:
push:
branches:
- main
- release/**
tags:
- "*"

env:
FOUNDRY_PROFILE: ci

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
# replace nightly because latest nightly release has some breaking changes that result in test failures
# this is a previous recent nightly release that should work
version: nightly-f625d0fa7c51e65b4bf1e8f7931cd1c6e2e285e9

- name: Print forge version
run: forge --version

- name: Build
run: forge build

- name: Add comment for build failure
if: failure()
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'The build has failed. Please check the logs.'
})
- name: Cache Foundry artifacts (excluding binaries)
uses: actions/cache/save@v3
with:
key: "${{ github.job }}-${{ github.sha }}"
path: |
- ./out
- ./cache
- ./broadcast
test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
# replace nightly because latest nightly release has some breaking changes that result in test failures
# this is a previous recent nightly release that should work
version: nightly-f625d0fa7c51e65b4bf1e8f7931cd1c6e2e285e9

- name: Restore cached Foundry artifacts
uses: actions/cache/restore@v3
with:
key: "${{ github.job }}-${{ github.sha }}"
path: |
- ./out
- ./cache
- ./broadcast
- name: Print forge version
run: forge --version

- name: Run tests
run: forge test -vvv

- name: Add comment for test failure
if: failure()
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'The tests have failed. Please check the logs.'
})
fmt:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
# replace nightly because latest nightly release has some breaking changes that result in test failures
# this is a previous recent nightly release that should work
version: nightly-f625d0fa7c51e65b4bf1e8f7931cd1c6e2e285e9

- name: Restore cached Foundry artifacts
uses: actions/cache/restore@v3
with:
key: "${{ github.job }}-${{ github.sha }}"
path: |
- ./out
- ./cache
- ./broadcast
- name: Print forge version
run: forge --version

- name: Check formatting
run: forge fmt --check

- name: Add comment for format failure
if: failure()
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'The code is not formatted correctly. Please run `forge fmt` and push the changes.'
})
56 changes: 0 additions & 56 deletions .github/workflows/test.yml

This file was deleted.

0 comments on commit 0429b22

Please sign in to comment.