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

test(ci): fail storage layout from same repo #1

Closed
wants to merge 96 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
4439bae
feat(ci): carve out storage layout CI
MaxMustermann2 Nov 21, 2024
4deff07
debug(ci): post the json github context
MaxMustermann2 Nov 21, 2024
dddebd7
debug(ci): add the forgotten `run`
MaxMustermann2 Nov 21, 2024
5f7363a
feat(ci): pass pr number as cache
MaxMustermann2 Nov 21, 2024
adf7459
fix(ci): apply `needs: cache`
MaxMustermann2 Nov 21, 2024
a53ea60
fix(ci): do not cache if it already exists
MaxMustermann2 Nov 21, 2024
3396c1a
fail the ci
MaxMustermann2 Nov 21, 2024
e17a904
fix(ci): use the correct hash
MaxMustermann2 Nov 21, 2024
fe7e8a6
fix(ci): change cache path everywhere
MaxMustermann2 Nov 21, 2024
aeb6fd6
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 21, 2024
2d3f04f
fix(ci): give contents: read permission to restore
MaxMustermann2 Nov 21, 2024
9e39dc1
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 21, 2024
628085b
fix forge fmt to re-trigger workflow
MaxMustermann2 Nov 21, 2024
14b5536
fix(ci): try changing the scope
MaxMustermann2 Nov 21, 2024
4b7692f
fix(ci): do not check for existing cache
MaxMustermann2 Nov 21, 2024
0d8db1d
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 21, 2024
60458b4
fix(ci)
MaxMustermann2 Nov 21, 2024
f6793bf
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 21, 2024
7d4088e
fix(ci): escape the commit status curl
MaxMustermann2 Nov 21, 2024
6c5e520
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 21, 2024
a8b56a6
fix(ci): do not use reusable restore
MaxMustermann2 Nov 21, 2024
b2e9c96
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 21, 2024
f36d9e4
fix(ci): use checkout v4
MaxMustermann2 Nov 21, 2024
30ca9e5
fix(ci): use checkout v4
MaxMustermann2 Nov 21, 2024
4371d7c
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 21, 2024
6a1bc11
revert to last known non fork situation
MaxMustermann2 Nov 26, 2024
0763b97
fix(compare-layouts): post pending status
MaxMustermann2 Nov 26, 2024
abff2bc
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 26, 2024
48015b8
reuse other actions and try
MaxMustermann2 Nov 26, 2024
97cb976
fix(ci): checkout before layout
MaxMustermann2 Nov 26, 2024
00d5860
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 26, 2024
ae2522a
fix(ci): stupid mistake
MaxMustermann2 Nov 26, 2024
71e9ebc
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 26, 2024
76dd538
add `started` and include sha
MaxMustermann2 Nov 26, 2024
b5349d0
asd
MaxMustermann2 Nov 26, 2024
cf3e590
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 26, 2024
c15d1a4
rename solhint to less verbose
MaxMustermann2 Nov 26, 2024
96d05ab
fix permissions
MaxMustermann2 Nov 26, 2024
7e60a03
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 26, 2024
dcbbe5b
fix(ci): try change scope of restore
MaxMustermann2 Nov 26, 2024
dc5f9c3
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 26, 2024
ff19c73
use artifacts not cache
MaxMustermann2 Nov 26, 2024
454c69f
fix(ci)
MaxMustermann2 Nov 26, 2024
1727af9
fix: download artifact based on run id
MaxMustermann2 Nov 27, 2024
52179ad
fix(ci): remove debug, smaller checkout
MaxMustermann2 Nov 27, 2024
2fdf8b2
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
3e0ec72
fix(ci): fast set commit status
MaxMustermann2 Nov 27, 2024
0922905
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
e220076
fix(ci): permissions
MaxMustermann2 Nov 27, 2024
4e63e92
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
40fbc9b
fix(ci): change msg
MaxMustermann2 Nov 27, 2024
0f496e7
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
7db6013
feat(ci): carve out storage layout CI
MaxMustermann2 Nov 27, 2024
7ead345
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
66972c3
fail storage compat
MaxMustermann2 Nov 27, 2024
f84c3a1
fix(ci): update status fast
MaxMustermann2 Nov 27, 2024
42ed2c2
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
7d5a4b4
feat(ci): carve out storage layout CI
MaxMustermann2 Nov 27, 2024
c05fca0
respond to AI comments
MaxMustermann2 Nov 27, 2024
ee19085
Merge branch 'feat/storage-layout-check'
MaxMustermann2 Nov 27, 2024
8230afd
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
dd628db
respond to more AI comments
MaxMustermann2 Nov 27, 2024
0dd8655
Merge branch 'feat/storage-layout-check'
MaxMustermann2 Nov 27, 2024
9121c90
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
1ff0aa2
error out if expected files do not exist
MaxMustermann2 Nov 27, 2024
3b78803
fix(ci): escape the params
MaxMustermann2 Nov 27, 2024
c38e6c7
Merge branch 'feat/storage-layout-check'
MaxMustermann2 Nov 27, 2024
9d47564
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
0510384
fix(ci): fail faster if the parent job failed
MaxMustermann2 Nov 27, 2024
1f202c2
Merge branch 'feat/storage-layout-check'
MaxMustermann2 Nov 27, 2024
a83839c
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
b0e4314
rename input for clarity
MaxMustermann2 Nov 27, 2024
78ba65c
Merge branch 'feat/storage-layout-check'
MaxMustermann2 Nov 27, 2024
67ddf0b
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
8e26760
do not set the key unless required
MaxMustermann2 Nov 27, 2024
6ca132c
Merge branch 'feat/storage-layout-check'
MaxMustermann2 Nov 27, 2024
9f42c95
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
65a4656
use not condition instead of == false
MaxMustermann2 Nov 27, 2024
66bc71c
Merge branch 'feat/storage-layout-check'
MaxMustermann2 Nov 27, 2024
510626d
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
1b9c587
remove superfluous comment
MaxMustermann2 Nov 27, 2024
aadac30
fix(ci): add timeout
MaxMustermann2 Nov 27, 2024
a667b0b
Merge branch 'feat/storage-layout-check'
MaxMustermann2 Nov 27, 2024
081a143
feat(forge-ci): parallelize layout extraction
MaxMustermann2 Nov 27, 2024
56c71cd
fix(ci): use artifacts with different names
MaxMustermann2 Nov 27, 2024
df267d6
fix(ci): flatten combination correctly
MaxMustermann2 Nov 27, 2024
8bf4f1c
split deployed layout job to parallel
MaxMustermann2 Nov 27, 2024
5ed62a2
fix(ci): make matrix single line output
MaxMustermann2 Nov 27, 2024
7164340
fix(ci): download current run artifact
MaxMustermann2 Nov 27, 2024
93a0a13
fix(ci): remove debug
MaxMustermann2 Nov 27, 2024
fc7c643
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
3866fc9
fix(ci): always create matrix
MaxMustermann2 Nov 27, 2024
956e303
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
491ecba
fix(ci): update job timeouts
MaxMustermann2 Nov 27, 2024
99bb116
fix(ci): respond to AI comments
MaxMustermann2 Nov 27, 2024
8391462
Merge branch 'main' into fix/comment-on-failure
MaxMustermann2 Nov 27, 2024
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
310 changes: 310 additions & 0 deletions .github/workflows/compare-layouts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,310 @@
name: Compare Storage Layouts

on:
workflow_run:
workflows: ["Forge CI"]
types:
- completed

permissions:
contents: read
statuses: write
pull-requests: write

jobs:
# The cache storage in the reusable foundry setup takes far too long.
# Do this job first to update the commit status and comment ASAP.
set-commit-status:
# Typically takes no more than 30s
timeout-minutes: 5
runs-on: ubuntu-latest
outputs:
number: ${{ steps.pr-context.outputs.number }}
steps:
# Log the workflow trigger details for debugging.
- name: Echo workflow trigger details
run: |
echo "Workflow run event: ${{ github.event.workflow_run.event }}"
echo "Workflow run conclusion: ${{ github.event.workflow_run.conclusion }}"
echo "Workflow run name: ${{ github.event.workflow_run.name }}"
echo "Workflow run URL: ${{ github.event.workflow_run.html_url }}"
echo "Commit SHA: ${{ github.event.workflow_run.head_commit.id }}"
echo "Workflow Run ID: ${{ github.event.workflow_run.id }}"
- name: Set commit status
# trigger is no matter what, because the status should be updated
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# this step would have been better located in forge-ci.yml, but since it needs the secret
# it is placed here. first, it is updated to pending here and failure/success is updated later.
run: |
gh api \
--method POST \
/repos/${{ github.repository }}/statuses/${{ github.event.workflow_run.head_commit.id }} \
-f state=pending \
-f context="${{ github.workflow }}" \
-f description="In progress..." \
-f target_url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- name: Get PR number
id: pr-context
if: ${{ github.event.workflow_run.event == 'pull_request' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_TARGET_REPO: ${{ github.repository }}
PR_BRANCH: |-
${{
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
|| github.event.workflow_run.head_branch
}}
run: |
pr_number=$(gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \
--json 'number' --jq '.number')
if [ -z "$pr_number" ]; then
echo "Error: PR number not found for branch '${PR_BRANCH}' in repository '${PR_TARGET_REPO}'" >&2
exit 1
fi
echo "number=$pr_number" >> "${GITHUB_OUTPUT}"
- name: Set message
id: set-message
env:
WORKFLOW_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
WORKFLOW_NAME: ${{ github.workflow }}
SHA: ${{ github.event.workflow_run.head_commit.id }}
run: |
message="🚀 The $WORKFLOW_NAME workflow has started."
echo "message=$message Check the [workflow run]($WORKFLOW_URL) for progress. ($SHA)" >> "${GITHUB_OUTPUT}"
- name: Comment CI Status
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ github.event.workflow_run.event == 'pull_request' }}
with:
header: ${{ github.workflow }}
hide_details: true
number: ${{ steps.pr-context.outputs.number }}
message: ${{ steps.set-message.outputs.message }}

setup:
# The caching of the binaries is necessary because we run the job to fetch
# the deployed layouts via a matrix strategy. This job is the parent of that job.
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, within this workflow.
# Any `pinning` of the version should be done here and in forge-ci.yml.
foundry-version: nightly
# Skip the setup job if the parent job failed.
skip-install: ${{ github.event.workflow_run.conclusion != 'success' }}

create-deployed-layouts-matrix:
# Takes about 2 seconds
timeout-minutes: 5
# Generating the matrix is very quick. It should be done regardless of the parent
# workflow status, because an empty matrix will result in no `fetch-deployed-layouts`
# jobs, which will cascade to no `compare-storage-layouts` job.
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Generate matrix from deployedContracts.json
id: generate-matrix
run: |
set -e
data=$(cat script/deployedContracts.json)

bootstrap=$(echo "$data" | jq -r '.clientChain.bootstrapLogic // empty')
clientGateway=$(echo "$data" | jq -r '.clientChain.clientGatewayLogic // empty')
vault=$(echo "$data" | jq -r '.clientChain.vaultImplementation // empty')
rewardVault=$(echo "$data" | jq -r '.clientChain.rewardVaultImplementation // empty')
capsule=$(echo "$data" | jq -r '.clientChain.capsuleImplementation // empty')

# Create the matrix as a JSON array
matrix=$(jq -n \
--arg bootstrap "$bootstrap" \
--arg clientGateway "$clientGateway" \
--arg vault "$vault" \
--arg rewardVault "$rewardVault" \
--arg capsule "$capsule" \
'[{name: "Bootstrap", address: $bootstrap},
{name: "ClientChainGateway", address: $clientGateway},
{name: "Vault", address: $vault},
{name: "RewardVault", address: $rewardVault},
{name: "ExoCapsule", address: $capsule}] | map(select(.address != ""))')

echo "Matrix: $matrix"
echo "matrix=$(echo "$matrix" | jq -c .)" >> "${GITHUB_OUTPUT}"

fetch-deployed-layouts:
# Takes about 15 seconds
timeout-minutes: 5
strategy:
matrix:
# if the parent workflow failed, the matrix will be empty. hence, no jobs will run.
contract: ${{ fromJSON(needs.create-deployed-layouts-matrix.outputs.matrix) }}
needs:
- setup
- create-deployed-layouts-matrix
runs-on: ubuntu-latest
steps:
- name: Echo a message to prevent "no steps" warning.
run: echo "Fetching the deployed layouts."
- name: Restore cached Foundry toolchain
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/cache/restore@v3
with:
path: ${{ needs.setup.outputs.installation-dir }}
key: ${{ needs.setup.outputs.cache-key }}
- name: Add Foundry to PATH
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: echo "${{ needs.setup.outputs.installation-dir }}" >> "$GITHUB_PATH"
- name: Fetch the deployed layout
if: ${{ github.event.workflow_run.conclusion == 'success' }}
env:
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
run: |
echo "Processing ${{ matrix.contract.name }} at address ${{ matrix.contract.address }}"
RPC_URL="https://eth-sepolia.g.alchemy.com/v2/$ALCHEMY_API_KEY"
cast storage --json "${{ matrix.contract.address }}" \
--rpc-url "$RPC_URL" \
--etherscan-api-key "$ETHERSCAN_API_KEY" > "${{ matrix.contract.name }}.deployed.json"
- name: Upload the deployed layout file as an artifact
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/upload-artifact@v4
with:
path: ${{ matrix.contract.name }}.deployed.json
name: deployed-layout-${{ matrix.contract.name }}-${{ github.event.workflow_run.head_commit.id }}

combine-deployed-layouts:
# Takes about 4 seconds
timeout-minutes: 5
needs: fetch-deployed-layouts
runs-on: ubuntu-latest
steps:
- name: Echo a message to prevent "no steps" warning.
run: echo "Combining the deployed layouts."
- name: Download artifacts
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/download-artifact@v4
with:
path: combined
- name: Zip up the deployed layouts
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: zip -j deployed-layouts.zip combined/*/*.json
- name: Upload the deployed layout files as an artifact
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/upload-artifact@v4
with:
path: deployed-layouts.zip
name: deployed-layouts-${{ github.event.workflow_run.head_commit.id }}

# The actual job to compare the storage layouts.
compare-storage-layouts:
# Takes no more than a minute
timeout-minutes: 5
needs:
- setup
- set-commit-status
- combine-deployed-layouts
runs-on: ubuntu-latest

steps:
# The repository needs to be available for script/deployedContracts.json
# and script/compareLayouts.js.
- name: Checkout the repository
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/checkout@v4
- name: Restore the compiled layout files from the artifact
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: dawidd6/action-download-artifact@v6
with:
name: compiled-layouts-${{ github.event.workflow_run.head_commit.id }}
run_id: ${{ github.event.workflow_run.id }}
- name: Restore the deployed layout files from the artifact
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/download-artifact@v4
with:
name: deployed-layouts-${{ github.event.workflow_run.head_commit.id }}
path: ./
- name: Extract the restored compiled layouts
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: unzip compiled-layouts.zip
- name: Extract the restored deployed layouts
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: unzip deployed-layouts.zip
- name: Set up Node.js
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Clear npm cache
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: npm cache clean --force
- name: Install the required dependency
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: npm install @openzeppelin/upgrades-core
- name: Compare the layouts
if: ${{ github.event.workflow_run.conclusion == 'success' }}
id: compare-layouts
run: |
node script/compareLayouts.js
# Even if this fails, the CI status should be updated.
continue-on-error: true
- name: Update parent commit status
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# if the outcome is not set, it will post failure
run: |
if [[ "${{ steps.compare-layouts.outcome }}" == "success" ]]; then
outcome="success"
description="Storage layouts match"
elif [[ "${{ steps.compare-layouts.outcome }}" == "failure" ]]; then
outcome="failure"
description="Storage layouts do not match"
else
outcome="failure"
description="Job skipped since ${{ github.event.workflow_run.name }} failed."
fi
gh api \
--method POST \
/repos/${{ github.repository }}/statuses/${{ github.event.workflow_run.head_commit.id }} \
-f state="$outcome" \
-f context="${{ github.workflow }}" \
-f description="$description" \
-f target_url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- name: Set message again
# Even though the job is different, specify a unique ID.
id: set-message-again
env:
WORKFLOW_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
WORKFLOW_NAME: ${{ github.workflow }}
SHA: ${{ github.event.workflow_run.head_commit.id }}
run: |
if [ ${{ steps.compare-layouts.outcome }} == "success" ]; then
message="✅ The $WORKFLOW_NAME workflow has completed successfully."
elif [ ${{ steps.compare-layouts.outcome }} == "failure" ]; then
message="❌ The $WORKFLOW_NAME workflow has failed!"
else
message="⏭ The $WORKFLOW_NAME workflow was skipped."
fi
echo "message=$message Check the [workflow run]($WORKFLOW_URL) for details. ($SHA)" >> "${GITHUB_OUTPUT}"
- name: Comment CI Status
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ github.event.workflow_run.event == 'pull_request' }}
with:
header: ${{ github.workflow }}
hide_details: true
number: ${{ needs.set-commit-status.outputs.number }}
message: ${{ steps.set-message-again.outputs.message }}
- name: Exit with the correct code
if: always()
# if the outcome is not set, it will exit 1. so, a failure in the parent job will
# result in a failure here.
run: |
if [[ "${{ steps.compare-layouts.outcome }}" == "success" ]]; then
exit 0
else
exit 1
fi
87 changes: 0 additions & 87 deletions .github/workflows/compare_deployed_storage_layout.py

This file was deleted.

Loading
Loading