feat: configure CMake from the JavaScript Action (#72)

* feat(action): modify to run `main/index.mjs` on Node 20

* feat: add configure cmake step

* feat: output build directory

* feat: get `source-dir` and `build-dir` inputs
This commit is contained in:
Alfi Maulana 2023-11-20 20:18:21 +07:00 committed by GitHub
parent ed7c2d179c
commit 48cb08d783
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27331 additions and 89 deletions

View File

@ -54,92 +54,5 @@ outputs:
description: The build directory of the CMake project description: The build directory of the CMake project
value: ${{ steps.process-inputs.outputs.build-dir }} value: ${{ steps.process-inputs.outputs.build-dir }}
runs: runs:
using: composite using: node20
steps: main: main/index.mjs
- 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 }}

27244
main/index.mjs generated

File diff suppressed because one or more lines are too long

View File

@ -7,6 +7,10 @@
"check": "sort-package-json && prettier --write . !main !README.md && eslint src", "check": "sort-package-json && prettier --write . !main !README.md && eslint src",
"test": "jest" "test": "jest"
}, },
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1"
},
"devDependencies": { "devDependencies": {
"@jest/globals": "^29.7.0", "@jest/globals": "^29.7.0",
"@types/jest": "^29.5.8", "@types/jest": "^29.5.8",

View File

@ -0,0 +1,11 @@
import core from "@actions/core";
import exec from "@actions/exec";
async function main() {
const sourceDir = core.getInput("source-dir");
const buildDir = core.getInput("build-dir");
await exec.exec("cmake", [sourceDir || ".", "-B", buildDir || "build"]);
core.setOutput("build-dir", buildDir || "build");
}
main();

View File

@ -12,6 +12,42 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@actions/core@npm:^1.10.1":
version: 1.10.1
resolution: "@actions/core@npm:1.10.1"
dependencies:
"@actions/http-client": "npm:^2.0.1"
uuid: "npm:^8.3.2"
checksum: 7a61446697a23dcad3545cf0634dedbdedf20ae9a0ee6ee977554589a15deb4a93593ee48a41258933d58ce0778f446b0d2c162b60750956fb75e0b9560fb832
languageName: node
linkType: hard
"@actions/exec@npm:^1.1.1":
version: 1.1.1
resolution: "@actions/exec@npm:1.1.1"
dependencies:
"@actions/io": "npm:^1.0.1"
checksum: 4a09f6bdbe50ce68b5cf8a7254d176230d6a74bccf6ecc3857feee209a8c950ba9adec87cc5ecceb04110182d1c17117234e45557d72fde6229b7fd3a395322a
languageName: node
linkType: hard
"@actions/http-client@npm:^2.0.1":
version: 2.2.0
resolution: "@actions/http-client@npm:2.2.0"
dependencies:
tunnel: "npm:^0.0.6"
undici: "npm:^5.25.4"
checksum: 868fe8529d78beb72f84ea2486e232fa6f66abe00d6ec4591b98c37e762c3d812868a3548638d75b49917961fd10ba1556916b47b1e9e4b55c266e2013c3ae8e
languageName: node
linkType: hard
"@actions/io@npm:^1.0.1":
version: 1.1.3
resolution: "@actions/io@npm:1.1.3"
checksum: 5b8751918e5bf0bebd923ba917fb1c0e294401e7ff0037f32c92a4efa4215550df1f6633c63fd4efb2bdaae8711e69b9e36925857db1f38935ff62a5c92ec29e
languageName: node
linkType: hard
"@ampproject/remapping@npm:^2.2.0": "@ampproject/remapping@npm:^2.2.0":
version: 2.2.1 version: 2.2.1
resolution: "@ampproject/remapping@npm:2.2.1" resolution: "@ampproject/remapping@npm:2.2.1"
@ -457,6 +493,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@fastify/busboy@npm:^2.0.0":
version: 2.1.0
resolution: "@fastify/busboy@npm:2.1.0"
checksum: 7bb641080aac7cf01d88749ad331af10ba9ec3713ec07cabbe833908c75df21bd56249bb6173bdec07f5a41896b21e3689316f86684c06635da45f91ff4565a2
languageName: node
linkType: hard
"@humanwhocodes/config-array@npm:^0.11.13": "@humanwhocodes/config-array@npm:^0.11.13":
version: 0.11.13 version: 0.11.13
resolution: "@humanwhocodes/config-array@npm:0.11.13" resolution: "@humanwhocodes/config-array@npm:0.11.13"
@ -1572,6 +1615,8 @@ __metadata:
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "cmake-action@workspace:." resolution: "cmake-action@workspace:."
dependencies: dependencies:
"@actions/core": "npm:^1.10.1"
"@actions/exec": "npm:^1.1.1"
"@jest/globals": "npm:^29.7.0" "@jest/globals": "npm:^29.7.0"
"@types/jest": "npm:^29.5.8" "@types/jest": "npm:^29.5.8"
"@types/node": "npm:^20.9.0" "@types/node": "npm:^20.9.0"
@ -4307,6 +4352,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"tunnel@npm:^0.0.6":
version: 0.0.6
resolution: "tunnel@npm:0.0.6"
checksum: e27e7e896f2426c1c747325b5f54efebc1a004647d853fad892b46d64e37591ccd0b97439470795e5262b5c0748d22beb4489a04a0a448029636670bfd801b75
languageName: node
linkType: hard
"type-check@npm:^0.4.0, type-check@npm:~0.4.0": "type-check@npm:^0.4.0, type-check@npm:~0.4.0":
version: 0.4.0 version: 0.4.0
resolution: "type-check@npm:0.4.0" resolution: "type-check@npm:0.4.0"
@ -4364,6 +4416,15 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"undici@npm:^5.25.4":
version: 5.27.2
resolution: "undici@npm:5.27.2"
dependencies:
"@fastify/busboy": "npm:^2.0.0"
checksum: 0cb62c57edc938f242c116e41fb2a74f81ed20e7e2e554cf1ceae548520df0592385b53d444f8cf59e1e10e6b27acd153198d8a2353b3040d0a778a099aac92c
languageName: node
linkType: hard
"unique-filename@npm:^3.0.0": "unique-filename@npm:^3.0.0":
version: 3.0.0 version: 3.0.0
resolution: "unique-filename@npm:3.0.0" resolution: "unique-filename@npm:3.0.0"
@ -4405,6 +4466,15 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"uuid@npm:^8.3.2":
version: 8.3.2
resolution: "uuid@npm:8.3.2"
bin:
uuid: dist/bin/uuid
checksum: bcbb807a917d374a49f475fae2e87fdca7da5e5530820ef53f65ba1d12131bd81a92ecf259cc7ce317cbe0f289e7d79fdfebcef9bfa3087c8c8a2fa304c9be54
languageName: node
linkType: hard
"v8-to-istanbul@npm:^9.0.1": "v8-to-istanbul@npm:^9.0.1":
version: 9.1.3 version: 9.1.3
resolution: "v8-to-istanbul@npm:9.1.3" resolution: "v8-to-istanbul@npm:9.1.3"