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

Print latest proposal calldata for a PR #3

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
77 changes: 77 additions & 0 deletions .github/workflows/run-latest-proposal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: "Run Latest Proposal"

env:
FOUNDRY_PROFILE: "ci"

on: [pull_request]

jobs:
run-proposal:
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: "recursive"

- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: Get Changed Files
id: files
uses: jitterbit/get-changed-files@v1
with:
format: "space-delimited"

- name: Set PR_CHANGED_FILES
run: echo "PR_CHANGED_FILES=${{ steps.files.outputs.all }}" >> $GITHUB_ENV

- name: Set DEBUG flag
run: echo "DEBUG=true" >> $GITHUB_ENV

- name: Set PROPOSALS_FOLDER
run: echo "PROPOSALS_FOLDER=src/proposals" >> $GITHUB_ENV

- name: List and Delete Previous Comments
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = context.payload.pull_request.number;
const comments = await github.rest.issues.listComments({
...context.repo,
issue_number: issue_number
});

const actionComments = comments.data.filter(comment => comment.user.login === 'github-actions[bot]');

if (actionComments.length === 0) {
return;
}
for (const comment of actionComments) {
await github.rest.issues.deleteComment({
...context.repo,
comment_id: comment.id,
});
}

- name: Run Proposal
run: ./run-proposal.sh

- name: Comment PR with Proposal Output
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
if (fs.existsSync('output.json')) {
const output = JSON.parse(fs.readFileSync('output.json', 'utf8'));
const prNumber = context.payload.pull_request.number;
github.rest.issues.createComment({
...context.repo,
issue_number: prNumber,
body: `### Proposal output for ${output.file}:\n\`\`\`\n${output.output}\n\`\`\``
});
}
66 changes: 66 additions & 0 deletions run-proposal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
# This script is used on the CI to print proposal output for the highest numbered .sol file in the PR.

# PR_CHANGED_FILES is a list of files changed in the PR, set by the CI
CHANGED_FILES=$PR_CHANGED_FILES
FOLDER=$PROPOSALS_FOLDER

if [[ ! -z "$CHANGED_FILES" ]]; then
IFS=' ' read -r -a files_array <<< "$CHANGED_FILES"

# Initialize an empty array to hold numbers and corresponding file names
max_number=-1
selected_file=""

for file in "${files_array[@]}"; do
if [[ $file == "$FOLDER"/*.sol ]]; then

# Extract the number following 'Proposal_' before '.sol'
number=$(echo $file | sed -E 's/.*Proposal_([0-9]+)\.sol/\1/')

# Check if a number was actually found; if not, skip this file
if [[ -z "$number" ]]; then
continue
fi

# Check if this number is the highest found so far
if [[ "$number" -gt "$max_number" ]]; then
max_number=$number
selected_file=$file
fi
fi
done

# If file was found
if [[ ! -z "$selected_file" ]]; then
echo "Processing $selected_file..."
output=$(forge script "$selected_file" 2>&1)
# Removal of ANSI Escape Codes
clean_output=$(echo "$output" | sed 's/\x1b\[[0-9;]*m//g')

echo "Output for $selected_file:"
echo "$clean_output"

# Extracting the relevant part of the output
selected_output=$(echo "$clean_output" | awk '
/------------------ Proposal Actions ------------------/, /\n\nProposal Description:/ {
if (/\n\nProposal Description:/) exit; # Exit before printing the line with "Proposal Description:"
print;
}
')

json_output=""
# Write to JSON if selected_output otherwise write a failure message
if [ ! -z "$selected_output" ]; then
json_output=$(jq -n --arg file "$selected_file" --arg output "$selected_output" '{file: $file, output: $output}')
else
json_output=$(jq -n --arg file "$selected_file" --arg output "Proposal $selected_file failed. Check CI logs" '{file: $file, output: $output}')
fi

echo "Writing JSON to output.json..."
# Create output.json
touch output.json
# Write JSON to output.json
echo "$json_output" > output.json
fi
fi
2 changes: 1 addition & 1 deletion src/proposals/BravoProposal_02.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {Token} from "src/mocks/Token.sol";

contract BravoProposal_02 is GovernorBravoProposal {
function name() public pure override returns (string memory) {
return "BRAVO_MOCK_2";
return "BRAVO_MOCK_02";
}

function description() public pure override returns (string memory) {
Expand Down
Loading