Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the utils functions to separate packages #114

Merged
merged 29 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
46635fc
feat: add exec-powershell package
aminya Aug 7, 2022
4c866cd
fix: use exec-powershell in setup-cpp
aminya Aug 8, 2022
fe2db9d
feat: add sudo-tools package
aminya Aug 8, 2022
2996940
fix: use sudo-tools in setup-cpp
aminya Aug 8, 2022
bf519e6
fix: rename execSudo to execRoot and isRoot to isSudo
aminya Aug 8, 2022
860880c
feat: add isRoot function in addition to isSudo
aminya Aug 8, 2022
2cdfbab
fix: do not cache isSudo
aminya Aug 8, 2022
0d99c85
fix: do not assume that CI (e.g. Docker) is root
aminya Aug 8, 2022
e495d4d
fix: rename execRoot to execRootSync
aminya Aug 8, 2022
897c5f6
feat: add async execRoot
aminya Aug 8, 2022
92711bc
feat: add sync execPowershell
aminya Aug 8, 2022
b77e674
fix: rename sudo-tools to root-tools
aminya Aug 8, 2022
758bb59
docs: automatically create the readme for the packages
aminya Aug 8, 2022
277b6cc
feat: add extension-tools package
aminya Aug 8, 2022
41bcd6a
Revert "fix: do not assume that CI (e.g. Docker) is root"
aminya Aug 8, 2022
c5a2f11
fix: use extension-tools in setup-cpp
aminya Aug 8, 2022
88c2d1a
fix: use ci-detect instead of isCI
aminya Aug 8, 2022
f8515df
fix: set shell: true for execRoot
aminya Aug 8, 2022
3d08c16
fix: fix github-actions detection
aminya Aug 8, 2022
6dd9d76
fix: add types for escape-path-with-spaces
aminya Aug 8, 2022
a0ead74
fix: fix the root-tools folder name
aminya Aug 8, 2022
b4a8389
feat: add untildify-user package
aminya Aug 8, 2022
b38bf66
feat: add user-access package
aminya Aug 8, 2022
232af3c
fix: use is-url-online to validate the download links
aminya Aug 8, 2022
edc37d2
Revert "fix: use is-url-online to validate the download links"
aminya Aug 8, 2022
0bbdead
feat: use is-link-working to test the urls
aminya Aug 8, 2022
91ab4d1
fix: use is-link-working fork
aminya Aug 8, 2022
4d3cf92
feat: add get-works package to validate the URLs
aminya Aug 8, 2022
1df74e7
docs: add readme for get-works [skip ci]
aminya Aug 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ temp-*
*.tsbuildinfo

# Build directories
./dist/
!./dist/setup_cpp.js
!./dist/setup_cpp.js.map
packages/*/dist/
.parcel-cache
exe/
*.log
*.exe
.cache/
.cache/
5 changes: 3 additions & 2 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ words:
- applellvm
- bazel
- bazelisk
- copr
- vbatts
- buildtools
- caxa
- ccache
- choco
- cmake
- copr
- CPATH
- Cppcheck
- CPPFLAGS
Expand All @@ -38,6 +37,7 @@ words:
- ghes
- Graphviz
- isci
- isroot
- kcov
- LDFLAGS
- lefticus
Expand Down Expand Up @@ -68,6 +68,7 @@ words:
- tsbuildinfo
- ucrt
- untildify
- vbatts
- vcpkg
- vcvarsall
- visualc
Expand Down
61 changes: 61 additions & 0 deletions dev/readme/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<h1 align="center"><%= projectName %></h1>
<p>
<% if (isProjectOnNpm) { -%>
<a href="https://www.npmjs.com/package/<%= projectName %>" target="_blank">
<img alt="Version" src="https://img.shields.io/npm/v/<%= projectName %>.svg">
</a>
<% } -%>
<% if (projectVersion && !isProjectOnNpm) { -%>
<img alt="Version" src="https://img.shields.io/badge/version-<%= projectVersion %>-blue.svg?cacheSeconds=2592000" />
<% } -%>
<% if (projectPrerequisites) { -%>
<% projectPrerequisites.map(({ name, value }) => { -%>
<img src="https://img.shields.io/badge/<%= name %>-<%= encodeURIComponent(value) %>-blue.svg" />
<% }) -%>
<% } -%>
<% if (projectDocumentationUrl) { -%>
<a href="<%= projectDocumentationUrl %>" target="_blank">
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
</a>
<% } -%>
<% if (isGithubRepos) { -%>
<a href="<%= repositoryUrl %>/graphs/commit-activity" target="_blank">
<img alt="Maintenance" src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" />
</a>
<% } -%>
<% if (licenseName) { -%>
<a href="<%= licenseUrl ? licenseUrl : '#' %>" target="_blank">
<img alt="License: <%= licenseName %>" src="https://img.shields.io/<%= isGithubRepos ? `github/license/${authorGithubUsername}/${projectName}` : `badge/License-${licenseName}-yellow.svg` %>" />
</a>
<% } -%>
<% if (authorTwitterUsername) { -%>
<a href="https://twitter.com/<%= authorTwitterUsername %>" target="_blank">
<img alt="Twitter: <%= authorTwitterUsername %>" src="https://img.shields.io/twitter/follow/<%= authorTwitterUsername %>.svg?style=social" />
</a>
<% } -%>
</p>
<% if (projectDescription) { -%>

> <%= projectDescription %>
> <% } -%>

## Install

```sh
npm install --save <%= projectName %>
```

## Usage

<!-- INSERT GENERATED DOCS START -->

<!-- INSERT GENERATED DOCS END -->

## 🤝 Contributing

You can sponsor my work here:

https://github.com/sponsors/aminya

Pull requests, issues and feature requests are welcome.
See the [Contributing guide](https://github.com/aminya/setup-cpp/blob/master/CONTRIBUTING.md).
2 changes: 0 additions & 2 deletions dist/actions_python.073441c2.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/actions_python.073441c2.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions dist/actions_python.4e47ab32.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/actions_python.4e47ab32.js.map

This file was deleted.

2 changes: 2 additions & 0 deletions dist/actions_python.dfab21e0.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/actions_python.dfab21e0.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/actions_python.feac98a0.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/actions_python.feac98a0.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.mjs.map

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
"clean": "shx rm -rf .parcel-cache dist exe",
"copy.matchers": "shx cp ./src/gcc/gcc_matcher.json ./dist/ && shx cp ./src/msvc/msvc_matcher.json ./dist && shx cp ./src/python/python_matcher.json ./dist/ && shx cp ./src/llvm/llvm_matcher.json ./dist/ ",
"dev": "cross-env NODE_ENV=development parcel watch",
"docs": "shx rm -rf packages/*/README.md && pnpm -r exec readme --path ../../dev/readme/template.md -y && pnpm -r exec ts-readme",
"format": "run-s lint.prettier",
"lint": "run-p --aggregate-output --continue-on-error lint.cspell lint.eslint lint.prettier lint.tsc",
"lint.cspell": "cspell lint --no-progress --show-suggestions",
"lint.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/ --fix",
"lint.prettier": "prettier --write .",
"lint.tsc": "tsc --noEmit | loose-ts-check",
"pack.exe": "shx rm -rf ./dist/tsconfig.tsbuildinfo && node ./dev/scripts/pack-exe.js",
"prepare": "npm run build",
"prepare": "pnpm run -r build && pnpm run -w build",
"start.docker": "docker run -t setup_cpp .",
"start.docker.arch": "docker run -t setup_cpp:arch .",
"start.docker.fedora": "docker run -t setup_cpp:fedora .",
Expand All @@ -54,16 +55,22 @@
"@actions/exec": "^1.1.1",
"@actions/io": "^1.1.2",
"@actions/tool-cache": "^2.0.1",
"escape-path-with-spaces": "^1.0.0",
"@npmcli/ci-detect": "github:aminya/ci-detect#37fe40075bebec96794ba0a7c4a6d5c70cbea00d",
"escape-path-with-spaces": "github:aminya/escape-path-with-spaces#d9f81ee649203ddc55783a2f96ada59df06118e3",
"exec-powershell": "workspace:*",
"execa": "^5.1.1",
"extension-tools": "workspace:*",
"get-works": "workspace:*",
"mri": "^1.2.0",
"msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1",
"numerous": "1.0.3",
"root-tools": "workspace:*",
"semver": "7.3.7",
"setup-python": "github:actions/setup-python#c474c82340438924daab9282d07300bfe7e3692d",
"time-delta": "github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e",
"ubuntu-version": "^2.0.0",
"untildify": "^4.0.0",
"untildify-user": "workspace:*",
"user-access": "workspace:*",
"which": "^2.0.2"
},
"devDependencies": {
Expand All @@ -79,16 +86,19 @@
"cspell": "^6.5.0",
"eslint": "^8.21.0",
"eslint-config-atomic": "^1.18.1",
"gen-readme": "^1.6.0",
"jest": "^28.1.3",
"loose-ts-check": "^1.2.0",
"npm-check-updates": "^16.0.5",
"npm-run-all2": "^6.0.1",
"parcel": "2.6.2",
"prettier": "2.7.1",
"prettier-config-atomic": "^3.0.10",
"readme-md-generator": "^1.0.0",
"shx": "0.3.4",
"terser-config-atomic": "^0.1.1",
"ts-jest": "^28.0.7",
"ts-readme": "^1.1.3",
"typescript": "^4.7.4"
},
"engines": {
Expand All @@ -113,6 +123,9 @@
"ninja",
"meson"
],
"alias": {
"electron": false
},
"pnpm": {
"overrides": {
"semver": "7.3.7",
Expand Down
60 changes: 60 additions & 0 deletions packages/exec-powershell/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<h1 align="center">exec-powershell</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
<a href="#" target="_blank">
<img alt="License: Apache--2.0" src="https://img.shields.io/badge/License-Apache--2.0-yellow.svg" />
</a>
</p>

> Run a powershell command.

## Install

```sh
npm install --save exec-powershell
```

## Usage

<!-- INSERT GENERATED DOCS START -->

### `execPowershell` (function)

Asynchronously execute a powershell command.

**Parameters:**

- command (`string`) - The powershell command to execute
- startupFlags (`string[]`) - The optional startup flags to be passed to powershell. Defaults to `["-NoProfile", "-NoLogo", "-NonInteractive"]`. This means that the Powershell profile is not sourced first.
- execOptions (`execa.Options`) - The options passed to `execa`. Defaults to `{ stdio: "inherit" }`

**returns:** execa.ExecaChildProcess<string>

### `execPowershellSync` (function)

Execute a powershell command.

**Parameters:**

- command (`string`) - The powershell command to execute
- startupFlags (`string[]`) - The optional startup flags to be passed to powershell. Defaults to `["-NoProfile", "-NoLogo", "-NonInteractive"]`. This means that the Powershell profile is not sourced first.
- execOptions (`execa.SyncOptions`) - The options passed to `execa`. Defaults to `{ stdio: "inherit" }`

**returns:** execa.ExecaSyncReturnValue<string>

### `getPowerShell` (function)

Get the path to the powershell executable.

**returns:** string

<!-- INSERT GENERATED DOCS END -->

## 🤝 Contributing

You can sponsor my work here:

https://github.com/sponsors/aminya

Pull requests, issues and feature requests are welcome.
See the [Contributing guide](https://github.com/aminya/setup-cpp/blob/master/CONTRIBUTING.md).
33 changes: 33 additions & 0 deletions packages/exec-powershell/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "exec-powershell",
"version": "1.0.0",
"description": "Run a powershell command.",
"homepage": "https://github.com/aminya/setup-cpp",
"license": "Apache-2.0",
"author": "Amin Yahyaabadi",
"main": "./dist/index.js",
"source": "./src/index.ts",
"scripts": {
"build": "tsc"
},
"dependencies": {
"execa": "^5.1.1",
"which": "^2.0.2"
},
"devDependencies": {
"@types/which": "^2.0.1"
},
"keywords": [
"powershell",
"pwsh",
"exec",
"execa",
"spawn",
"system",
"github-actions",
"github",
"actions",
"gitlab",
"ci"
]
}
64 changes: 64 additions & 0 deletions packages/exec-powershell/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import execa from "execa"
import which from "which"

/** The cached powershell path */
let powershell: string | undefined

/**
* Asynchronously execute a powershell command.
*
* @param command The powershell command to execute
* @param startupFlags The optional startup flags to be passed to powershell. Defaults to `["-NoProfile", "-NoLogo",
* "-NonInteractive"]`. This means that the Powershell profile is not sourced first.
* @param execOptions The options passed to `execa`. Defaults to `{ stdio: "inherit" }`
* @returns A promise to the execution result
* @note It prefers `pwsh` over `powershell`
*/
export function execPowershell(
command: string,
startupFlags: string[] = ["-NoProfile", "-NoLogo", "-NonInteractive"],
execOptions: execa.Options = { stdio: "inherit" }
): execa.ExecaChildProcess<string> {
return execa(getPowerShell(), [...startupFlags, "-c", command], execOptions)
}

/**
* Execute a powershell command.
*
* @param command The powershell command to execute
* @param startupFlags The optional startup flags to be passed to powershell. Defaults to `["-NoProfile", "-NoLogo",
* "-NonInteractive"]`. This means that the Powershell profile is not sourced first.
* @param execOptions The options passed to `execa`. Defaults to `{ stdio: "inherit" }`
* @returns The execution result
* @note It prefers `pwsh` over `powershell`
*/
export function execPowershellSync(
command: string,
startupFlags: string[] = ["-NoProfile", "-NoLogo", "-NonInteractive"],
execOptions: execa.SyncOptions = { stdio: "inherit" }
): execa.ExecaSyncReturnValue<string> {
return execa.sync(getPowerShell(), [...startupFlags, "-c", command], execOptions)
}

/**
* Get the path to the powershell executable.
*
* @note It prefers `pwsh` over `powershell`
* @note It caches the path for the subsequent calls to this function
*/
export function getPowerShell() {
if (powershell === undefined) {
const maybePwsh = which.sync("pwsh", { nothrow: true })
if (maybePwsh !== null) {
powershell = maybePwsh
}
const maybePowerShell = which.sync("powershell", { nothrow: true })
if (maybePowerShell !== null) {
powershell = maybePowerShell
}
}
if (powershell === undefined) {
throw new Error("Could not find powershell")
}
return powershell
}
7 changes: 7 additions & 0 deletions packages/exec-powershell/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["./src"]
}
Loading