Skip to content

Commit 4d0877b

Browse files
authored
fix: address check workflow (yearn#505)
* fix: address check workflow * fix issue output * break constants for testing * fix: script async issues * fix: checks action and constants test * fix: formatting * Fix contract check automation (yearn#506) * fix: address check workflow * fix issue output * break constants for testing * fix: script async issues * fix: checks action and constants test * fix: formatting * fix: workflow issue posting * Fix contract check automation (yearn#508) * fix: address check workflow * fix issue output * break constants for testing * fix: script async issues * fix: checks action and constants test * fix: formatting * fix: workflow issue posting * fix: unbreak constants * fix: add contract checks to build workflow * fix: workflow perms * fix: workflow secrets issue on forked PR * fix: close if statement * move check and issue generation from CI to script * Fix contract check automation (yearn#516) * fix: address check workflow * fix issue output * break constants for testing * fix: script async issues * fix: checks action and constants test * fix: formatting * fix: workflow issue posting * fix: unbreak constants * fix: add contract checks to build workflow * fix: workflow perms * fix: workflow secrets issue on forked PR * fix: close if statement * move check and issue generation from CI to script * fix: issue with workflow * Fix contract check automation (yearn#518) * fix: address check workflow * fix issue output * break constants for testing * fix: script async issues * fix: checks action and constants test * fix: formatting * fix: workflow issue posting * fix: unbreak constants * fix: add contract checks to build workflow * fix: workflow perms * fix: workflow secrets issue on forked PR * fix: close if statement * move check and issue generation from CI to script * fix: issue with workflow * fix: just work please - add debugging * fix: better debugging * fix: pass vars to github environment correctly
1 parent 500eae8 commit 4d0877b

File tree

7 files changed

+88
-49
lines changed

7 files changed

+88
-49
lines changed

.github/workflows/addressChecks.yml

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ jobs:
1313
steps:
1414
- name: Checkout repository
1515
uses: actions/checkout@v4
16-
with:
17-
token: ${{ secrets.RG_ISSUES_TOKEN }}
1816

1917
- name: Set up Node.js
2018
uses: actions/setup-node@v4
@@ -40,32 +38,13 @@ jobs:
4038
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
4139
run: |
4240
ts-node scripts/runAddressChecks.ts
43-
44-
- name: Check if all checks passed
45-
id: check_all_passed
46-
run: |
47-
ALL_CHECKS_PASSED=$(jq -r '.addressChecks.allChecksPassed' scripts/fetchedAddressData.json)
48-
echo "All checks passed: $ALL_CHECKS_PASSED"
49-
echo "all_checks_passed=$ALL_CHECKS_PASSED" >> $GITHUB_ENV
50-
if [ "$ALL_CHECKS_PASSED" != "true" ]; then
51-
echo "Generating issue content..."
52-
echo "Automatic Address Checks have failed. The following contracts have changed:" > issue_body.md
53-
jq -r '.addressChecks.failedChecks[]' scripts/fetchedAddressData.json | while read CHECK; do
54-
echo "- $CHECK" >> issue_body.md
55-
done
56-
echo "The addresses shown above should be the updated, correct addresses. Please review and change the values in \`src/ethereum/constants.ts\`." >> issue_body.md
57-
echo "" >> issue_body.md
58-
echo "Updated fetchedAddressData.json content:" >> issue_body.md
59-
cat scripts/fetchedAddressData.json >> issue_body.md
60-
fi
61-
41+
echo "ALL_CHECKS_PASSED=$(cat all_checks_passed.txt)" >> $GITHUB_ENV
6242
6343
- name: Create an issue if checks failed
64-
if: env.all_checks_passed != 'true'
65-
uses: peter-evans/create-issue-from-file@v4
66-
with:
67-
token: ${{ secrets.RG_ISSUES_TOKEN }}
68-
title: 'Address Checks Failed'
69-
content-filepath: 'issue_body.md'
70-
labels: 'address-checks, alert'
71-
assignees: 'rossgalloway'
44+
if: env.ALL_CHECKS_PASSED != 'true'
45+
run: |
46+
curl -H "Authorization: Bearer ${{ secrets.ADDRESS_CHECKS }}" \
47+
-H "Content-Type: application/json" \
48+
-d "$(jq -n --arg title ':robot: Address Checks Failed' --arg body "$(cat issue_body.md)" '{title: $title, body: $body}')" \
49+
https://api.github.com/repos/yearn/yearn-devdocs/issues
50+
echo "Issue created"

.github/workflows/documentation.yml

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on: [push, pull_request]
55
jobs:
66
build-and-release:
77
runs-on: ubuntu-latest
8+
permissions:
9+
contents: write
810
steps:
911
- uses: actions/checkout@v4
1012
- uses: actions/setup-node@v4
@@ -13,13 +15,45 @@ jobs:
1315
- name: Test Build
1416
run: |
1517
if [ -e yarn.lock ]; then
16-
yarn install
18+
yarn install
19+
yarn global add ts-node
1720
elif [ -e package-lock.json ]; then
18-
npm ci
21+
npm ci
22+
npm install -g ts-node
1923
else
20-
npm i
24+
npm install
25+
npm install -g ts-node
2126
fi
2227
npm run build
28+
29+
- name: Check if PR is from a fork
30+
id: check_fork
31+
run: |
32+
if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
33+
echo "PR is from a fork"
34+
echo "is_fork=true" >> $GITHUB_ENV
35+
else
36+
echo "PR is not from a fork"
37+
echo "is_fork=false" >> $GITHUB_ENV
38+
fi
39+
40+
- name: Run address checks
41+
if: env.is_fork != 'true'
42+
env:
43+
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
44+
run: |
45+
ts-node scripts/runAddressChecks.ts
46+
echo "ALL_CHECKS_PASSED=$(cat all_checks_passed.txt)" >> $GITHUB_ENV
47+
48+
- name: Create an issue if address checks fail
49+
if: env.is_fork != 'true' && env.ALL_CHECKS_PASSED != 'true'
50+
run: |
51+
curl -H "Authorization: Bearer ${{ secrets.ADDRESS_CHECKS }}" \
52+
-H "Content-Type: application/json" \
53+
-d "$(jq -n --arg title ':robot: Address Checks Failed' --arg body "$(cat issue_body.md)" '{title: $title, body: $body}')" \
54+
https://api.github.com/repos/yearn/yearn-devdocs/issues
55+
echo "Issue created"
56+
2357
- name: Trigger Algolia Recrawl
2458
if: github.event_name != 'pull_request'
2559
run: |

scripts/fetchedAddressData.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"timeLastChecked": 1736294978,
3-
2+
"timeLastChecked": 1738956876,
43
"addressesData": {
54
"v3ContractAddresses": {
65
"topLevel": {
@@ -133,4 +132,4 @@
133132
"yGauge USDS-1 yVault": true
134133
}
135134
}
136-
}
135+
}

scripts/runAddressChecks.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ const fetchAddresses = async () => {
7474
if (!yearnV3Data) throw new Error('Failed to fetch Yearn V3 addresses')
7575

7676
const v3AddressData: V3ContractAddresses = {
77-
7877
topLevel: topLevelData.addresses,
7978
protocolPeriphery: protocolPeripheryData.addresses,
8079
releaseRegistry: releaseRegistryData.addresses,
@@ -98,7 +97,7 @@ const fetchAddresses = async () => {
9897
veYfiGaugeAddresses: veYfiData.veYfiGaugeAddresses,
9998
}
10099

101-
const addressChecks = {
100+
const addressChecks: AddressChecks = {
102101
allV3ChecksPassed: v3CheckFlag,
103102
allVeYfiChecksPassed: veYfiCheckFlag,
104103
failedChecks,
@@ -128,11 +127,39 @@ const fetchAddresses = async () => {
128127
}
129128

130129
async function runAddressCheck() {
131-
let addressesData, addressChecks // declare variables outside the if block
130+
let addressesData: ContractAddresses = {} as ContractAddresses // initialize with default value
131+
let addressChecks: AddressChecks = {} as AddressChecks // initialize with default value
132132
if (publicClient) {
133133
const result = await fetchAddresses()
134-
addressesData = result?.addressesData
135-
addressChecks = result?.addressChecks
134+
if (result) {
135+
// added null check for result
136+
addressesData = result.addressesData
137+
addressChecks = result.addressChecks
138+
} else {
139+
throw new Error('Failed to fetch addresses')
140+
}
141+
}
142+
143+
const allChecksPassed =
144+
addressChecks.allV3ChecksPassed && addressChecks.allVeYfiChecksPassed
145+
process.env.ALL_CHECKS_PASSED = allChecksPassed ? 'true' : 'false'
146+
console.log('allChecksPassed: ', process.env.ALL_CHECKS_PASSED)
147+
148+
fs.writeFileSync('all_checks_passed.txt', process.env.ALL_CHECKS_PASSED)
149+
150+
if (addressChecks.failedChecks.length > 0) {
151+
console.log('Generating issue content...')
152+
let issueContent =
153+
':robot::warning: **Automatic Address Checks have failed!** :warning::robot:\n'
154+
issueContent += 'The following contracts have changed:\n'
155+
addressChecks.failedChecks.forEach((check: string) => {
156+
issueContent += `- ${check}\n`
157+
})
158+
issueContent +=
159+
'\nThe addresses shown above should be the updated, correct addresses. Please review and change the values in `src/ethereum/constants.ts`.\n'
160+
161+
fs.writeFileSync('issue_body.md', issueContent)
162+
console.log('Issue content generated.')
136163
}
137164
const timeLastChecked = Math.floor(Date.now() / 1000) // get current time in Unix format
138165
console.log('writing report to scripts/fetchedAddressData.json')

src/ethereum/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ export const protocolPeriphery = {
181181
keeper: '0x52605BbF54845f520a3E94792d019f62407db2f8',
182182
aprOracleENS: 'apr.oracle.v3.ychad.eth',
183183
aprOracle: '0x1981AD9F44F2EA9aDd2dC4AD7D075c102C70aF92',
184-
releaseRegistry: '0x1981ad9f44f2ea9add2dc4ad7d075c102c70af92',
185184
baseFeeProvider: '0xe0514dd71cfdc30147e76f65c30bdf60bfd437c3',
186185
commonReportTrigger: '0xa045d4daea28ba7bfe234c96eaa03dafae85a147',
187186
auctionFactory: '0xE6aB098E8582178A76DC80d55ca304d1Dec11AD8',

src/ethereum/types.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,21 @@ export type VeYfiGauge = {
7171
}
7272

7373
export type AddressChecks = {
74-
allChecksPassed: boolean | undefined
74+
allV3ChecksPassed: boolean | undefined
75+
allVeYfiChecksPassed: boolean | undefined
7576
failedChecks: string[]
7677
v3Checks: {
7778
topLevel: {
78-
v3ProtocolAddressProviderCheck: Promise<boolean>
79+
v3ProtocolAddressProviderCheck: boolean
7980
v3ProtocolAddressProviderENSCheck: boolean
80-
v3ReleaseRegistryCheck: Promise<boolean>
81+
v3ReleaseRegistryCheck: boolean
8182
v3ReleaseRegistryENSCheck: boolean
82-
v3RoleManagerCheck: Promise<boolean>
83+
v3RoleManagerCheck: boolean
8384
v3RoleManagerENSCheck: boolean
8485
}
8586
protocolPeriphery: { [key: string]: boolean }
8687
releaseRegistry: { [key: string]: boolean }
8788
yearnV3: { [key: string]: boolean }
8889
}
89-
veYFiChecks: GaugeCheckRecord
90+
veYfiChecks: GaugeCheckRecord
9091
}

src/ethereum/v3Checks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const fetchTopLevelAddressesFromENS = async (
3838
'v3ProtocolAddressProvider',
3939
failedChecks
4040
)
41-
const v3ProtocolAddressProviderCheck = validateAddress(
41+
const v3ProtocolAddressProviderCheck = await validateAddress(
4242
constants.topLevel.protocolAddressProvider,
4343
'v3ProtocolAddressProvider',
4444
v3ProtocolAddressProvider,
@@ -55,7 +55,7 @@ export const fetchTopLevelAddressesFromENS = async (
5555
'v3ReleaseRegistry',
5656
failedChecks
5757
)
58-
const v3ReleaseRegistryCheck = validateAddress(
58+
const v3ReleaseRegistryCheck = await validateAddress(
5959
constants.topLevel.releaseRegistry,
6060
'v3ReleaseRegistry',
6161
v3ReleaseRegistry,
@@ -70,7 +70,7 @@ export const fetchTopLevelAddressesFromENS = async (
7070
'v3RoleManager',
7171
failedChecks
7272
)
73-
const v3RoleManagerCheck = validateAddress(
73+
const v3RoleManagerCheck = await validateAddress(
7474
constants.yearnV3RoleManager.roleManager,
7575
'v3RoleManager',
7676
v3RoleManager,

0 commit comments

Comments
 (0)