diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e1583d9..8c4f477d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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] diff --git a/dist/index.js b/dist/index.js index 7c268e68..7f37bcb0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -107951,7 +107951,7 @@ async function restoreCache(key, restoreKeys, paths) { lib_core.info(`Cache restored from key: ${cacheKey}`); } else { - lib_core.info(`Cache not found for input keys: ${[key, ...restoreKeys].join(", ")}`); + lib_core.info(`Cache is not found for input keys: ${[key, ...restoreKeys].join(", ")}`); } return cacheKey; } diff --git a/dist/post/index.js b/dist/post/index.js index fbbb7f2b..635a4516 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -87479,7 +87479,7 @@ async function restoreCache(key, restoreKeys, paths) { core.info(`Cache restored from key: ${cacheKey}`); } else { - core.info(`Cache not found for input keys: ${[key, ...restoreKeys].join(", ")}`); + core.info(`Cache is not found for input keys: ${[key, ...restoreKeys].join(", ")}`); } return cacheKey; } diff --git a/lint-fmt/dist/index.js b/lint-fmt/dist/index.js index 132bf037..0c07f72b 100644 --- a/lint-fmt/dist/index.js +++ b/lint-fmt/dist/index.js @@ -27942,25 +27942,32 @@ function convertToUnix(str) { async function parse() { const githubWorkspace = external_node_process_namespaceObject.env.GITHUB_WORKSPACE ?? external_node_process_namespaceObject.cwd(); const fpath = external_node_path_namespaceObject.join(githubWorkspace, ".ocamlformat"); - const buf = await external_node_fs_namespaceObject.promises.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 external_node_fs_namespaceObject.promises.access(fpath, external_node_fs_namespaceObject.promises.constants.R_OK); + const buf = await external_node_fs_namespaceObject.promises.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 = Object.fromEntries(kv); + return config; + } + catch { + return; + } } 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; } ;// CONCATENATED MODULE: ./src/opam.ts diff --git a/packages/lint-fmt/src/ocamlformat.ts b/packages/lint-fmt/src/ocamlformat.ts index 2c65e845..2d6e98d6 100644 --- a/packages/lint-fmt/src/ocamlformat.ts +++ b/packages/lint-fmt/src/ocamlformat.ts @@ -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 = 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; } diff --git a/packages/setup-ocaml/src/cache.ts b/packages/setup-ocaml/src/cache.ts index 5a7054dd..62f194c7 100644 --- a/packages/setup-ocaml/src/cache.ts +++ b/packages/setup-ocaml/src/cache.ts @@ -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;