Skip to content

Commit 7d63ebe

Browse files
authored
Merge pull request #836 from ocaml/fix-lint-fmt
Do not throw an error even if the `.ocamlformat` is not found
2 parents f8143a0 + 2ce0a3c commit 7d63ebe

File tree

6 files changed

+51
-34
lines changed

6 files changed

+51
-34
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to
88

99
## [unreleased]
1010

11+
### Fixed
12+
13+
- Do not throw an error even if the .ocamlformat file is not found.
14+
1115
## [3.0.1]
1216

1317
### Fixed
@@ -342,7 +346,7 @@ and this project adheres to
342346

343347
### Fixed
344348

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

347351
## [2.0.0-beta12]
348352

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/post/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lint-fmt/dist/index.js

+21-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/lint-fmt/src/ocamlformat.ts

+22-16
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,32 @@ import { convertToUnix } from "./compat.js";
77
async function parse() {
88
const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd();
99
const fpath = path.join(githubWorkspace, ".ocamlformat");
10-
const buf = await fs.readFile(fpath);
11-
const str = buf.toString();
12-
const normalisedStr = convertToUnix(str);
13-
const config = normalisedStr
14-
.split("\n")
15-
.map((line) => line.split("=").map((str) => str.trim()));
16-
return config;
10+
try {
11+
await fs.access(fpath, fs.constants.R_OK);
12+
const buf = await fs.readFile(fpath);
13+
const str = buf.toString();
14+
const normalisedStr = convertToUnix(str);
15+
const kv = normalisedStr
16+
.split("\n")
17+
.map((line) => line.split("=").map((str) => str.trim()));
18+
const config: Record<string, string> = Object.fromEntries(kv);
19+
return config;
20+
} catch {
21+
return;
22+
}
1723
}
1824

1925
export async function getOcamlformatVersion() {
2026
const config = await parse();
21-
const version = config
22-
.filter((line) => line.at(0) === "version")
23-
.flat()
24-
.at(1);
25-
if (!version) {
26-
core.warning(
27-
"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",
28-
);
27+
if (config === undefined) {
28+
core.warning(".ocamlformat file is not found");
2929
return;
3030
}
31-
return version;
31+
if (config.version) {
32+
return config.version;
33+
}
34+
core.warning(
35+
"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",
36+
);
37+
return;
3238
}

packages/setup-ocaml/src/cache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async function restoreCache(
119119
core.info(`Cache restored from key: ${cacheKey}`);
120120
} else {
121121
core.info(
122-
`Cache not found for input keys: ${[key, ...restoreKeys].join(", ")}`,
122+
`Cache is not found for input keys: ${[key, ...restoreKeys].join(", ")}`,
123123
);
124124
}
125125
return cacheKey;

0 commit comments

Comments
 (0)