Skip to content

feat: Improve test coverage and Documentation #18

feat: Improve test coverage and Documentation

feat: Improve test coverage and Documentation #18

Workflow file for this run

name: Task - Test Solidity
on:
workflow_call:
push:
paths:
- 'solidity/**'
pull_request:
paths:
- 'solidity/**'
env:
FOUNDRY_PROFILE: ci
jobs:
check:
env:
working-directory: ./solidity
strategy:
fail-fast: true
name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Run Forge build
working-directory: ${{ env.working-directory }}
run: |
forge --version
forge build --sizes
id: build
- name: Run Forge tests
working-directory: ${{ env.working-directory }}
run: |
forge test -vvv
id: run-tests
- name: Run Forge tests with gas report
working-directory: ${{ env.working-directory }}
run: |
forge test --match-contract PragmaDecoderGasTest -vvv --gas-report > gas_report.txt
id: gas-report
- name: Parse current gas report
working-directory: ${{ env.working-directory }}
run: |
echo "current_gas_results=$(grep -A 6 "Gas used for" gas_report.txt | awk '{print $NF}' | tr '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV
- name: Get previous gas results
working-directory: ${{ env.working-directory }}
run: |
git checkout HEAD^1
forge test --match-contract PragmaDecoderGasTest -vvv | grep -E '^[A-Za-z]+,[0-9]+$' > previous_gas_report.txt
echo "previous_gas_results=$(cat previous_gas_report.txt | tr '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV
git checkout -
- name: Compare gas results
id: compare-gas
working-directory: ${{ env.working-directory }}
run: |
{
echo 'gas_summary<<EOF'
echo "Gas Report Summary:"
echo '```'
IFS=',' read -ra current_array <<< "$current_gas_results"
IFS=',' read -ra previous_array <<< "$previous_gas_results"
for i in "${!current_array[@]}"; do
IFS=',' read -r test current <<< "${current_array[$i]}"
echo "Gas used for $test update: $current"
if [ ${#previous_array[@]} -gt $i ]; then
IFS=',' read -r prev_test previous <<< "${previous_array[$i]}"
if [ "$test" = "$prev_test" ]; then
diff=$((current - previous))
if [ $diff -gt 0 ]; then
echo "Change: :red_circle: +$diff ($(echo "scale=2; $diff * 100 / $previous" | bc)% increase)"
elif [ $diff -lt 0 ]; then
echo "Change: :green_circle: $diff ($(echo "scale=2; -$diff * 100 / $previous" | bc)% decrease)"
else
echo "Change: :white_circle: No change"
fi
else
echo "Change: N/A (Test name mismatch)"
fi
else
echo "Change: N/A (New test)"
fi
echo ""
done
echo '```'
echo 'EOF'
} >> $GITHUB_OUTPUT
- name: Comment PR
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
SUMMARY: ${{ steps.compare-gas.outputs.gas_summary }}
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: process.env.SUMMARY
})
- name: Update gas results
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
working-directory: ${{ env.working-directory }}
run: |
echo "$current_gas_results" > previous_gas_results.txt
git config user.name github-actions
git config user.email github-actions@github.com
git add previous_gas_results.txt
git commit -m "Update gas results" || echo "No changes to commit"
git push origin main
- name: Upload gas report as artifact
uses: actions/upload-artifact@v3
with:
name: gas-report
path: ${{ env.working-directory }}/gas_report.txt