feat(ci/arena): Add logging and debug output to workflow script

This commit is contained in:
Reinier van der Leer
2024-03-01 11:02:41 +01:00
parent 4011294da0
commit 4546dfdf17

View File

@@ -23,16 +23,21 @@ jobs:
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
console.log('⚙️ Setting up...');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const pr = context.payload.pull_request; const pr = context.payload.pull_request;
const isFork = pr.head.repo.fork; const isFork = pr.head.repo.fork;
console.log('↔️ Fetching PR diff metadata...');
const prFilesChanged = (await github.rest.pulls.listFiles({ const prFilesChanged = (await github.rest.pulls.listFiles({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
pull_number: pr.number, pull_number: pr.number,
})).data; })).data;
console.debug(prFilesChanged);
const arenaFilesChanged = prFilesChanged.filter( const arenaFilesChanged = prFilesChanged.filter(
({ filename: file }) => file.startsWith('arena/') && file.endsWith('.json') ({ filename: file }) => file.startsWith('arena/') && file.endsWith('.json')
); );
@@ -40,6 +45,8 @@ jobs:
({ filename }) => filename.startsWith('autogpts/') ({ filename }) => filename.startsWith('autogpts/')
); );
console.log(` ${arenaFilesChanged.length} arena entries affected`);
console.debug(arenaFilesChanged);
if (arenaFilesChanged.length === 0) { if (arenaFilesChanged.length === 0) {
// If no files in `arena/` are changed, this job does not need to run. // If no files in `arena/` are changed, this job does not need to run.
return; return;
@@ -67,21 +74,28 @@ jobs:
if (arenaFilesChanged.length === 1) { if (arenaFilesChanged.length === 1) {
const newArenaFile = arenaFilesChanged[0] const newArenaFile = arenaFilesChanged[0]
const newArenaFileName = path.basename(newArenaFile.filename) const newArenaFileName = path.basename(newArenaFile.filename)
console.log(` Arena entry in PR: ${newArenaFile}`);
if (pr.mergeable) { if (pr.mergeable) {
const newArenaEntry = JSON.parse(fs.readFileSync(newArenaFile.filename)); const newArenaEntry = JSON.parse(fs.readFileSync(newArenaFile.filename));
const allArenaFiles = await (await glob.create('arena/*.json')).glob(); const allArenaFiles = await (await glob.create('arena/*.json')).glob();
console.debug(newArenaEntry);
console.log(` Checking ${newArenaFileName} against existing entries...`);
for (const file of allArenaFiles) { for (const file of allArenaFiles) {
if ( if (
path.basename(file) === newArenaFileName path.basename(file) === newArenaFileName
&& newArenaFile.status != 'added' && newArenaFile.status != 'added'
) { ) {
flagForManualCheck = true; flagForManualCheck = true;
continue;
} }
console.debug(`Checking against ${file}`...)
const arenaEntry = JSON.parse(fs.readFileSync(file)); const arenaEntry = JSON.parse(fs.readFileSync(file));
if (arenaEntry.github_repo_url === newArenaEntry.github_repo_url) { if (arenaEntry.github_repo_url === newArenaEntry.github_repo_url) {
console.log('⚠️ Duplicate detected: ${file}');
issues.push( issues.push(
`The github_repo_url specified in __${newArenaFileName}__ ` `The github_repo_url specified in __${newArenaFileName}__ `
+ `already exists in __${file}__. ` + `already exists in __${file}__. `
@@ -91,6 +105,7 @@ jobs:
} }
} }
} else { } else {
console.log('⚠️ PR has conflicts');
issues.push( issues.push(
`__${newArenaFileName}__ conflicts with existing entry with the same name` `__${newArenaFileName}__ conflicts with existing entry with the same name`
) )
@@ -98,8 +113,12 @@ jobs:
} }
} // end if (arenaFilesChanged.length === 1) } // end if (arenaFilesChanged.length === 1)
console.log(' Finished checking against existing entries')
if (issues.length == 0) { if (issues.length == 0) {
console.log('✅ No issues detected');
if (flagForManualCheck) { if (flagForManualCheck) {
console.log(' Requesting review from maintainers...')
await github.rest.pulls.requestReviewers({ await github.rest.pulls.requestReviewers({
owner: github.context.repo.owner, owner: github.context.repo.owner,
repo: github.context.repo.repo, repo: github.context.repo.repo,
@@ -107,6 +126,7 @@ jobs:
team_reviewers: ['maintainers'], team_reviewers: ['maintainers'],
}); });
} else { } else {
console.log(' Approving PR...');
await github.rest.pulls.createReview({ await github.rest.pulls.createReview({
owner: github.context.repo.owner, owner: github.context.repo.owner,
repo: github.context.repo.repo, repo: github.context.repo.repo,
@@ -115,6 +135,9 @@ jobs:
}); });
} }
} else { } else {
console.log(`⚠️ ${issues.length} issues detected`);
console.log(' Posting comment indicating issues...')
await github.rest.issues.createComment({ await github.rest.issues.createComment({
owner: github.context.repo.owner, owner: github.context.repo.owner,
repo: github.context.repo.repo, repo: github.context.repo.repo,
@@ -122,6 +145,8 @@ jobs:
body: `Our automation found one or more issues with this submission:\n` body: `Our automation found one or more issues with this submission:\n`
+ issues.map(i => `- ${i.replace('\n', '\n ')}`).join('\n'), + issues.map(i => `- ${i.replace('\n', '\n ')}`).join('\n'),
}); });
console.log(" Applying label 'invalid'...")
await github.rest.issues.addLabels({ await github.rest.issues.addLabels({
owner: github.context.repo.owner, owner: github.context.repo.owner,
repo: github.context.repo.repo, repo: github.context.repo.repo,
@@ -130,6 +155,7 @@ jobs:
}); });
if (close) { if (close) {
console.log(' Auto-closing PR...')
await github.rest.pulls.update({ await github.rest.pulls.update({
owner: github.context.repo.owner, owner: github.context.repo.owner,
repo: github.context.repo.repo, repo: github.context.repo.repo,