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(lib): implement shallow-clone #40

Merged
merged 12 commits into from
Mar 14, 2024
62 changes: 62 additions & 0 deletions .github/workflows/create-PR-deploy-to-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Create PR Deploy to Release

on:
push:
branches:
- deploy/*
pull_request:
branches:
- deploy/*

env:
HEAD_BRANCH: ${{ github.head_ref || github.ref_name }}

permissions:
contents: write
pull-requests: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set Env
run: |
echo "PR_BRANCH=merge/${HEAD_BRANCH}" >> $GITHUB_ENV
echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\///' | cut -d'-' -f1)" >> $GITHUB_ENV
echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\/v[0-9\.]*-\(.*\)/\1/')" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: 'release/${{ env.VERSION }}'
fetch-depth: 0
fetch-tags: 'true'

- name: Get Testnet Latest Tag
if: ${{ env.NETWORK == 'testnet' }}
run: |
echo "LATESTTAG=$(git describe --tags --match "*testnet*" --abbrev=0)" >> $GITHUB_ENV

- name: Get Mainnet Latest Tag
if: ${{ env.NETWORK == 'mainnet' }}
run: |
echo "LATESTTAG=$(git describe --tags --match "*mainnet*" --abbrev=0)" >> $GITHUB_ENV

- name: Reset promotion branch
run: |
git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH}
git reset --hard ${HEAD_BRANCH}

- name: Generate Release note
id: template
run: |
echo "VERSION=${{ env.VERSION }} - SHA: ${{ github.sha }}" > CHANGELOG.md

- name: Create Pull Request
id: cpr
uses: peter-evans/[email protected]
with:
labels: automated PR
delete-branch: true
title: 'chore(`release/${{ env.VERSION }}`): merge from `${{ env.HEAD_BRANCH}}`'
body: ${{ steps.template.outputs.result }}
branch: ${{ env.PR_BRANCH }}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
toBranch: ${{ env.FEATURE_BRANCH }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6.0.1
with:
branch: ${{ env.HEAD_BRANCH }}
base: ${{env.FEATURE_BRANCH}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
toBranch: ${{matrix.branch_name}}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6.0.1
with:
labels: automated PR
delete-branch: true
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/create-PR-release-to-network.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Create PR from release to network

on:
pull_request:
branches:
- release/*
types:
- closed

permissions:
contents: write
pull-requests: write

env:
HEAD_BRANCH: ${{ github.head_ref || github.ref_name }}
RELEASE_BRANCH: ${{ github.event.pull_request.base.ref}}

jobs:
merge-release-to-network:
runs-on: ubuntu-latest
if: ${{ (github.event.pull_request.merged == true) && (contains(github.head_ref, 'deploy') || contains(github.ref_name, 'deploy')) }}
steps:
- name: Set Env
run: |
echo "PR_BRANCH=merge/${HEAD_BRANCH}" >> $GITHUB_ENV
echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\///' | cut -d'-' -f1)" >> $GITHUB_ENV
echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\/v[0-9\.]*-\(.*\)/\1/')" >> $GITHUB_ENV

- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ env.NETWORK }}

- name: Reset promotion branch
run: |
git fetch origin ${RELEASE_BRANCH}:${RELEASE_BRANCH}
git reset --hard ${RELEASE_BRANCH}

- name: Create Pull Request
id: cpr
uses: peter-evans/[email protected]
with:
labels: automated PR
delete-branch: true
title: 'chore(`${{ env.NETWORK }}`): merge from `${{ env.HEAD_BRANCH}}`'
body: ${{ steps.template.outputs.result }}
branch: ${{env.PR_BRANCH}}
64 changes: 64 additions & 0 deletions .github/workflows/create-release-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Create Release Tag

on:
pull_request:
types: [closed]
branches:
- mainnet
- testnet

env:
HEAD_BRANCH: ${{ github.head_ref || github.ref_name }}

permissions:
contents: write
pull-requests: write

jobs:
create-release-tag:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Set Env
run: |
echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\///' | cut -d'-' -f1)" >> $GITHUB_ENV
echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\/v[0-9\.]*-\(.*\)/\1/')" >> $GITHUB_ENV

- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ env.NETWORK }}
fetch-depth: 0
fetch-tags: 'true'

- name: Set Mainnet Tag
if: ${{ env.NETWORK == 'mainnet' }}
run: |
echo "TAG=${{ env.VERSION }}" >> $GITHUB_ENV

- name: Set Testnet Tag
if: ${{ env.NETWORK == 'testnet' }}
run: |
echo "TAG=${{ env.VERSION }}-testnet" >> $GITHUB_ENV

- name: Get Testnet Latest Tag
if: ${{ env.NETWORK == 'testnet' }}
run: |
echo "LATESTTAG=$(git describe --tags --match "*testnet*" --abbrev=0)" >> $GITHUB_ENV

- name: Get Mainnet Latest Tag
if: ${{ env.NETWORK == 'mainnet' }}
run: |
echo "LATESTTAG=$(git describe --tags --match "*mainnet*" --abbrev=0)" >> $GITHUB_ENV

- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.TAG }}
run: |
gh release create "$tag" \
--repo "$GITHUB_REPOSITORY" \
--title "${{ env.NETWORK }} release ${{ env.VERSION }}" \
--target "${{ env.NETWORK }}" \
--notes-start-tag "${{ env.LATESTTAG }}" \
--generate-notes
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
shallow = true
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/lib/openzeppelin-contracts"]
shallow = true
8 changes: 4 additions & 4 deletions .husky/generate-layout.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
rm -rf logs/storage/*
dirOutputs=$(ls out | grep '^[^.]*\.sol$') # assuming the out dir is at 'out'
while IFS= read -r contractDir; do
innerdirOutputs=$(ls out/$contractDir)
innerdirOutputs=$(ls out/"$contractDir")

while IFS= read -r jsonFile; do
fileIn=out/$contractDir/$jsonFile
fileOut=logs/storage/$contractDir:${jsonFile%.json}.log
node .husky/storage-logger.js $fileIn $fileOut &
fileIn=out/"$contractDir"/$jsonFile
fileOut=logs/storage/"$contractDir":${jsonFile%.json}.log
node .husky/storage-logger.js "$fileIn" "$fileOut" &
done <<< "$innerdirOutputs"
done <<< "$dirOutputs"

Expand Down
4 changes: 2 additions & 2 deletions .husky/pre-push
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ forge build --sizes 2>&1 | sed -n '/Contract/,$p' > logs/contract-code-sizes.log
git add logs

output=$(git status -s)
line_count=$(echo "$output" | wc -l)
if [ "$line_count" -gt 1 ]; then
word_count=$(echo "$output" | wc -w)
if [ "$word_count" -gt 0 ]; then
git commit -m "chore: storage layout"
fi

Expand Down
67 changes: 36 additions & 31 deletions .husky/storage-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,49 @@ const fileIn = process.argv[2];
const fileOut = process.argv[3];

if (!fileIn) {
console.error('Invalid input');
console.error('Invalid input');
}

fs.readFile(fileIn, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
if (err) {
console.error('Error reading file:', err);
return;
}

try {
const jsonData = JSON.parse(data);
if (typeof jsonData.storageLayout == 'undefined' || jsonData.ast.absolutePath == 'undefined') {
return;
}

try {
const jsonData = JSON.parse(data);
if (typeof jsonData.storageLayout == 'undefined') {
return;
}
if (jsonData.storageLayout.storage.length == 0) {
return;
}

if (jsonData.storageLayout.storage.length == 0) {
return;
}
// Skip generating storage layout for files locate in the directory "src"
if (!jsonData.ast.absolutePath.startsWith('src')) {
return;
}

const outputData = jsonData.storageLayout.storage
.map(({ contract, label, offset, slot, type: typeId }) => {
const typeObj = jsonData.storageLayout.types[typeId];
const typeLabel = typeObj.label;
const numberOfBytes = typeObj.numberOfBytes;
return `${contract}:${label} (storage_slot: ${slot}) (offset: ${offset}) (type: ${typeLabel}) (numberOfBytes: ${numberOfBytes})`;
})
.join('\n');
if (!fileOut) {
console.log(outputData);
} else {
fs.writeFile(fileOut, outputData, 'utf-8', err => {
if (err) {
console.error('Error writing file:', err);
return;
}
});
const outputData = jsonData.storageLayout.storage
.map(({ contract, label, offset, slot, type: typeId }) => {
const typeObj = jsonData.storageLayout.types[typeId];
const typeLabel = typeObj.label;
const numberOfBytes = typeObj.numberOfBytes;
return `${contract}:${label} (storage_slot: ${slot}) (offset: ${offset}) (type: ${typeLabel}) (numberOfBytes: ${numberOfBytes})`;
})
.join('\n');
if (!fileOut) {
console.log(outputData);
} else {
fs.writeFile(fileOut, outputData, 'utf-8', err => {
if (err) {
console.error('Error writing file:', err);
return;
}
} catch (err) {
console.error('Error parsing JSON:', err);
});
}
} catch (err) {
console.error('Error parsing JSON:', err);
}
});
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts
27 changes: 27 additions & 0 deletions logs/contract-code-sizes.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
| Contract | Size (kB) | Margin (kB) |
|---------------------------|-----------|-------------|
| LibErrorHandler | 0.086 | 24.49 |
| LibNativeTransfer | 0.086 | 24.49 |
| LibSafeRange | 0.086 | 24.49 |
| Math | 0.086 | 24.49 |
| MockERC20 | 3.704 | 20.872 |
| MockERC721 | 3.964 | 20.612 |
| Panic | 0.086 | 24.49 |
| RONTransferHelper | 0.086 | 24.49 |
| RONTransferHelperExtended | 0.086 | 24.49 |
| SafeCast | 0.086 | 24.49 |
| SignedMath | 0.086 | 24.49 |
| StdStyle | 0.086 | 24.49 |
| Strings | 0.086 | 24.49 |
| TransferFromHelper | 0.086 | 24.49 |
| TransferHelper | 0.086 | 24.49 |
| console | 0.086 | 24.49 |
| console2 | 0.086 | 24.49 |
| safeconsole | 0.086 | 24.49 |
| stdError | 0.592 | 23.984 |
| stdJson | 0.086 | 24.49 |
| stdMath | 0.086 | 24.49 |
| stdStorage | 0.086 | 24.49 |
| stdStorageSafe | 0.086 | 24.49 |
| stdToml | 0.086 | 24.49 |

1 change: 1 addition & 0 deletions logs/storage/Counter.sol:Counter.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/Counter.sol:Counter:number (storage_slot: 0) (offset: 0) (type: uint256) (numberOfBytes: 32)
Loading