Skip to content

Commit

Permalink
cmake's workflow support (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukka authored Feb 5, 2023
1 parent d8897e1 commit 2d1ee0a
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 161 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ jobs:
# located elsewhere.
# cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt'

# You could use CMake workflow presets defined in the CMakePresets.json
# with just this line below.
# workflowPreset: 'workflow-name'

# This is the name of the CMakePresets.json's configuration to use to generate
# the project files. This configuration leverages the vcpkg.cmake toolchain file to
# run vcpkg and install all dependencies specified in vcpkg.json.
Expand Down Expand Up @@ -132,6 +136,12 @@ Flowchart with related input in [action.yml](https://github.com/lukka/run-cmake/

```
┌───────────────────────────┐ ┌───────────────────────────┐
│ <if workflowPreset │ Yes │ Run the workflow │ Inputs:
│ provided> ├─────►│ and then exit │ - `cmakeListsTxtPath`
└─────────────┬─────────────┘ └─────────────┬─────────────┘ - `workflowPreset`
│ No ⬬ - `workflowPresetCmdString`
┌───────────────────────────┐ ┌───────────────────────────┐
│ <if configurePreset │ Yes │ <if VCPKG_ROOT defined │ Inputs:
│ provided> ├─────►│ and CC and CXX undefined> │ - `runVcpkgEnvFormatString`
└─────────────┬─────────────┘ │ run `vcpkg env` to set │ - `configurePresetAdditionalArgs`
Expand Down
14 changes: 13 additions & 1 deletion __tests__/functional.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2020-2021 Luca Cappa
// Copyright (c) 2019-2020-2021-2023 Luca Cappa
// Released under the term specified in file LICENSE.txt
// SPDX short identifier: MIT

Expand Down Expand Up @@ -99,6 +99,18 @@ describe('run-cmake functional tests', () => {
console.log(cp.execSync(`node ${testScript}`, options)?.toString());
});

test('run workflow', () => {
process.env.INPUT_WORKFLOWPRESET = "default-workflow";
process.env.INPUT_BUILDPRESET = "default-multi"; // Must be ignored
process.env.INPUT_TESTPRESET = "default-multi"; // Must be ignored
process.env.INPUT_CMAKELISTSTXTPATH = path.join(assetDirectory, 'CMakeLists.txt');
const options: cp.ExecSyncOptions = {
env: process.env,
stdio: "inherit"
};
console.log(cp.execSync(`node ${testScript}`, options)?.toString());
});

test('basic test for environment variables in input, no shell, it must throw', () => {
// Building will use an environment variable that will not be
// resolved since not being run inside a shell, and it will throw.
Expand Down
17 changes: 16 additions & 1 deletion __tests__/theAssets/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 3,
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
Expand Down Expand Up @@ -52,5 +52,20 @@
"name": "default-multi",
"configurePreset": "default-multi"
}
],
"workflowPresets": [
{
"name": "default-workflow",
"steps": [
{
"type": "configure",
"name": "default-multi"
},
{
"type": "build",
"name": "default-multi"
}
]
}
]
}
2 changes: 1 addition & 1 deletion __tests__/unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2020-2021 Luca Cappa
// Copyright (c) 2019-2020-2021-2022-2023 Luca Cappa
// Released under the term specified in file LICENSE.txt
// SPDX short identifier: MIT

Expand Down
12 changes: 10 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2020-2021 Luca Cappa
# Copyright (c) 2019-2020-2021-2023 Luca Cappa
# Released under the term specified in file LICENSE.txt
# SPDX short identifier: MIT

Expand All @@ -12,10 +12,14 @@ inputs:
default: "${{ github.workspace }}/CMakeLists.txt"
required: false
description: "Path to CMakeLists.txt."
workflowPreset:
default: ""
required: false
description: "The name of the workflow preset. Optional. This value is stored in the WORKFLOW_PRESET_NAME environment variable, and used by the default value of 'workflowPresetCmdString' input."
configurePreset:
default: ""
required: false
description: "The name of the configure preset. Required. This value is stored in the CONFIGURE_PRESET_NAME environment variable, and used by the default value of 'configurePresetCmdString' input."
description: "The name of the configure preset. Optional. This value is stored in the CONFIGURE_PRESET_NAME environment variable, and used by the default value of 'configurePresetCmdString' input."
buildPreset:
default: ""
required: false
Expand Down Expand Up @@ -46,6 +50,10 @@ inputs:
default: "\\s*\"(.+CMakeOutput\\.log)\"\\.\\s*;\\s*\"(.+CMakeError\\.log)\"\\.\\s*;\\s*(.+out\\.log)\\s*;\\s+(.+err\\.log)\\s*;\\s*(.+vcpkg.+\\.log)\\s*"
required: false
description: "Specifies a semicolon separated list of regular expressions that are used to identify log file paths in the workflow output. A regular expression must have a single capturing group, that is a single pair of parenthesis such as 'See also (.+.log)'. When a match occurs, the content of the file is written into the workflow output for disclosing its content to the user. The default regular expressions are for CMake's and vcpkg's log files."
workflowPresetCmdString:
default: "[`--workflow`, `--preset`, `$[env.WORKFLOW_PRESET_NAME]`, `--fresh`]"
required: false
description: "The CMake command format string to run the workflow steps."
configurePresetCmdString:
default: "[`--preset`, `$[env.CONFIGURE_PRESET_NAME]`]"
required: false
Expand Down
Loading

0 comments on commit 2d1ee0a

Please sign in to comment.