Skip to content

Commit

Permalink
Guess os_distros if none is specified to bot
Browse files Browse the repository at this point in the history
  • Loading branch information
cartermckinnon committed Apr 4, 2024
1 parent 761c8d2 commit adec708
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/actions/bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,41 @@ class CICommand {
this.goal_args[goal] = args;
}

// a map of file path prefixes to OS distros that are associated with the file paths
// a value of "*" implies multiple OS distros are associated with the path, and we should just rely on the workflow's default
// a value of null means no OS distros are associated with the path
osDistroPathPrefixHints = {
"templates/al2/": "al2",
"templates/al2023/": "al2023",
"templates/shared/": "*",
"nodeadm/": "al2023",
"doc/": null,
};

async guessOsDistrosForChangedFiles(github) {
const files = await github.rest.pulls.listFiles({
owner: this.repository_owner,
repo: this.repository_name,
pull_number: this.pr_number
});
let osDistros = [];
for (const file of files) {
for (const prefix of osDistroPathPrefixHints) {
if (file.filename.startsWith(prefix)) {
osDistros = osDistros.concat(this.osDistroPathPrefixHints[prefix]);
} else {
console.log("file does not match an OS distro hint, not attempting to guess os_distros!");
return null;
}
}
}
if (osDistros.length != 1) {
console.log("changed files matched more than one OS distro prefix, not attempting to guess os_distros!");
return null;
}
return osDistros[0];
}

async run(author, github) {
const pr = await github.rest.pulls.get({
owner: this.repository_owner,
Expand Down Expand Up @@ -198,6 +233,12 @@ class CICommand {
inputs[`${goal}_arguments`] = args;
}
}
if (!inputs.hasOwnProperty('os_distros')) {
osDistros = await this.guessOsDistrosForChangedFiles(github);
if (osDistros != null) {
inputs['os_distros'] = osDistros;
}
}
console.log(`Dispatching workflow with inputs: ${JSON.stringify(inputs)}`);
await github.rest.actions.createWorkflowDispatch({
owner: this.repository_owner,
Expand Down

0 comments on commit adec708

Please sign in to comment.