Skip to content

Commit

Permalink
Implement custom provided CMake and ninja versions (#53)
Browse files Browse the repository at this point in the history
* #43

* better maintanability for functional tests
  • Loading branch information
lukka authored Nov 4, 2022
1 parent 6df5a61 commit 875c83c
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 126 deletions.
69 changes: 60 additions & 9 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
- cron: '0 1 * * SUN'
workflow_dispatch:

env:
CMAKE_LATEST: 3.24.2
NINJA_LATEST: 1.11.1

jobs:
build_and_test:
name: '${{ matrix.os }}: build and test'
Expand All @@ -17,10 +21,10 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: '16.x'
- run: |
Expand All @@ -34,8 +38,8 @@ jobs:
which cmake
cmake --version
CMAKE_VER="$(cmake --version)"
if ! [[ "$CMAKE_VER" =~ .*"3.24.2".* ]]; then
echo "ASSERTION FAILED! Instead of 3.24.2, found: "
if ! [[ "$CMAKE_VER" =~ .*"${CMAKE_LATEST}".* ]]; then
echo "ASSERTION FAILED! Instead of ${CMAKE_LATEST}, found: "
echo "$CMAKE_VER"
exit -1
fi
Expand All @@ -45,14 +49,61 @@ jobs:
which ninja
ninja --version
NINJA_VER="$(ninja --version)"
if ! [[ "$NINJA_VER" =~ .*"1.11.1".* ]]; then
echo "ASSERTION FAILED! Instead of 1.11.1, found: "
if ! [[ "$NINJA_VER" =~ .*"${NINJA_LATEST}".* ]]; then
echo "ASSERTION FAILED! Instead of ${NINJA_LATEST}, found: "
echo "$NINJA_VER"
exit -1
fi
shell: bash
- name: Coveralls
uses: coverallsapp/github-action@master

# TODO templatize the tests iterating on the versions.
test_user_provided_version:
name: '${{ matrix.os }}: functional test (${{ matrix.cmake }}, ${{ matrix.ninja }})'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
cmake: ["", "3.22.6"]
ninja: ["", "1.11.0"]

steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions/setup-node@v3
with:
node-version: '16.x'

- uses: ./
name: validation test by running get-cmake
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
cmakeVersion: ${{ matrix.cmake }}
ninjaVersion: ${{ matrix.ninja }}
- name: CMake version check ${{ matrix.cmake }}
run: |
which cmake
cmake --version
CMAKE_VER="$(cmake --version)"
EXPECTED_CMAKE_VER="${{ matrix.cmake }}"
[ -z "${EXPECTED_CMAKE_VER}" ] && EXPECTED_CMAKE_VER="${{ env.CMAKE_LATEST}}"
if ! [[ "$CMAKE_VER" =~ .*"${EXPECTED_CMAKE_VER}".* ]]; then
echo "ASSERTION FAILED! Instead of ${EXPECTED_CMAKE_VER}, found: "
echo "$CMAKE_VER"
exit -1
fi
shell: bash
- name: ninja version check ${{ matrix.ninja }}
run: |
which ninja
ninja --version
NINJA_VER="$(ninja --version)"
EXPECTED_NINJA_VER="${{ matrix.ninja }}"
[ -z "$EXPECTED_NINJA_VER" ] && EXPECTED_NINJA_VER="${{ env.NINJA_LATEST}}"
if ! [[ "$NINJA_VER" =~ .*"${{ matrix.ninja }}".* ]]; then
echo "ASSERTION FAILED! Instead of $EXPECTED_NINJA_VER, found: "
echo "$NINJA_VER"
exit -1
fi
shell: bash

2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright (c) 2020-2021 Luca Cappa
Copyright (c) 2020-2021-2022 Luca Cappa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
[![Coverage Status](https://coveralls.io/repos/github/lukka/get-cmake/badge.svg?branch=main)](https://coveralls.io/github/lukka/get-cmake?branch=main)

- [The **get-cmake** action for downloading and caching CMake and ninja binaries on the GitHub agents.](#the-get-cmake-action-for-downloading-and-caching-cmake-and-ninja-binaries-on-the-github-agents)
- [<a id='quickstart'>Quickstart</a>](#quickstart)
- [<a id='reference'>Action reference: all input/output parameters</a>](#action-reference-all-inputoutput-parameters)
- [Quickstart](#quickstart)
- [Action reference: all input/output parameters](#action-reference-all-inputoutput-parameters)
- [Who is using `get-cmake`](#who-is-using-get-cmake)
- [Developers information](#developers-information)
- [Prerequisites](#prerequisites)
- [Build and lint](#build-and-lint)
- [Packaging](#packaging)
- [Testing](#testing)
- [<a id='contributing'>Contributing</a>](#contributing)
- [Contributing](#contributing)
- [License](#license)

<br>
Expand All @@ -26,28 +26,37 @@ Flowchart of `get-cmake`:
1. If cache miss occurs, the action downloads and installs CMake and ninja, then **caches both automatically** with GitHub's [@actions/cache](https://www.npmjs.com/package/@actions/cache) APIs;
1. Adds to PATH the CMake and ninja executables;

## <a id='quickstart'>Quickstart</a>
## Quickstart

```yaml
# - uses: actions/cache@v1 <-----= YOU DO NOT NEED THIS
# key: <key> <-----= YOU DO NOT NEED THIS
# path: <path> <-----= YOU DO NOT NEED THIS

- name: Get latest CMake and ninja
- name: Get latest CMake and ninja
# Using 'latest' branch, the most recent CMake and ninja are installed.
uses: lukka/get-cmake@latest ⟸ THIS IS THE ONE LINER YOU NEED

# If you need to pin your workflow to specific CMake version you can use the 'tag' to select the version.


# If you need to _pin_ your workflow to specific CMake/ninja versions you have TWO options:

# Option 1: specify in a input parameter the desired version (using multiple lines).
- name: Get specific version CMake, v3.24.2, and ninja v1.11.1
uses: lukka/get-cmake@latest
with:
cmakeVersion: 3.24.2
ninjaVersion: 1.11.1

# Option 2: or you can use the Git 'tag' to select the version, and you can have a one-liner statement,
# but note that you can only use one of the existing tags, create a PR to add more tags!
- name: Get specific version CMake, v3.24.2
uses: lukka/[email protected] ⟸ THIS IS THE ONE LINER YOU NEED
```
<br>
## <a id='reference'>Action reference: all input/output parameters</a>
There are no inputs, nor outputs.
## Action reference: all input/output parameters
[action.yml](https://github.com/lukka/get-cmake/blob/main/action.yml)
Please read [actions.yml](./actions.yml).
<br>
Expand Down Expand Up @@ -86,7 +95,7 @@ To build, pack and test:

> jest

## <a id='contributing'>Contributing</a>
## Contributing

The software is provided as is, there is no warranty of any kind. All users are encouraged to improve the [source code](https://github.com/lukka/get-cmake) with fixes and new features.

Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ runs:
using: 'node16'
main: 'dist/index.js'

inputs:
cmakeVersion:
required: false
description: "Optional CMake version, e.g. '2.8.4'"
ninjaVersion:
required: false
description: "Optional Ninja version, e.g. '1.0.0'"

branding:
icon: 'terminal'
color: 'green'
106 changes: 56 additions & 50 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

"use strict";

// Copyright (c) 2020-2021 Luca Cappa
// Copyright (c) 2020-2021-2022 Luca Cappa
// Released under the term specified in file LICENSE.txt
// SPDX short identifier: MIT
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
Expand Down Expand Up @@ -40,11 +40,59 @@ function hashCode(text) {
return hash.toString();
}
class ToolsGetter {
constructor(cmakeOverride, ninjaOverride) {
this.cmakeOverride = cmakeOverride;
this.ninjaOverride = ninjaOverride;
this.cmakeVersion = cmakeOverride || ToolsGetter.CMakeDefaultVersion;
core.debug(`user defined cmake version:${this.cmakeVersion}`);
this.ninjaVersion = ninjaOverride || ToolsGetter.NinjaDefaultVersion;
core.debug(`user defined ninja version:${this.ninjaVersion}`);
}
run() {
return __awaiter(this, void 0, void 0, function* () {
const cmakeData = ToolsGetter.cmakePackagesMap[process.platform];
const ninjaData = ToolsGetter.ninjaPackagesMap[process.platform];
yield this.get(cmakeData, ninjaData);
// Predefined URL for CMake
const LinuxX64 = `https://github.com/Kitware/CMake/releases/download/v${this.cmakeVersion}/cmake-${this.cmakeVersion}-linux-x86_64.tar.gz`;
const WinX64 = `https://github.com/Kitware/CMake/releases/download/v${this.cmakeVersion}/cmake-${this.cmakeVersion}-windows-x86_64.zip`;
const MacOs = `https://github.com/Kitware/CMake/releases/download/v${this.cmakeVersion}/cmake-${this.cmakeVersion}-macos-universal.tar.gz`;
// Predefined URL for ninja
const NinjaLinuxX64 = `https://github.com/ninja-build/ninja/releases/download/v${this.ninjaVersion}/ninja-linux.zip`;
const NinjaMacosX64 = `https://github.com/ninja-build/ninja/releases/download/v${this.ninjaVersion}/ninja-mac.zip`;
const NinjaWindowsX64 = `https://github.com/ninja-build/ninja/releases/download/v${this.ninjaVersion}/ninja-win.zip`;
const cmakePackagesMap = {
"linux": {
url: LinuxX64,
binPath: 'bin/',
extractFunction: tools.extractTar, dropSuffix: ".tar.gz"
},
"win32": {
url: WinX64,
binPath: 'bin/',
extractFunction: tools.extractZip, dropSuffix: ".zip"
},
"darwin": {
url: MacOs,
binPath: "CMake.app/Contents/bin/",
extractFunction: tools.extractTar, dropSuffix: '.tar.gz'
}
};
const ninjaPackagesMap = {
"linux": {
url: NinjaLinuxX64,
binPath: '',
extractFunction: tools.extractZip, dropSuffix: ".zip"
},
"win32": {
url: NinjaWindowsX64,
binPath: '',
extractFunction: tools.extractZip, dropSuffix: ".zip"
},
"darwin": {
url: NinjaMacosX64,
binPath: '',
extractFunction: tools.extractZip, dropSuffix: '.zip'
}
};
yield this.get(cmakePackagesMap[process.platform], ninjaPackagesMap[process.platform]);
});
}
get(cmakeData, ninjaData) {
Expand Down Expand Up @@ -125,54 +173,12 @@ class ToolsGetter {
}
}
exports.ToolsGetter = ToolsGetter;
ToolsGetter.CMakeVersion = '3.24.2';
ToolsGetter.NinjaVersion = '1.11.1';
// Predefined URL for CMake
ToolsGetter.linux_x64 = `https://github.com/Kitware/CMake/releases/download/v${ToolsGetter.CMakeVersion}/cmake-${ToolsGetter.CMakeVersion}-linux-x86_64.tar.gz`;
ToolsGetter.win_x64 = `https://github.com/Kitware/CMake/releases/download/v${ToolsGetter.CMakeVersion}/cmake-${ToolsGetter.CMakeVersion}-windows-x86_64.zip`;
ToolsGetter.macos = `https://github.com/Kitware/CMake/releases/download/v${ToolsGetter.CMakeVersion}/cmake-${ToolsGetter.CMakeVersion}-macos-universal.tar.gz`;
// Predefined URL for ninja
ToolsGetter.ninja_linux_x64 = `https://github.com/ninja-build/ninja/releases/download/v${ToolsGetter.NinjaVersion}/ninja-linux.zip`;
ToolsGetter.ninja_macos_x64 = `https://github.com/ninja-build/ninja/releases/download/v${ToolsGetter.NinjaVersion}/ninja-mac.zip`;
ToolsGetter.ninja_windows_x64 = `https://github.com/ninja-build/ninja/releases/download/v${ToolsGetter.NinjaVersion}/ninja-win.zip`;
ToolsGetter.cmakePackagesMap = {
"linux": {
url: ToolsGetter.linux_x64,
binPath: 'bin/',
extractFunction: tools.extractTar, dropSuffix: ".tar.gz"
},
"win32": {
url: ToolsGetter.win_x64,
binPath: 'bin/',
extractFunction: tools.extractZip, dropSuffix: ".zip"
},
"darwin": {
url: ToolsGetter.macos,
binPath: "CMake.app/Contents/bin/",
extractFunction: tools.extractTar, dropSuffix: '.tar.gz'
}
};
ToolsGetter.ninjaPackagesMap = {
"linux": {
url: ToolsGetter.ninja_linux_x64,
binPath: '',
extractFunction: tools.extractZip, dropSuffix: ".zip"
},
"win32": {
url: ToolsGetter.ninja_windows_x64,
binPath: '',
extractFunction: tools.extractZip, dropSuffix: ".zip"
},
"darwin": {
url: ToolsGetter.ninja_macos_x64,
binPath: '',
extractFunction: tools.extractZip, dropSuffix: '.zip'
}
};
ToolsGetter.CMakeDefaultVersion = '3.24.2';
ToolsGetter.NinjaDefaultVersion = '1.11.1';
function main() {
return __awaiter(this, void 0, void 0, function* () {
try {
const cmakeGetter = new ToolsGetter();
const cmakeGetter = new ToolsGetter(core.getInput('cmakeVersion'), core.getInput('ninjaVersion'));
yield cmakeGetter.run();
core.info('get-cmake action execution succeeded');
process.exitCode = 0;
Expand Down Expand Up @@ -63679,7 +63685,7 @@ var __webpack_exports__ = {};
"use strict";
var exports = __webpack_exports__;

// Copyright (c) 2020-2021 Luca Cappa
// Copyright (c) 2020-2021-2022 Luca Cappa
// Released under the term specified in file LICENSE.txt
// SPDX short identifier: MIT
Object.defineProperty(exports, "__esModule", ({ value: true }));
Expand Down
2 changes: 1 addition & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Copyright (c) 2020-2021 Luca Cappa
// Copyright (c) 2020-2021-2022 Luca Cappa
// Released under the term specified in file LICENSE.txt
// SPDX short identifier: MIT

Expand Down
Loading

0 comments on commit 875c83c

Please sign in to comment.