Skip to content

Commit

Permalink
ugly
Browse files Browse the repository at this point in the history
  • Loading branch information
dacbd committed Jul 21, 2022
1 parent 2acfde5 commit 543543b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/cml/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ const run = async (opts) => {
winston.warn(
'Github Actions timeout has been updated from 72h to 35 days. Update your workflow accordingly to be able to restart it automatically.'
);
await cml.workflowCheck();
}

winston.info(`Preparing workdir ${workdir}...`);
Expand Down
4 changes: 4 additions & 0 deletions src/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,10 @@ Automated commits for ${this.repo}/commit/${sha} created by CML.
return renderPr(url);
}

async workflowCheck() {
return await getDriver(this).workflowCheck();
}

async pipelineRerun(opts) {
return await getDriver(this).pipelineRerun(opts);
}
Expand Down
71 changes: 71 additions & 0 deletions src/drivers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,77 @@ class Github {
return GITHUB_SHA;
}

async workflowCheck() {
const WARNINGS = [];
const _DIR = '.github/workflows/';
const yaml = require('js-yaml');
const files = await fs.readdir(_DIR);
for (const file of files) {
const rawStr = await fs.readFile(`${_DIR}${file}`, 'utf8');
const doc = yaml.load(rawStr);
Object.keys(doc.jobs).forEach((job) => {
// does job contain timeout?
const timeoutVal = doc.jobs[job]['timeout-minutes'];
if (timeoutVal === undefined) return;

// does job have label runs-on "self-hosted" or "cml"
const runsOn = doc.jobs[job]['runs-on'];
switch (typeof runsOn) {
case 'string':
if (
runsOn !== 'self-hosted' &&
!runsOn.toLocaleLowerCase().includes('cml')
)
return;
break;
case 'object':
if (!Array.isArray(runsOn)) return; // shouldnt happen
if (
!runsOn
.map((v) => {
return (
v === 'self-hosted' || v.toLocaleLowerCase().includes('cml')
);
})
.reduce((pv, v) => pv || v)
) {
return;
}
break;
default:
return;
}

console.log('found timeout in job:', job);
// locate timeout for warning
const warning = (function (find) {
const lines = rawStr.split('\n');
for (const i in lines) {
if (lines[i].includes(find[0])) {
find.shift();
if (find.length === 0) {
return parseInt(i) + 1;
}
}
}
return -1;
})([`${job}:`, 'timeout-minutes:']);
if (warning !== -1) {
WARNINGS.push({
file: `${_DIR}${file}`,
line: warning
});
}
});
}
for (const warning of WARNINGS) {
console.log(
`::warning file=${warning.file},line=${warning.line},title=Possible Unexpected Behavoir using \`cml runner\`::GitHub Actions has updated timeout-minutes if your job is unlikely to longer than 6hrs then you should remove timeout-minutes, to have cml auto-restart for long training jobs change this value to: 50400 (35d)`
);
}
process.exit();
}

get branch() {
return branchName(GITHUB_HEAD_REF || GITHUB_REF);
}
Expand Down

1 comment on commit 543543b

@github-actions

This comment was marked as outdated.

Please sign in to comment.