Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not throw an error even if the .ocamlformat is not found #836

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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