generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
689c538
commit 55eca19
Showing
1 changed file
with
62 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,87 @@ | ||
import {join, dirname} from "path"; | ||
import {parse} from "toml"; | ||
import {readFile, existsSync} from "fs"; | ||
import { join, dirname } from "path"; | ||
import { parse } from "toml"; | ||
import { readFile, existsSync } from "fs"; | ||
import { dir } from "console"; | ||
Check failure on line 4 in src/configFile.ts GitHub Actions / Test setup-foreman action (ubuntu-latest)
|
||
interface foremanConfig { | ||
tools: foremanTool[]; | ||
tools: foremanTool[]; | ||
} | ||
|
||
interface foremanTool { | ||
source?: string; | ||
github?: string; | ||
gitlab?: string; | ||
version: string; | ||
source?: string; | ||
github?: string; | ||
gitlab?: string; | ||
version: string; | ||
} | ||
|
||
const MANIFEST = "foreman.toml"; | ||
|
||
function findManifestPath(): string | null { | ||
let directory = __dirname; | ||
while (true) { | ||
if (!directory) { | ||
break; | ||
let directory = __dirname; | ||
while (directory != "/") { | ||
const configFilePath = join(directory, MANIFEST); | ||
if (existsSync(configFilePath)) { | ||
return configFilePath; | ||
} else { | ||
directory = dirname(directory); | ||
} | ||
} | ||
const configFilePath = join(directory, MANIFEST); | ||
if (existsSync(configFilePath)) { | ||
return configFilePath; | ||
} else { | ||
directory = dirname(directory); | ||
} | ||
} | ||
return null; | ||
return null; | ||
} | ||
|
||
function checkSameOrgToolSpecs(manifestContent: foremanConfig): boolean { | ||
const tools = manifestContent.tools; | ||
if (tools == null) { | ||
throw new Error("Tools section in Foreman config not found"); | ||
} | ||
|
||
const orgs: string[] = []; | ||
for (const tool_name in tools) { | ||
const tool_spec = tools[tool_name]; | ||
let source = tool_spec["source"]; | ||
if (source == null) { | ||
source = tool_spec["github"]; | ||
} | ||
if (source == null) { | ||
continue; | ||
const tools = manifestContent.tools; | ||
if (tools == null) { | ||
throw new Error("Tools section in Foreman config not found"); | ||
} | ||
|
||
const source_array = source.split("/"); | ||
const org = source_array[0]; | ||
const orgs: string[] = []; | ||
for (const tool_name in tools) { | ||
const tool_spec = tools[tool_name]; | ||
let source = tool_spec["source"]; | ||
if (source == null) { | ||
source = tool_spec["github"]; | ||
} | ||
if (source == null) { | ||
continue; | ||
} | ||
|
||
const source_array = source.split("/"); | ||
const org = source_array[0]; | ||
|
||
if (org == null) { | ||
throw new Error( | ||
`Org not found in tool spec definition for: ${tool_name}` | ||
); | ||
if (org == null) { | ||
throw new Error( | ||
`Org not found in tool spec definition for: ${tool_name}` | ||
); | ||
} | ||
orgs.push(org.toLowerCase()); | ||
} | ||
orgs.push(org.toLowerCase()); | ||
} | ||
if (orgs.length == 0) { | ||
return true; | ||
} | ||
return orgs.every(val => val === orgs[0]); | ||
if (orgs.length == 0) { | ||
return true; | ||
} | ||
return orgs.every(val => val === orgs[0]); | ||
} | ||
|
||
async function checkSameOrgInConfig(): Promise<void> { | ||
const manifestPath = findManifestPath(); | ||
if (manifestPath == null) { | ||
throw new Error("Foreman config file could not be found"); | ||
} | ||
|
||
await readFile(manifestPath, "utf8", (err, data) => { | ||
if (err) { | ||
throw new Error("Could not read Foreman config file"); | ||
const manifestPath = findManifestPath(); | ||
if (manifestPath == null) { | ||
throw new Error("Foreman config file could not be found"); | ||
} | ||
{ | ||
const manifestContent = parse(data); | ||
const sameGithubOrgSource = checkSameOrgToolSpecs(manifestContent); | ||
if (sameGithubOrgSource == false) { | ||
throw new Error("Not all GitHub orgs are the same"); | ||
} | ||
} | ||
}); | ||
|
||
await readFile(manifestPath, "utf8", (err, data) => { | ||
if (err) { | ||
throw new Error("Could not read Foreman config file"); | ||
} | ||
{ | ||
const manifestContent = parse(data); | ||
const sameGithubOrgSource = checkSameOrgToolSpecs(manifestContent); | ||
if (sameGithubOrgSource == false) { | ||
throw new Error("Not all GitHub orgs are the same"); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
export default { | ||
checkSameOrgInConfig, | ||
checkSameOrgToolSpecs | ||
checkSameOrgInConfig, | ||
checkSameOrgToolSpecs | ||
}; |