Skip to content

Commit

Permalink
use find-up library instead of going up parent directories ourselves
Browse files Browse the repository at this point in the history
  • Loading branch information
afujiwara-roblox committed Sep 28, 2023
1 parent eb6c4ea commit ba6fdd5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 59 deletions.
2 changes: 1 addition & 1 deletion __tests__/hello.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// who needs tests?
import configFile from "../src/configFile";
import { parse } from "toml";
import {parse} from "toml";

test("get off my back, Jest", () => {
expect(5).toEqual(5);
Expand Down
55 changes: 25 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@actions/github": "^2.1.1",
"@actions/tool-cache": "^1.3.1",
"axios": "^0.21.2",
"find-up": "5.0.0",
"semver": "^7.1.3",
"toml": "^3.0.0"
},
Expand Down
31 changes: 8 additions & 23 deletions src/configFile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {join, dirname} from "path";
import {parse} from "toml";
import {readFile, existsSync} from "fs";
import { parse } from "toml";
import { readFile } from "fs";
let findUp = require("find-up");

Check failure on line 3 in src/configFile.ts

View workflow job for this annotation

GitHub Actions / Test setup-foreman action (ubuntu-latest)

'findUp' is never reassigned. Use 'const' instead

Check failure on line 3 in src/configFile.ts

View workflow job for this annotation

GitHub Actions / Test setup-foreman action (ubuntu-latest)

Require statement not part of import statement

Check failure on line 3 in src/configFile.ts

View workflow job for this annotation

GitHub Actions / Test setup-foreman action with working-directory (ubuntu-latest)

'findUp' is never reassigned. Use 'const' instead

Check failure on line 3 in src/configFile.ts

View workflow job for this annotation

GitHub Actions / Test setup-foreman action with working-directory (ubuntu-latest)

Require statement not part of import statement
interface foremanConfig {
tools: foremanTool[];
}
Expand All @@ -14,19 +14,6 @@ interface foremanTool {

const MANIFEST = "foreman.toml";

function findManifestPath(): string | null {
let directory = __dirname;
while (directory != "/") {
const configFilePath = join(directory, MANIFEST);
if (existsSync(configFilePath)) {
return configFilePath;
} else {
directory = dirname(directory);
}
}
return null;
}

function checkSameOrgToolSpecs(manifestContent: foremanConfig): boolean {
const tools = manifestContent.tools;
if (tools == null) {
Expand Down Expand Up @@ -61,7 +48,7 @@ function checkSameOrgToolSpecs(manifestContent: foremanConfig): boolean {
}

async function checkSameOrgInConfig(): Promise<void> {
const manifestPath = findManifestPath();
const manifestPath = await findUp(MANIFEST);
if (manifestPath == null) {
throw new Error("Foreman config file could not be found");
}
Expand All @@ -70,12 +57,10 @@ async function checkSameOrgInConfig(): Promise<void> {
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");
}
const manifestContent = parse(data);
const sameGithubOrgSource = checkSameOrgToolSpecs(manifestContent);
if (sameGithubOrgSource == false) {
throw new Error("Not all GitHub orgs are the same");
}
});
}
Expand Down
10 changes: 5 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {getInput, debug, addPath, setFailed} from "@actions/core";
import {downloadTool, extractZip} from "@actions/tool-cache";
import {GitHub} from "@actions/github";
import {resolve} from "path";
import {exec} from "@actions/exec";
import { getInput, debug, addPath, setFailed } from "@actions/core";
import { downloadTool, extractZip } from "@actions/tool-cache";
import { GitHub } from "@actions/github";
import { resolve } from "path";
import { exec } from "@actions/exec";
import configFile from "./configFile";
import foreman from "./foreman";

Expand Down

0 comments on commit ba6fdd5

Please sign in to comment.