mirror of
https://github.com/threeal/cmake-action.git
synced 2025-06-08 18:21:20 +00:00
chore: merge pull request #70 from threeal/js-action
Convert to JavaScript Action
This commit is contained in:
commit
434fbed336
28
.eslintrc.json
Normal file
28
.eslintrc.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"root": true,
|
||||
"extends": ["eslint:recommended", "prettier"],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2022,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["**/*.mts", "**/*.ts"],
|
||||
"extends": ["plugin:@typescript-eslint/recommended"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"project": ["tsconfig.eslint.json"]
|
||||
},
|
||||
"plugins": ["@typescript-eslint", "eslint-plugin-tsdoc"],
|
||||
"rules": {
|
||||
"tsdoc/syntax": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["**/*.test.*"],
|
||||
"env": {
|
||||
"jest": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
main/index.mjs -diff linguist-generated=true
|
9
.github/dependabot.yaml
vendored
9
.github/dependabot.yaml
vendored
@ -7,3 +7,12 @@ updates:
|
||||
commit-message:
|
||||
prefix: chore
|
||||
labels: [chore]
|
||||
|
||||
- package-ecosystem: npm
|
||||
directory: /
|
||||
schedule:
|
||||
interval: daily
|
||||
commit-message:
|
||||
prefix: chore
|
||||
labels: [chore]
|
||||
versioning-strategy: increase
|
||||
|
39
.github/workflows/build.yaml
vendored
Normal file
39
.github/workflows/build.yaml
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
name: Build
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [main]
|
||||
jobs:
|
||||
build-package:
|
||||
name: Build Package
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4.0.0
|
||||
with:
|
||||
node-version: latest
|
||||
|
||||
- name: Update Yarn
|
||||
run: corepack enable && yarn set version stable
|
||||
|
||||
- name: Cache deps
|
||||
uses: actions/cache@v3.3.2
|
||||
with:
|
||||
path: .yarn
|
||||
key: yarn-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
|
||||
|
||||
- name: Install deps
|
||||
run: yarn install
|
||||
|
||||
- name: Check lib
|
||||
run: yarn check
|
||||
|
||||
- name: Bundle dist
|
||||
run: yarn bundle
|
||||
|
||||
- name: Check diff
|
||||
run: git diff --exit-code HEAD
|
43
.github/workflows/test.yml
vendored
43
.github/workflows/test.yml
vendored
@ -5,6 +5,36 @@ on:
|
||||
push:
|
||||
branches: [latest, main]
|
||||
jobs:
|
||||
test-package:
|
||||
name: Test Package
|
||||
runs-on: ${{ matrix.os }}-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows, ubuntu, macos]
|
||||
env:
|
||||
NODE_OPTIONS: --experimental-vm-modules
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4.0.0
|
||||
with:
|
||||
node-version: latest
|
||||
|
||||
- name: Cache deps
|
||||
uses: actions/cache@v3.3.2
|
||||
with:
|
||||
path: .yarn
|
||||
key: yarn-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
|
||||
|
||||
- name: Install deps
|
||||
run: corepack enable && yarn install
|
||||
|
||||
- name: Test lib
|
||||
run: yarn test
|
||||
|
||||
default-usage:
|
||||
runs-on: ${{ matrix.os }}-latest
|
||||
strategy:
|
||||
@ -132,16 +162,3 @@ jobs:
|
||||
build-args: --target test_c --target test_cpp
|
||||
run-test: true
|
||||
test-args: -R test
|
||||
|
||||
specified-shell:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Checkout the repository
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Use the action with specified shell
|
||||
uses: ./
|
||||
with:
|
||||
shell: bash
|
||||
source-dir: test
|
||||
run-build: true
|
||||
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,4 +1,8 @@
|
||||
.*
|
||||
!.eslint*
|
||||
!.git*
|
||||
|
||||
build
|
||||
build/
|
||||
coverage/
|
||||
dist/
|
||||
node_modules/
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
[](https://github.com/threeal/cmake-action/releases/)
|
||||
[](./LICENSE)
|
||||
[](https://github.com/threeal/cmake-action/actions/workflows/build.yaml)
|
||||
[](https://github.com/threeal/cmake-action/actions/workflows/test.yml)
|
||||
|
||||
Configure, build, and test your [CMake](https://cmake.org/) project using [GitHub Actions](https://github.com/features/actions). This action simplifies the workflow for configuring the build environment of a CMake project. It can also be optionally specified to build a CMake project using the `cmake --build` command and test it using the `ctest` command.
|
||||
@ -22,7 +23,6 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action
|
||||
|
||||
| Name | Value Type | Description |
|
||||
| --- | --- | --- |
|
||||
| `shell` | String | The shell to be used to run the commands. It defaults to `pwsh` on Windows and `bash` on Linux and macOS. Refer to [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell) for more information on available shell options. |
|
||||
| `source-dir` | Path | The source directory of the CMake project. It defaults to the current directory. |
|
||||
| `build-dir` | Path | The build directory of the CMake project. It defaults to the `build` directory inside the source directory. |
|
||||
| `generator` | String | The build system generator for the CMake project. It appends the CMake configuration arguments with `-G [val]`. |
|
||||
|
94
action.yml
94
action.yml
@ -5,9 +5,6 @@ branding:
|
||||
color: gray-dark
|
||||
icon: terminal
|
||||
inputs:
|
||||
shell:
|
||||
description: The shell to be used to run the commands
|
||||
required: false
|
||||
source-dir:
|
||||
description: The source directory of the CMake project
|
||||
required: false
|
||||
@ -54,92 +51,5 @@ outputs:
|
||||
description: The build directory of the CMake project
|
||||
value: ${{ steps.process-inputs.outputs.build-dir }}
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Process the inputs
|
||||
id: process-inputs
|
||||
shell: bash
|
||||
run: |
|
||||
if [ -n '${{ inputs.shell }}' ]; then
|
||||
SHELL='${{ inputs.shell }}'
|
||||
else
|
||||
SHELL='${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}'
|
||||
fi
|
||||
echo "shell=$SHELL" >> $GITHUB_OUTPUT
|
||||
|
||||
SOURCE_DIR="."
|
||||
if [ -n '${{ inputs.source-dir }}' ]; then
|
||||
SOURCE_DIR="${{ inputs.source-dir }}"
|
||||
fi
|
||||
|
||||
BUILD_DIR="build"
|
||||
if [ -n '${{ inputs.build-dir }}' ]; then
|
||||
BUILD_DIR="${{ inputs.build-dir }}"
|
||||
elif [ -n "${{ inputs.source-dir }}" ]; then
|
||||
BUILD_DIR="${{ inputs.source-dir }}/build"
|
||||
fi
|
||||
echo "build-dir=$BUILD_DIR" >> $GITHUB_OUTPUT
|
||||
|
||||
ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'"
|
||||
if [ -n '${{ inputs.generator }}' ]; then
|
||||
ARGS="$ARGS -G '${{ inputs.generator }}'"
|
||||
fi
|
||||
if [ -n '${{ inputs.c-compiler }}' ]; then
|
||||
ARGS="$ARGS -D CMAKE_C_COMPILER='${{ inputs.c-compiler }}'"
|
||||
fi
|
||||
if [ -n '${{ inputs.cxx-compiler }}' ]; then
|
||||
ARGS="$ARGS -D CMAKE_CXX_COMPILER='${{ inputs.cxx-compiler }}'"
|
||||
fi
|
||||
if [ -n '${{ inputs.c-flags }}' ]; then
|
||||
ARGS="$ARGS -D CMAKE_C_FLAGS='${{ inputs.c-flags }}'"
|
||||
fi
|
||||
if [ -n '${{ inputs.cxx-flags }}' ]; then
|
||||
ARGS="$ARGS -D CMAKE_CXX_FLAGS='${{ inputs.cxx-flags }}'"
|
||||
fi
|
||||
for OPT in ${{ inputs.options }}; do
|
||||
ARGS="$ARGS -D $OPT"
|
||||
done
|
||||
if [ -n '${{ inputs.args }}' ]; then
|
||||
ARGS="$ARGS ${{ inputs.args }}"
|
||||
fi
|
||||
echo "cmake-args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
|
||||
|
||||
if [ '${{ inputs.run-build }}' == 'true' ] || [ '${{ inputs.run-test }}' == 'true' ]; then
|
||||
BUILD_ARGS="--build '$BUILD_DIR'"
|
||||
if [ -n '${{ inputs.build-args }}' ]; then
|
||||
BUILD_ARGS="$BUILD_ARGS ${{ inputs.build-args }}"
|
||||
fi
|
||||
echo "cmake-build-args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
if [ '${{ inputs.run-test }}' == 'true' ]; then
|
||||
TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error"
|
||||
if [ -n '${{ inputs.test-args }}' ]; then
|
||||
TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}"
|
||||
fi
|
||||
echo "cmake-test-args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Install Ninja
|
||||
if: ${{ inputs.generator == 'Ninja' }}
|
||||
shell: bash
|
||||
run: |
|
||||
case "$OSTYPE" in
|
||||
darwin*) brew install ninja ;;
|
||||
linux*) sudo apt install -y ninja-build ;;
|
||||
*) choco install ninja ;;
|
||||
esac
|
||||
|
||||
- name: Configure the CMake project
|
||||
shell: ${{ steps.process-inputs.outputs.shell }}
|
||||
run: cmake ${{ steps.process-inputs.outputs.cmake-args }}
|
||||
|
||||
- name: Build targets
|
||||
if: inputs.run-build != 'false' || inputs.run-test != 'false'
|
||||
shell: ${{ steps.process-inputs.outputs.shell }}
|
||||
run: cmake ${{ steps.process-inputs.outputs.cmake-build-args }}
|
||||
|
||||
- name: Run tests
|
||||
if: inputs.run-test != 'false'
|
||||
shell: ${{ steps.process-inputs.outputs.shell }}
|
||||
run: ctest ${{ steps.process-inputs.outputs.cmake-test-args }}
|
||||
using: node20
|
||||
main: main/index.mjs
|
||||
|
19
jest.config.json
Normal file
19
jest.config.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"collectCoverage": true,
|
||||
"coverageThreshold": {
|
||||
"global": {
|
||||
"branches": 100,
|
||||
"functions": 100,
|
||||
"lines": 100,
|
||||
"statements": 100
|
||||
}
|
||||
},
|
||||
"extensionsToTreatAsEsm": [".ts", ".mts"],
|
||||
"moduleNameMapper": {
|
||||
"^(\\.{1,2}/.*)\\.mjs$": "$1.mts"
|
||||
},
|
||||
"testMatch": ["**/*.test.ts"],
|
||||
"transform": {
|
||||
"^.+\\.m?ts$": ["ts-jest", { "useESM": true }]
|
||||
}
|
||||
}
|
27308
main/index.mjs
generated
Normal file
27308
main/index.mjs
generated
Normal file
File diff suppressed because one or more lines are too long
32
package.json
Normal file
32
package.json
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "cmake-action",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"bundle": "tsc && ncc build dist/main.mjs -o main",
|
||||
"check": "sort-package-json && prettier --write . !main !README.md && eslint src",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/io": "^1.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jest/globals": "^29.7.0",
|
||||
"@types/jest": "^29.5.8",
|
||||
"@types/node": "^20.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.11.0",
|
||||
"@typescript-eslint/parser": "^6.11.0",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint": "^8.53.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-tsdoc": "^0.2.17",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.1.0",
|
||||
"sort-package-json": "^2.6.0",
|
||||
"ts-jest": "^29.1.1",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"packageManager": "yarn@4.0.2"
|
||||
}
|
78
src/main.mts
Normal file
78
src/main.mts
Normal file
@ -0,0 +1,78 @@
|
||||
import core from "@actions/core";
|
||||
import exec from "@actions/exec";
|
||||
import io from "@actions/io";
|
||||
|
||||
async function main() {
|
||||
const sourceDir = core.getInput("source-dir");
|
||||
const buildDir = core.getInput("build-dir");
|
||||
|
||||
const configureArgs = [sourceDir || ".", "-B", buildDir || "build"];
|
||||
|
||||
const generator = core.getInput("generator");
|
||||
if (generator) configureArgs.push(...["-G", generator]);
|
||||
|
||||
if (generator.match(/ninja/gi) && !(await io.which("ninja"))) {
|
||||
switch (process.platform) {
|
||||
case "linux":
|
||||
await exec.exec("sudo", ["apt", "install", "-y", "ninja-build"]);
|
||||
break;
|
||||
case "darwin":
|
||||
await exec.exec("brew", ["install", "ninja"]);
|
||||
break;
|
||||
case "win32":
|
||||
await exec.exec("choco", ["install", "ninja"]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const cCompiler = core.getInput("c-compiler");
|
||||
if (cCompiler) configureArgs.push("-DCMAKE_C_COMPILER=" + cCompiler);
|
||||
|
||||
const cxxCompiler = core.getInput("cxx-compiler");
|
||||
if (cxxCompiler) configureArgs.push("-DCMAKE_CXX_COMPILER=" + cxxCompiler);
|
||||
|
||||
const cFlags = core.getMultilineInput("c-flags").join(" ");
|
||||
if (cFlags) configureArgs.push("-DCMAKE_C_FLAGS=" + cFlags);
|
||||
|
||||
const cxxFlags = core.getMultilineInput("cxx-flags").join(" ");
|
||||
if (cxxFlags) configureArgs.push("-DCMAKE_CXX_FLAGS=" + cxxFlags);
|
||||
|
||||
const options = core
|
||||
.getMultilineInput("options")
|
||||
.flatMap((opts) => opts.split(" "))
|
||||
.map((opt) => "-D" + opt);
|
||||
configureArgs.push(...options);
|
||||
|
||||
const args = core
|
||||
.getMultilineInput("args")
|
||||
.flatMap((args) => args.split(" "));
|
||||
configureArgs.push(...args);
|
||||
|
||||
await exec.exec("cmake", configureArgs);
|
||||
core.setOutput("build-dir", buildDir || "build");
|
||||
|
||||
const runBuild = core.getBooleanInput("run-build");
|
||||
const runTest = core.getBooleanInput("run-test");
|
||||
|
||||
if (runBuild || runTest) {
|
||||
const buildArgs = core
|
||||
.getMultilineInput("build-args")
|
||||
.flatMap((args) => args.split(" "));
|
||||
await exec.exec("cmake", ["--build", buildDir || "build", ...buildArgs]);
|
||||
}
|
||||
|
||||
if (runTest) {
|
||||
const testArgs = core
|
||||
.getMultilineInput("test-args")
|
||||
.flatMap((args) => args.split(" "));
|
||||
await exec.exec("ctest", [
|
||||
"--test-dir",
|
||||
buildDir || "build",
|
||||
"--output-on-failure",
|
||||
"--no-tests=error",
|
||||
...testArgs,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
1
src/main.test.ts
Normal file
1
src/main.test.ts
Normal file
@ -0,0 +1 @@
|
||||
test("some test", () => {});
|
4
tsconfig.eslint.json
Normal file
4
tsconfig.eslint.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": []
|
||||
}
|
17
tsconfig.json
Normal file
17
tsconfig.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
"sourceMap": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"lib": ["ES2022"],
|
||||
"target": "ES2022",
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["**/*.test.*"]
|
||||
}
|
Loading…
Reference in New Issue
Block a user