-
Notifications
You must be signed in to change notification settings - Fork 73
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: setup for running checks locally #29
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
node_modules | ||
.idea | ||
|
||
reports/ | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
require('dotenv').config() | ||
import fs from 'fs'; | ||
import { | ||
DAO_NAME, | ||
GITHUB_REPO_NAME, | ||
GITHUB_REPO_OWNER, | ||
GOVERNOR_ADDRESS, | ||
REPORTS_BRANCH, | ||
RUNNING_LOCALLY | ||
} from "./utils/constants"; | ||
import { github } from "./utils/clients/github"; | ||
import { governorBravo } from "./utils/contracts/governor-bravo"; | ||
import { provider } from "./utils/clients/ethers"; | ||
import { AllCheckResults, Proposal } from "./types"; | ||
|
@@ -32,6 +34,7 @@ async function main() { | |
.map((proposal) => proposal.args as unknown as Proposal); | ||
|
||
for (const proposal of activeProposals) { | ||
console.log(`Checking proposal ${proposal.id}...`); | ||
const checkResults: AllCheckResults = Object.fromEntries( | ||
await Promise.all( | ||
Object.keys(ALL_CHECKS).map(async (checkId) => [ | ||
|
@@ -56,37 +59,46 @@ async function main() { | |
: null, | ||
]); | ||
|
||
let sha: string | undefined; | ||
try { | ||
const { data } = await github.rest.repos.getContent({ | ||
const report = toProposalReport( | ||
{ start: startBlock, end: endBlock, current: latestBlock }, | ||
proposal, | ||
checkResults | ||
); | ||
|
||
if (RUNNING_LOCALLY) { | ||
// Running locally, dump to file | ||
const dir = `./reports/${DAO_NAME}/${GOVERNOR_ADDRESS}/`; // TODO more robust way to keep this in sync with `path` | ||
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true }); | ||
fs.writeFileSync(`${dir}/${proposal.id}.md`, report); | ||
|
||
} else { | ||
// Running in CI, save to file on REPORTS_BRANCH | ||
const { github } = await import("./utils/clients/github"); // lazy load to avoid errors about missing env vars when not in CI | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would probably do this slightly differently, where you just have a different entry point for main and local testing, but you can probably also just use something like is the github token to enter this code path also would be cool if our testing was scripted (integration testing) for ongoing maintenance, but that's a lot of work There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yea different entry point could work also, but probably would want to pull out some of the existing code into standalone methods to avoid duplicating code. My thinking was this is the shortest path forward to knocking out the bigger unknowns (e.g. tx simulation), then could refactor later
Do you mean remove the
Could you create an issue with some more details on what you had in mind here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
agree, you would want both entry points to call into the report generator code, where the cli entry point writes the output to console, (or somewhere useful for manual testing), takes cli arguments for which governor and/or proposal to check, etc. it shouldn't be a large refactor, but i'm ok with doing it later
yeah, you only need to check the one created #31 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool that all makes sense, thanks 👌 |
||
let sha: string | undefined; | ||
try { | ||
const { data } = await github.rest.repos.getContent({ | ||
owner: GITHUB_REPO_OWNER, | ||
repo: GITHUB_REPO_NAME, | ||
ref: REPORTS_BRANCH, | ||
path, | ||
}); | ||
if ("sha" in data) { | ||
sha = data.sha; | ||
} | ||
} catch (error) { | ||
console.warn("Failed to get sha for file at path", path, error); | ||
} | ||
|
||
await github.rest.repos.createOrUpdateFileContents({ | ||
owner: GITHUB_REPO_OWNER, | ||
repo: GITHUB_REPO_NAME, | ||
ref: REPORTS_BRANCH, | ||
branch: REPORTS_BRANCH, | ||
message: `Update ${path} as of ${formattedDateTime}`, | ||
content: Buffer.from(report, "utf-8").toString("base64"), | ||
path, | ||
sha, | ||
}); | ||
if ("sha" in data) { | ||
sha = data.sha; | ||
} | ||
} catch (error) { | ||
console.warn("Failed to get sha for file at path", path, error); | ||
} | ||
|
||
await github.rest.repos.createOrUpdateFileContents({ | ||
owner: GITHUB_REPO_OWNER, | ||
repo: GITHUB_REPO_NAME, | ||
branch: REPORTS_BRANCH, | ||
message: `Update ${path} as of ${formattedDateTime}`, | ||
content: Buffer.from( | ||
toProposalReport( | ||
{ start: startBlock, end: endBlock, current: latestBlock }, | ||
proposal, | ||
checkResults | ||
), | ||
"utf-8" | ||
).toString("base64"), | ||
path, | ||
sha, | ||
}); | ||
} catch (error) { | ||
console.error("Failed to update file contents", error); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { providers } from "ethers"; | ||
import { INFURA_API_KEY } from "../constants"; | ||
import { RPC_URL } from "../constants"; | ||
|
||
export const provider = new providers.InfuraProvider(1, INFURA_API_KEY); | ||
export const provider = new providers.JsonRpcProvider(RPC_URL); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -578,6 +578,11 @@ diff@^4.0.1: | |
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" | ||
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== | ||
|
||
dotenv@^10.0.0: | ||
version "10.0.0" | ||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81" | ||
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q== | ||
|
||
[email protected]: | ||
version "6.5.4" | ||
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
.env.local
maybeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, must have been using my global gitignore. Done in 6bd5777