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 2ce0a3c
Show file tree
Hide file tree
Showing 6 changed files with 51 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.

35 changes: 21 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.

38 changes: 22 additions & 16 deletions packages/lint-fmt/src/ocamlformat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,32 @@ 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 kv = normalisedStr
.split("\n")
.map((line) => line.split("=").map((str) => str.trim()));
const config: Record<string, string> = Object.fromEntries(kv);
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 file is not found");
return;
}
return version;
if (config.version) {
return config.version;
}
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 2ce0a3c

Please sign in to comment.