-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: cache handling and improve cache action logs (#46)
* fix: use getBooleanInput and add logging * chore: update dist build
- Loading branch information
Showing
8 changed files
with
153 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,41 @@ | ||
const { saveCache } = require("./cache.js"); | ||
const core = require("@actions/core"); | ||
|
||
async function save() { | ||
await saveCache(); | ||
} | ||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in | ||
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to | ||
// throw an uncaught exception. Instead of failing this action, just warn. | ||
process.on("uncaughtException", (e) => { | ||
const warningPrefix = "[warning]"; | ||
core.info(`${warningPrefix}${e.message}`); | ||
}); | ||
|
||
// Added early exit to resolve issue with slow post action step: | ||
// - https://github.com/actions/setup-node/issues/878 | ||
// https://github.com/actions/cache/pull/1217 | ||
async function run(earlyExit) { | ||
try { | ||
const cacheInput = core.getBooleanInput("cache"); | ||
if (cacheInput) { | ||
await saveCache(); | ||
} else { | ||
core.info("Cache not requested, not saving cache"); | ||
} | ||
|
||
module.exports = save; | ||
if (earlyExit) { | ||
process.exit(0); | ||
} | ||
} catch (error) { | ||
let message = "Unknown error!"; | ||
if (error instanceof Error) { | ||
message = error.message; | ||
} | ||
if (typeof error === "string") { | ||
message = error; | ||
} | ||
core.warning(message); | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
save(); | ||
run(true); | ||
} |