Skip to content

Commit 67e7d24

Browse files
committed
feat: check for the setup-cpp updates and notify
1 parent 6e6418d commit 67e7d24

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ stats.html
77
src/python/setup-python/
88
src/msvc/msvc-dev-cmd/
99
dev/cpp_vcpkg_project
10-
package.json

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
"test.unit": "jest --runInBand"
6060
},
6161
"prettier": "prettier-config-atomic",
62+
"dependencies": {
63+
"update-notifier": "^6.0.2"
64+
},
6265
"devDependencies": {
6366
"@actions/core": "^1.10.0",
6467
"@actions/exec": "^1.1.1",
@@ -153,7 +156,9 @@
153156
"engines": {
154157
"node": ">=12.x"
155158
},
156-
"includeNodeModules": true,
159+
"includeNodeModules": {
160+
"update-notifier": false
161+
},
157162
"optimize": true,
158163
"outputFormat": "commonjs"
159164
},
@@ -162,7 +167,9 @@
162167
"engines": {
163168
"node": ">=16.x"
164169
},
165-
"includeNodeModules": true,
170+
"includeNodeModules": {
171+
"update-notifier": false
172+
},
166173
"optimize": true,
167174
"outputFormat": "commonjs"
168175
}

src/check-updates.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { warning } from "ci-log"
2+
import { readFile } from "fs/promises"
3+
import { join } from "path"
4+
5+
// auto self update notifier
6+
export async function checkUpdates() {
7+
try {
8+
const updateNotifier = (await import("update-notifier")).default
9+
const packageJsonString = await readFile(join(__dirname, "..", "package.json"), "utf8")
10+
const packageJson = JSON.parse(packageJsonString)
11+
updateNotifier({ pkg: packageJson }).notify()
12+
} catch (err) {
13+
warning(`Failed to check for updates: ${err}`)
14+
}
15+
}

src/main.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { untildifyUser } from "untildify-user"
1616
import { setupBazel } from "./bazel/bazel"
1717
import { setupBrew } from "./brew/brew"
1818
import { setupCcache } from "./ccache/ccache"
19+
import { checkUpdates } from "./check-updates"
1920
import { setupChocolatey } from "./chocolatey/chocolatey"
2021
import { setupCmake } from "./cmake/cmake"
2122
import { setupConan } from "./conan/conan"
@@ -89,7 +90,9 @@ const inputs: Array<Inputs> = ["compiler", "architecture", ...tools]
8990

9091
/** The main entry function */
9192
export async function main(args: string[]): Promise<number> {
93+
let checkUpdatePromise = Promise.resolve()
9294
if (!GITHUB_ACTIONS) {
95+
checkUpdatePromise = checkUpdates()
9396
process.env.ACTIONS_ALLOW_UNSECURE_COMMANDS = "true"
9497
}
9598

@@ -297,8 +300,11 @@ export async function main(args: string[]): Promise<number> {
297300
}
298301
}
299302

303+
await checkUpdatePromise
304+
300305
return errorMessages.length === 0 ? 0 : 1 // exit with non-zero if any error message
301306
}
307+
302308
// Run main
303309
main(process.argv)
304310
.then((ret) => {

0 commit comments

Comments
 (0)