Skip to content

feat(ci): carve out storage layout CI #44

feat(ci): carve out storage layout CI

feat(ci): carve out storage layout CI #44

Workflow file for this run

name: Forge CI
on:
merge_group:
pull_request:
push:
branches:
- main
- release/**
tags:
- "*"
jobs:
setup:
# A full job can be used as a reusable workflow.
# However, individual steps cannot call a reusable workflow.
# Instead, they can call a composite action.
uses: ./.github/workflows/reusable-foundry-setup.yml
with:
# The below line does not accept environment variables,
# so it becomes the single source of truth for the version.
foundry-version: nightly
build:
runs-on: ubuntu-latest
needs: setup
outputs:
# The cache-key only contains the version name. It is only used so that the name does not
# need to be repeated everywhere; instead setting the `foundry-version` above suffices.
cache-key: ${{ needs.setup.outputs.cache-key }}
# Github's cache actions are a bit weird to deal with. It wouldn't let me restore the
# binaries to /usr/bin, so I restored them to the original location and added it to PATH.
# This output will let us carry it to other jobs.
installation-dir: ${{ needs.setup.outputs.installation-dir }}
steps:
- name: Restore cached Foundry toolchain
uses: actions/cache/restore@v3
with:
path: ${{ needs.setup.outputs.installation-dir }}
key: ${{ needs.setup.outputs.cache-key }}
- name: Add Foundry to PATH
run: echo "${{ needs.setup.outputs.installation-dir }}" >> $GITHUB_PATH
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build
run: forge build
- name: Cache build artifacts
uses: actions/cache/save@v3
with:
path: |
./lib
./out
./cache
./broadcast
key: build-${{ github.sha }}
test:
runs-on: ubuntu-latest
needs: build
steps:
- name: Restore cached Foundry toolchain
uses: actions/cache/restore@v3
with:
path: ${{ needs.build.outputs.installation-dir }}
key: ${{ needs.build.outputs.cache-key }}
- name: Add Foundry to PATH
run: echo "${{ needs.build.outputs.installation-dir }}" >> $GITHUB_PATH
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Restore build artifacts
uses: actions/cache/restore@v3
with:
path: |
./lib
./out
./cache
./broadcast
key: build-${{ github.sha }}
- name: Test
run: forge test -vvv
- name: Set test snapshot as summary
run: NO_COLOR=1 forge snapshot >> $GITHUB_STEP_SUMMARY
format:
runs-on: ubuntu-latest
needs: build
steps:
- name: Restore cached Foundry toolchain
uses: actions/cache/restore@v3
with:
path: ${{ needs.build.outputs.installation-dir }}
key: ${{ needs.build.outputs.cache-key }}
- name: Add Foundry to PATH
run: echo "${{ needs.build.outputs.installation-dir }}" >> $GITHUB_PATH
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Restore build artifacts
uses: actions/cache/restore@v3
with:
path: |
./lib
./out
./cache
./broadcast
key: build-${{ github.sha }}
- name: Check formatting
run: forge fmt --check
extract-storage-layout:
runs-on: ubuntu-latest
needs: build
steps:
- name: Restore cached Foundry toolchain
uses: actions/cache/restore@v3
with:
path: ${{ needs.build.outputs.installation-dir }}
key: ${{ needs.build.outputs.cache-key }}
- name: Add Foundry to PATH
run: echo "${{ needs.build.outputs.installation-dir }}" >> $GITHUB_PATH
- name: Checkout base branch or previous commit
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref || github.event.before }}
submodules: recursive
- name: Generate base branch layout file
# Note that this `run` will do a `forge build` so we don't need to do it ourselves.
# The build artifacts of this step are not relevant to us either, so we don't need to
# cache them.
run: |
forge inspect src/core/ExocoreGateway.sol:ExocoreGateway storage-layout > ExocoreGateway.base.json
- name: Cache base branch layout file
uses: actions/cache/save@v3
with:
path: ExocoreGateway.base.json
key: ExocoreGateway-base-layout-${{ github.sha }}
# Now we can generate the layout for the PR level.
- name: Checkout back to PR
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
submodules: recursive
# Restoring these will help make `forge inspect` faster.
- name: Restore build artifacts
uses: actions/cache/restore@v3
with:
path: |
./lib
./out
./cache
./broadcast
key: build-${{ github.sha }}
# This step restores the base branch layout file, while the next step generates the PR
# branch layout files.
- name: Restore base branch layout file
uses: actions/cache/restore@v3
with:
path: ExocoreGateway.base.json
key: ExocoreGateway-base-layout-${{ github.sha }}
- name: Generate storage layout files for the PR
run: |
for file in Bootstrap ClientChainGateway RewardVault Vault ExocoreGateway ExoCapsule; do
forge inspect src/core/${file}.sol:${file} storage-layout > ${file}.compiled.json;
done
# At this point, we will make our cache to send to another workflow, which will have access to the secrets.
- name: Zip storage layout files
run: zip storage-layouts.zip *.compiled.json ExocoreGateway.base.json
- name: Cache storage layout files
uses: actions/cache/save@v3
with:
path: storage-layouts.zip
key: storage-layouts-${{ github.sha }}
- name: Store the cache output file
run: |
echo ${{ needs.build.outputs.cache-key }} > res.txt
echo ${{ needs.build.outputs.installation-dir }} >> res.txt
- name: Cache the output file
uses: actions/cache/save@v3
with:
path: res.txt
key: cache-${{ github.sha }}