mirror of
https://github.com/threeal/cmake-action.git
synced 2025-12-21 07:45:12 +00:00
Compare commits
No commits in common. "main" and "v2.1.0" have entirely different histories.
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -1,2 +1,2 @@
|
||||
dist/** -diff linguist-generated
|
||||
pnpm-lock.yaml -diff linguist-generated
|
||||
yarn.lock -diff linguist-generated
|
||||
|
||||
4
.github/dependabot.yaml
vendored
4
.github/dependabot.yaml
vendored
@ -6,7 +6,7 @@ updates:
|
||||
interval: daily
|
||||
commit-message:
|
||||
prefix: chore
|
||||
labels: []
|
||||
labels: [chore]
|
||||
|
||||
- package-ecosystem: npm
|
||||
directory: /
|
||||
@ -14,5 +14,5 @@ updates:
|
||||
interval: daily
|
||||
commit-message:
|
||||
prefix: chore
|
||||
labels: []
|
||||
labels: [chore]
|
||||
versioning-strategy: increase
|
||||
|
||||
35
.github/workflows/build.yaml
vendored
35
.github/workflows/build.yaml
vendored
@ -5,30 +5,23 @@ on:
|
||||
push:
|
||||
branches: [main]
|
||||
jobs:
|
||||
build-action:
|
||||
name: Build Action
|
||||
runs-on: ubuntu-24.04
|
||||
build-package:
|
||||
name: Build Package
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout Project
|
||||
uses: actions/checkout@v5.0.0
|
||||
uses: actions/checkout@v4.2.2
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: threeal/setup-pnpm-action@v1.0.0
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4.1.0
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
|
||||
- name: Install Dependencies
|
||||
run: pnpm install
|
||||
- name: Setup Yarn
|
||||
uses: threeal/setup-yarn-action@v2.0.0
|
||||
|
||||
- name: Check Types
|
||||
run: pnpm tsc
|
||||
- name: Build Package
|
||||
run: yarn build
|
||||
|
||||
- name: Test Action
|
||||
run: pnpm test
|
||||
|
||||
- name: Check Formatting
|
||||
run: pnpm prettier --check .
|
||||
|
||||
- name: Check Lint
|
||||
run: pnpm eslint
|
||||
|
||||
- name: Build Action
|
||||
run: pnpm rollup -c && git diff --exit-code dist
|
||||
- name: Check Diff
|
||||
run: git diff && git diff-index --quiet --exit-code HEAD
|
||||
|
||||
30
.github/workflows/check.yaml
vendored
Normal file
30
.github/workflows/check.yaml
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
name: Check
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [main]
|
||||
jobs:
|
||||
check-package:
|
||||
name: Check Package
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout Project
|
||||
uses: actions/checkout@v4.2.2
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4.1.0
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
|
||||
- name: Setup Yarn
|
||||
uses: threeal/setup-yarn-action@v2.0.0
|
||||
|
||||
- name: Check Formatting
|
||||
run: yarn format
|
||||
|
||||
- name: Check Diff
|
||||
run: git diff && git diff-index --quiet --exit-code HEAD
|
||||
|
||||
- name: Check Lint
|
||||
run: yarn lint
|
||||
51
.github/workflows/test.yaml
vendored
51
.github/workflows/test.yaml
vendored
@ -5,22 +5,40 @@ on:
|
||||
push:
|
||||
branches: [main]
|
||||
jobs:
|
||||
test-package:
|
||||
name: Test Package
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout Project
|
||||
uses: actions/checkout@v4.2.2
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4.1.0
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
|
||||
- name: Setup Yarn
|
||||
uses: threeal/setup-yarn-action@v2.0.0
|
||||
|
||||
- name: Test Package
|
||||
run: yarn test
|
||||
|
||||
test-action:
|
||||
name: Test Action
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-24.04, macos-14, windows-2022]
|
||||
os: [ubuntu-22.04, macos-14, windows-2022]
|
||||
steps:
|
||||
- name: Checkout Sample Project
|
||||
uses: actions/checkout@v5.0.0
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
repository: threeal/cpp-starter
|
||||
ref: v1.0.0
|
||||
|
||||
- name: Checkout Action
|
||||
uses: actions/checkout@v5.0.0
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
path: cmake-action
|
||||
sparse-checkout: |
|
||||
@ -37,17 +55,17 @@ jobs:
|
||||
|
||||
test-action-with-specified-dirs:
|
||||
name: Test Action With Specified Directories
|
||||
runs-on: ubuntu-24.04
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout Sample Project
|
||||
uses: actions/checkout@v5.0.0
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
repository: threeal/cpp-starter
|
||||
ref: v1.0.0
|
||||
path: project
|
||||
|
||||
- name: Checkout Action
|
||||
uses: actions/checkout@v5.0.0
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
path: cmake-action
|
||||
sparse-checkout: |
|
||||
@ -67,16 +85,16 @@ jobs:
|
||||
|
||||
test-action-without-run-build:
|
||||
name: Test Action Without Run Build
|
||||
runs-on: ubuntu-24.04
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout Sample Project
|
||||
uses: actions/checkout@v5.0.0
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
repository: threeal/cpp-starter
|
||||
ref: v1.0.0
|
||||
|
||||
- name: Checkout Action
|
||||
uses: actions/checkout@v5.0.0
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
path: cmake-action
|
||||
sparse-checkout: |
|
||||
@ -94,16 +112,16 @@ jobs:
|
||||
|
||||
test-action-with-additional-options:
|
||||
name: Test Action With Additional Options
|
||||
runs-on: ubuntu-24.04
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout Sample Project
|
||||
uses: actions/checkout@v5.0.0
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
repository: threeal/cpp-starter
|
||||
ref: v1.0.0
|
||||
|
||||
- name: Checkout Action
|
||||
uses: actions/checkout@v5.0.0
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
path: cmake-action
|
||||
sparse-checkout: |
|
||||
@ -121,16 +139,16 @@ jobs:
|
||||
|
||||
test-action-with-custom-generator:
|
||||
name: Test Action With Custom Generator
|
||||
runs-on: ubuntu-24.04
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout Sample Project
|
||||
uses: actions/checkout@v5.0.0
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
repository: threeal/cpp-starter
|
||||
ref: v1.0.0
|
||||
|
||||
- name: Checkout Action
|
||||
uses: actions/checkout@v5.0.0
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
path: cmake-action
|
||||
sparse-checkout: |
|
||||
@ -138,6 +156,9 @@ jobs:
|
||||
dist
|
||||
sparse-checkout-cone-mode: false
|
||||
|
||||
- name: Setup Ninja
|
||||
uses: seanmiddleditch/gha-setup-ninja@v5
|
||||
|
||||
- name: Configure Sample Project
|
||||
id: cmake-action
|
||||
uses: ./cmake-action
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,6 +1,6 @@
|
||||
.*
|
||||
!.env.yarn
|
||||
!.git*
|
||||
!.npmrc
|
||||
!.prettier*
|
||||
!.nvmrc
|
||||
|
||||
node_modules/
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
dist
|
||||
pnpm-lock.yaml
|
||||
README.md
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["prettier-plugin-organize-imports"]
|
||||
}
|
||||
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023-2025 Alfi Maulana
|
||||
Copyright (c) 2023-2024 Alfi Maulana
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
19
README.md
19
README.md
@ -37,13 +37,13 @@ on:
|
||||
jobs:
|
||||
build-project:
|
||||
name: Build Project
|
||||
runs-on: ubuntu-24.04
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout Project
|
||||
uses: actions/checkout@v4.2.2
|
||||
uses: actions/checkout@v4.2.1
|
||||
|
||||
- name: Build Project
|
||||
uses: threeal/cmake-action@v2.1.0
|
||||
uses: threeal/cmake-action@v2.0.0
|
||||
```
|
||||
|
||||
### Specify the Source and Build Directories
|
||||
@ -52,7 +52,7 @@ By default, this action uses the current working directory as the source directo
|
||||
|
||||
```yaml
|
||||
- name: Build Project
|
||||
uses: threeal/cmake-action@v2.1.0
|
||||
uses: threeal/cmake-action@v2.0.0
|
||||
with:
|
||||
source-dir: source
|
||||
build-dir: output
|
||||
@ -63,8 +63,11 @@ By default, this action uses the current working directory as the source directo
|
||||
The following example demonstrates how to use this action to configure and build the project using [Ninja](https://ninja-build.org/) as the build system generator and [Clang](https://clang.llvm.org/) as the compiler:
|
||||
|
||||
```yaml
|
||||
- name: Setup Ninja
|
||||
uses: seanmiddleditch/gha-setup-ninja@v5
|
||||
|
||||
- name: Build Project
|
||||
uses: threeal/cmake-action@v2.1.0
|
||||
uses: threeal/cmake-action@v2.0.0
|
||||
with:
|
||||
generator: Ninja
|
||||
cxx-compiler: clang++
|
||||
@ -76,7 +79,7 @@ Use the `options` input to specify additional options for configuring a project:
|
||||
|
||||
```yaml
|
||||
- name: Build Project
|
||||
uses: threeal/cmake-action@v2.1.0
|
||||
uses: threeal/cmake-action@v2.0.0
|
||||
with:
|
||||
options: |
|
||||
BUILD_TESTS=ON
|
||||
@ -91,7 +94,7 @@ By default, this action builds the project after configuration. To skip the buil
|
||||
|
||||
```yaml
|
||||
- name: Configure Project
|
||||
uses: threeal/cmake-action@v2.1.0
|
||||
uses: threeal/cmake-action@v2.0.0
|
||||
with:
|
||||
run-build: false
|
||||
```
|
||||
@ -100,4 +103,4 @@ By default, this action builds the project after configuration. To skip the buil
|
||||
|
||||
This project is licensed under the terms of the [MIT License](./LICENSE).
|
||||
|
||||
Copyright © 2023-2025 [Alfi Maulana](https://github.com/threeal/)
|
||||
Copyright © 2023-2024 [Alfi Maulana](https://github.com/threeal/)
|
||||
|
||||
@ -33,5 +33,5 @@ outputs:
|
||||
description: The build directory of the CMake project
|
||||
value: ${{ steps.process-inputs.outputs.build-dir }}
|
||||
runs:
|
||||
using: node24
|
||||
using: node20
|
||||
main: dist/action.mjs
|
||||
|
||||
10
dist/action.mjs
generated
vendored
10
dist/action.mjs
generated
vendored
@ -82,7 +82,7 @@ async function exec(command, args) {
|
||||
resolve();
|
||||
}
|
||||
else {
|
||||
reject(new Error(`Command exited with status code ${code.toString()}`));
|
||||
reject(new Error(`Command exited with status code ${code}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -136,7 +136,7 @@ function parse(str) {
|
||||
const args = [];
|
||||
let match;
|
||||
while ((match = regex.exec(str)) !== null) {
|
||||
args.push(match[1] || match[2] || match[3] || match[4]);
|
||||
args.push(match[1] ?? match[2] ?? match[3] ?? match[4]);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
@ -162,7 +162,7 @@ function getContext() {
|
||||
}
|
||||
input = getInput("options");
|
||||
if (input) {
|
||||
options.push(...parse(input).map((opt) => opt));
|
||||
options.push(...parse(input).map((opt) => opt.toString()));
|
||||
}
|
||||
return {
|
||||
sourceDir,
|
||||
@ -170,11 +170,11 @@ function getContext() {
|
||||
configure: {
|
||||
generator: getInput("generator"),
|
||||
options,
|
||||
args: parse(getInput("args")).map((arg) => arg),
|
||||
args: parse(getInput("args")).map((arg) => arg.toString()),
|
||||
},
|
||||
build: {
|
||||
enabled: getInput("run-build") == "true",
|
||||
args: parse(getInput("build-args")).map((arg) => arg),
|
||||
args: parse(getInput("build-args")).map((arg) => arg.toString()),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
11
eslint.config.js
Normal file
11
eslint.config.js
Normal file
@ -0,0 +1,11 @@
|
||||
import eslint from "@eslint/js";
|
||||
import tseslint from "typescript-eslint";
|
||||
|
||||
export default [
|
||||
eslint.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
...tseslint.configs.stylistic,
|
||||
{
|
||||
ignores: [".*", "dist"],
|
||||
},
|
||||
];
|
||||
@ -1,20 +0,0 @@
|
||||
import eslint from "@eslint/js";
|
||||
import { defineConfig, globalIgnores } from "eslint/config";
|
||||
import tseslint from "typescript-eslint";
|
||||
|
||||
export default defineConfig(
|
||||
globalIgnores(["dist"]),
|
||||
eslint.configs.recommended,
|
||||
tseslint.configs.strictTypeChecked,
|
||||
tseslint.configs.stylisticTypeChecked,
|
||||
{
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
projectService: {
|
||||
allowDefaultProject: ["rollup.config.js"],
|
||||
},
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
20
jest.config.json
Normal file
20
jest.config.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"collectCoverage": true,
|
||||
"coverageReporters": ["text"],
|
||||
"coverageThreshold": {
|
||||
"global": {
|
||||
"branches": 100,
|
||||
"functions": 100,
|
||||
"lines": 100,
|
||||
"statements": 100
|
||||
}
|
||||
},
|
||||
"moduleNameMapper": {
|
||||
"^(\\.{1,2}/.*)\\.js$": "$1"
|
||||
},
|
||||
"preset": "ts-jest/presets/default-esm",
|
||||
"transform": {
|
||||
"^.+\\.ts$": ["ts-jest", { "useESM": true }]
|
||||
},
|
||||
"verbose": true
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
pre-commit:
|
||||
piped: true
|
||||
jobs:
|
||||
- name: install dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: check types
|
||||
run: pnpm tsc
|
||||
|
||||
- name: fix formatting
|
||||
run: pnpm prettier --write .
|
||||
|
||||
- name: fix lint
|
||||
run: pnpm eslint --fix
|
||||
|
||||
- name: build action
|
||||
run: pnpm rollup -c
|
||||
|
||||
- name: check diff
|
||||
run: git diff --exit-code dist pnpm-lock.yaml {staged_files}
|
||||
37
package.json
37
package.json
@ -3,26 +3,29 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "vitest run"
|
||||
"build": "rollup -c",
|
||||
"format": "prettier --write --cache . !dist !README.md",
|
||||
"lint": "eslint",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"gha-utils": "^0.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.35.0",
|
||||
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||
"@rollup/plugin-typescript": "^12.1.4",
|
||||
"@tsconfig/node24": "^24.0.1",
|
||||
"@types/node": "^24.3.0",
|
||||
"@vitest/coverage-v8": "^3.1.4",
|
||||
"eslint": "^9.34.0",
|
||||
"jiti": "^2.5.1",
|
||||
"lefthook": "^1.12.3",
|
||||
"prettier": "^3.6.2",
|
||||
"prettier-plugin-organize-imports": "^4.2.0",
|
||||
"rollup": "^4.46.2",
|
||||
"typescript": "^5.9.2",
|
||||
"typescript-eslint": "^8.42.0",
|
||||
"vitest": "^3.1.4"
|
||||
}
|
||||
"@eslint/js": "^9.16.0",
|
||||
"@jest/globals": "^29.7.0",
|
||||
"@rollup/plugin-node-resolve": "^15.3.0",
|
||||
"@rollup/plugin-typescript": "^12.1.1",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/node": "^22.10.1",
|
||||
"eslint": "^9.16.0",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.4.2",
|
||||
"rollup": "^4.28.0",
|
||||
"ts-jest": "^29.2.5",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.7.2",
|
||||
"typescript-eslint": "^8.17.0"
|
||||
},
|
||||
"packageManager": "yarn@4.5.3"
|
||||
}
|
||||
|
||||
2574
pnpm-lock.yaml
2574
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
@ -1,6 +0,0 @@
|
||||
packages:
|
||||
- .
|
||||
|
||||
onlyBuiltDependencies:
|
||||
- esbuild
|
||||
- lefthook
|
||||
@ -1,7 +1,5 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { buildProject, configureProject } from "./cmake.js";
|
||||
import { jest } from "@jest/globals";
|
||||
import type { Context } from "./context.js";
|
||||
import { exec } from "./exec.js";
|
||||
|
||||
interface TestCase {
|
||||
name: string;
|
||||
@ -23,7 +21,9 @@ const defaultContext: Context = {
|
||||
},
|
||||
};
|
||||
|
||||
vi.mock("./exec.js", () => ({ exec: vi.fn() }));
|
||||
jest.unstable_mockModule("./exec.js", () => ({
|
||||
exec: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("configure a CMake project", () => {
|
||||
const testCases: TestCase[] = [
|
||||
@ -100,7 +100,10 @@ describe("configure a CMake project", () => {
|
||||
|
||||
for (const testCase of testCases) {
|
||||
it(`should execute the correct command ${testCase.name}`, async () => {
|
||||
vi.mocked(exec).mockReset();
|
||||
const { configureProject } = await import("./cmake.js");
|
||||
const { exec } = await import("./exec.js");
|
||||
|
||||
jest.mocked(exec).mockReset();
|
||||
|
||||
await configureProject({ ...defaultContext, ...testCase.context });
|
||||
|
||||
@ -141,7 +144,10 @@ describe("build a CMake project", () => {
|
||||
|
||||
for (const testCase of testCases) {
|
||||
it(`should execute the correct command ${testCase.name}`, async () => {
|
||||
vi.mocked(exec).mockReset();
|
||||
const { buildProject } = await import("./cmake.js");
|
||||
const { exec } = await import("./exec.js");
|
||||
|
||||
jest.mocked(exec).mockReset();
|
||||
|
||||
await buildProject({ ...defaultContext, ...testCase.context });
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import type { Context } from "./context.js";
|
||||
import { exec } from "./exec.js";
|
||||
import type { Context } from "./context.js";
|
||||
|
||||
/**
|
||||
* Configures the build system for a CMake project.
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import { jest } from "@jest/globals";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { Context } from "./context.js";
|
||||
|
||||
vi.mock("gha-utils", () => ({ getInput: vi.fn() }));
|
||||
jest.unstable_mockModule("gha-utils", () => ({
|
||||
getInput: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("get action context", () => {
|
||||
interface TestCase {
|
||||
@ -183,8 +185,10 @@ describe("get action context", () => {
|
||||
const { getInput } = await import("gha-utils");
|
||||
const { getContext } = await import("./context.js");
|
||||
|
||||
const inputs = testCase.inputs ?? {};
|
||||
vi.mocked(getInput).mockImplementation((name) => inputs[name] ?? "");
|
||||
const inputs = testCase.inputs || {};
|
||||
jest.mocked(getInput).mockImplementation((name) => {
|
||||
return inputs[name] || "";
|
||||
});
|
||||
|
||||
expect(getContext()).toStrictEqual({
|
||||
sourceDir: "",
|
||||
|
||||
@ -40,7 +40,7 @@ export function getContext(): Context {
|
||||
|
||||
input = getInput("options");
|
||||
if (input) {
|
||||
options.push(...parse(input).map((opt) => opt));
|
||||
options.push(...parse(input).map((opt) => opt.toString()));
|
||||
}
|
||||
|
||||
return {
|
||||
@ -49,11 +49,11 @@ export function getContext(): Context {
|
||||
configure: {
|
||||
generator: getInput("generator"),
|
||||
options,
|
||||
args: parse(getInput("args")).map((arg) => arg),
|
||||
args: parse(getInput("args")).map((arg) => arg.toString()),
|
||||
},
|
||||
build: {
|
||||
enabled: getInput("run-build") == "true",
|
||||
args: parse(getInput("build-args")).map((arg) => arg),
|
||||
args: parse(getInput("build-args")).map((arg) => arg.toString()),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,17 +1,16 @@
|
||||
import { logCommand } from "gha-utils";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { exec } from "./exec.js";
|
||||
import { jest } from "@jest/globals";
|
||||
|
||||
describe("execute commands", () => {
|
||||
vi.mock("gha-utils", () => ({
|
||||
logCommand: vi.fn<(command: string, ...args: string[]) => void>(),
|
||||
}));
|
||||
const logCommand = jest.fn<(command: string, ...args: string[]) => void>();
|
||||
jest.unstable_mockModule("gha-utils", () => ({ logCommand }));
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(logCommand).mockClear();
|
||||
logCommand.mockClear();
|
||||
});
|
||||
|
||||
it("should successfully execute a command", async () => {
|
||||
const { exec } = await import("./exec.js");
|
||||
|
||||
await exec("node", ["--version"]);
|
||||
|
||||
expect(logCommand).toHaveBeenCalledTimes(1);
|
||||
@ -19,6 +18,8 @@ describe("execute commands", () => {
|
||||
});
|
||||
|
||||
it("should fail to execute a command", async () => {
|
||||
const { exec } = await import("./exec.js");
|
||||
|
||||
await expect(exec("node", ["--invalid"])).rejects.toThrow(
|
||||
"Command exited with status code 9",
|
||||
);
|
||||
|
||||
@ -17,11 +17,11 @@ export async function exec(command: string, args: string[]): Promise<void> {
|
||||
});
|
||||
logCommand(proc.spawnfile, ...proc.spawnargs.splice(1));
|
||||
proc.on("error", reject);
|
||||
proc.on("close", (code: number) => {
|
||||
proc.on("close", (code) => {
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(`Command exited with status code ${code.toString()}`));
|
||||
reject(new Error(`Command exited with status code ${code}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -12,7 +12,7 @@ export function parse(str: string): string[] {
|
||||
const args: string[] = [];
|
||||
let match: RegExpExecArray | null;
|
||||
while ((match = regex.exec(str)) !== null) {
|
||||
args.push(match[1] || match[2] || match[3] || match[4]);
|
||||
args.push(match[1] ?? match[2] ?? match[3] ?? match[4]);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
@ -1,7 +1,13 @@
|
||||
{
|
||||
"extends": "@tsconfig/node24",
|
||||
"include": ["src"],
|
||||
"exclude": ["**/*.test.ts"],
|
||||
"compilerOptions": {
|
||||
"exactOptionalPropertyTypes": true,
|
||||
"strict": true,
|
||||
"module": "node16",
|
||||
"noEmit": true
|
||||
"moduleResolution": "node16",
|
||||
"esModuleInterop": true,
|
||||
"target": "es2022",
|
||||
"skipLibCheck": true
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
coverage: {
|
||||
all: false,
|
||||
enabled: true,
|
||||
reporter: ["text"],
|
||||
thresholds: { 100: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user