Skip to content

Commit

Permalink
Do not throw an error even if the .ocamlformat is not found
Browse files Browse the repository at this point in the history
Signed-off-by: Sora Morimoto <sora@morimoto.io>
  • Loading branch information
smorimoto committed Aug 4, 2024
1 parent f8143a0 commit 9726f56
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 34 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to

## [unreleased]

### Fixed

- Do not throw an error even if the .ocamlformat file is not found.

## [3.0.1]

### Fixed
Expand Down Expand Up @@ -342,7 +346,7 @@ and this project adheres to

### Fixed

- Print a proper error if the version not found in the `.ocamlformat` file.
- Print a proper error if the version is not found in the `.ocamlformat` file.

## [2.0.0-beta12]

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

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

2 changes: 1 addition & 1 deletion dist/post/index.js

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

36 changes: 22 additions & 14 deletions lint-fmt/dist/index.js

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

43 changes: 27 additions & 16 deletions packages/lint-fmt/src/ocamlformat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,37 @@ import { convertToUnix } from "./compat.js";
async function parse() {
const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd();
const fpath = path.join(githubWorkspace, ".ocamlformat");
const buf = await fs.readFile(fpath);
const str = buf.toString();
const normalisedStr = convertToUnix(str);
const config = normalisedStr
.split("\n")
.map((line) => line.split("=").map((str) => str.trim()));
return config;
try {
await fs.access(fpath, fs.constants.R_OK);
const buf = await fs.readFile(fpath);
const str = buf.toString();
const normalisedStr = convertToUnix(str);
const config = normalisedStr
.split("\n")
.map((line) => line.split("=").map((str) => str.trim()));
return config;
} catch {
return;
}
}

export async function getOcamlformatVersion() {
const config = await parse();
const version = config
.filter((line) => line.at(0) === "version")
.flat()
.at(1);
if (!version) {
core.warning(
"Field version not found in .ocamlformat file: setting up your project to use the default profile and the OCamlFormat version you installed in .ocamlformat file is considered good practice",
);

if (config === undefined) {
core.warning(".ocamlformat is not found");
return;
}
return version;

for (const [key, value] of config) {
if (key === "version") {
return value;
}
}

core.warning(
"ocamlformat version is not found in .ocamlformat: setting up your project to use the default profile and the ocamlformat version you installed in .ocamlformat file is considered good practice",
);

return;
}
2 changes: 1 addition & 1 deletion packages/setup-ocaml/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async function restoreCache(
core.info(`Cache restored from key: ${cacheKey}`);
} else {
core.info(
`Cache not found for input keys: ${[key, ...restoreKeys].join(", ")}`,
`Cache is not found for input keys: ${[key, ...restoreKeys].join(", ")}`,
);
}
return cacheKey;
Expand Down

0 comments on commit 9726f56

Please sign in to comment.