Skip to content

Commit 3ce1db2

Browse files
committed
fix: add option for setup-cpp cli install
1 parent 1d824aa commit 3ce1db2

File tree

9 files changed

+29
-16
lines changed

9 files changed

+29
-16
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Setting up a **cross-platform** environment for building and testing C++/C proje
3131
| --------------- | ----------------------------------------------------------------------------------------------------------- |
3232
| compiler | llvm, gcc, msvc, apple-clang, vcvarsall |
3333
| build system | cmake, ninja, meson, make, task, bazel |
34-
| package manager | vcpkg, conan, choco, brew, nala |
34+
| package manager | vcpkg, conan, choco, brew, nala, setup-cpp |
3535
| analyzer/linter | clang-tidy, clang-format, cppcheck, cpplint, flawfinder, lizard, infer, cmakelang, cmake-format, cmake-lint |
3636
| cache | ccache, sccache |
3737
| documentation | doxygen, graphviz |
@@ -195,11 +195,14 @@ jobs:
195195
cppcheck: true # instead of `true`, which chooses the default version, you can pass a specific version.
196196
```
197197
198-
When using the `setup-cpp` action in GitHub Actions, it will also install the `setup-cpp` CLI, which you can use in the subsequent commands if needed:
198+
When using the `setup-cpp` action in GitHub Actions, by default it will also install the `setup-cpp` CLI, which you can use in the subsequent commands. You can modify the default behaviour if needed.
199199

200200
```yaml
201201
- name: Setup Cpp
202202
uses: aminya/setup-cpp@v1
203+
with:
204+
setup-cpp: true
205+
node-package-manager: "npm"
203206
204207
- name: Use Setup Cpp CLI
205208
run: setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ inputs:
157157
python:
158158
description: "Wether to install python (true/false) or the specific version to install."
159159
required: false
160-
nodePackageManager:
160+
setup-cpp:
161+
description: "Wether to install setup-cpp (true/false) or the specific version to install. (Default to the current version called by the action)"
162+
required: false
163+
node-package-manager:
161164
description: "The node package manager to use (npm/yarn/pnpm) when installing setup-cpp globally"
162165
required: false
163166

dist/legacy/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli-options.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import { type Inputs, inputs } from "./tool.js"
66
import type { InstallationInfo } from "./utils/setup/setupBin.js"
77

88
export function parseArgs(args: string[]): Opts {
9-
return mri<Record<Inputs, string | undefined> & { help: boolean; version: boolean }>(args, {
10-
string: [...inputs, "timeout", "nodePackageManager"],
11-
default: Object.fromEntries(inputs.map((inp) => [inp, maybeGetInput(inp)])),
9+
const defaults = Object.fromEntries(inputs.map((inp) => [inp, maybeGetInput(inp)]))
10+
defaults["setup-cpp"] = "true"
11+
12+
return mri<Record<Inputs, string | undefined> & { help: boolean; version: boolean; "setup-cpp": boolean }>(args, {
13+
string: [...inputs, "timeout", "node-package-manager"],
14+
default: defaults,
1215
alias: { h: "help", v: "version" },
13-
boolean: ["help", "version"],
16+
boolean: ["help", "version", "setup-cpp"],
1417
})
1518
}
1619

@@ -41,7 +44,7 @@ All the available tools:
4144
"build system": {
4245
tools: "--cmake, --ninja, --meson, --make, --task, --bazel",
4346
},
44-
"package manager": { tools: "--vcpkg, --conan, --choco, --brew, --nala" },
47+
"package manager": { tools: "--vcpkg, --conan, --choco, --brew, --nala, --setup-cpp" },
4548
"analyzer/linter": {
4649
tools:
4750
"--clang-tidy, --clang-format, --cppcheck, --cpplint, --flawfinder, --lizard, --infer, , --cmakelang, --cmake-lint, --cmake-format",
@@ -67,8 +70,9 @@ export type Opts = mri.Argv<
6770
Record<Inputs, string | undefined> & {
6871
help: boolean
6972
version: boolean
73+
"setup-cpp": boolean
7074
timeout?: string
71-
nodePackageManager?: string
75+
"node-package-manager"?: string
7276
}
7377
>
7478

src/setup-cpp-installer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { error, info } from "ci-log"
22
import { execa } from "execa"
3+
import which from "which"
34
/**
45
* Install the setup-cpp CLI globally
56
* @param version - The version of setup-cpp to install
@@ -8,8 +9,8 @@ import { execa } from "execa"
89
export async function installSetupCpp(version: string, packageManager: string = "npm") {
910
try {
1011
// check if `setup-cpp` is available in the shell, if so, skip the installation to avoid overwriting the existing version
11-
const { stdout } = await execa("setup-cpp", ["--version"])
12-
if (stdout) {
12+
const setupCppPath = await which("setup-cpp", { nothrow: true })
13+
if (setupCppPath !== null) {
1314
return
1415
}
1516

src/setup-cpp.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ async function main(args: string[]): Promise<number> {
2828
// parse options using mri or github actions
2929
const opts = parseArgs(args)
3030

31-
const installSetupCppPromise = installSetupCpp(packageJson.version, opts.nodePackageManager)
31+
const installSetupCppPromise = opts["setup-cpp"]
32+
? installSetupCpp(packageJson.version, opts["node-package-manager"])
33+
: Promise.resolve()
3234

3335
// print help
3436
if (opts.help) {

0 commit comments

Comments
 (0)