From 67e7d24a8bee55ea1cd8dd4f8f4248770b2e2b00 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 21 Apr 2023 21:14:22 -0700 Subject: [PATCH] feat: check for the setup-cpp updates and notify --- .prettierignore | 1 - package.json | 11 +++++++++-- src/check-updates.ts | 15 +++++++++++++++ src/main.ts | 6 ++++++ 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/check-updates.ts diff --git a/.prettierignore b/.prettierignore index 024b5bf2..1f9b46de 100644 --- a/.prettierignore +++ b/.prettierignore @@ -7,4 +7,3 @@ stats.html src/python/setup-python/ src/msvc/msvc-dev-cmd/ dev/cpp_vcpkg_project -package.json diff --git a/package.json b/package.json index aecf96ee..64b27807 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,9 @@ "test.unit": "jest --runInBand" }, "prettier": "prettier-config-atomic", + "dependencies": { + "update-notifier": "^6.0.2" + }, "devDependencies": { "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", @@ -153,7 +156,9 @@ "engines": { "node": ">=12.x" }, - "includeNodeModules": true, + "includeNodeModules": { + "update-notifier": false + }, "optimize": true, "outputFormat": "commonjs" }, @@ -162,7 +167,9 @@ "engines": { "node": ">=16.x" }, - "includeNodeModules": true, + "includeNodeModules": { + "update-notifier": false + }, "optimize": true, "outputFormat": "commonjs" } diff --git a/src/check-updates.ts b/src/check-updates.ts new file mode 100644 index 00000000..94b8c9ae --- /dev/null +++ b/src/check-updates.ts @@ -0,0 +1,15 @@ +import { warning } from "ci-log" +import { readFile } from "fs/promises" +import { join } from "path" + +// auto self update notifier +export async function checkUpdates() { + try { + const updateNotifier = (await import("update-notifier")).default + const packageJsonString = await readFile(join(__dirname, "..", "package.json"), "utf8") + const packageJson = JSON.parse(packageJsonString) + updateNotifier({ pkg: packageJson }).notify() + } catch (err) { + warning(`Failed to check for updates: ${err}`) + } +} diff --git a/src/main.ts b/src/main.ts index 40e6c71f..242eeda8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,6 +16,7 @@ import { untildifyUser } from "untildify-user" import { setupBazel } from "./bazel/bazel" import { setupBrew } from "./brew/brew" import { setupCcache } from "./ccache/ccache" +import { checkUpdates } from "./check-updates" import { setupChocolatey } from "./chocolatey/chocolatey" import { setupCmake } from "./cmake/cmake" import { setupConan } from "./conan/conan" @@ -89,7 +90,9 @@ const inputs: Array = ["compiler", "architecture", ...tools] /** The main entry function */ export async function main(args: string[]): Promise { + let checkUpdatePromise = Promise.resolve() if (!GITHUB_ACTIONS) { + checkUpdatePromise = checkUpdates() process.env.ACTIONS_ALLOW_UNSECURE_COMMANDS = "true" } @@ -297,8 +300,11 @@ export async function main(args: string[]): Promise { } } + await checkUpdatePromise + return errorMessages.length === 0 ? 0 : 1 // exit with non-zero if any error message } + // Run main main(process.argv) .then((ret) => {