Skip to content

Commit

Permalink
CMake Orb implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ouj committed Feb 3, 2023
1 parent 4540096 commit 97180ef
Show file tree
Hide file tree
Showing 12 changed files with 339 additions and 1 deletion.
37 changes: 37 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: 2.1
setup: true
orbs:
orb-tools: circleci/orb-tools@11.5
shellcheck: circleci/shellcheck@3.1

filters: &filters
tags:
only: /.*/

workflows:
lint-pack:
jobs:
- orb-tools/lint:
filters: *filters
- orb-tools/pack:
filters: *filters
- orb-tools/review:
exclude: 'RC009'
filters: *filters
- shellcheck/check:
filters: *filters
- orb-tools/publish:
orb-name: loomhq/cmake-orb
vcs-type: << pipeline.project.type >>
requires:
[orb-tools/lint, orb-tools/review, orb-tools/pack, shellcheck/check]
context:
- orb-publishing
- github-token
filters: *filters
# Triggers the next workflow in the Orb Development Kit.
- orb-tools/continue:
pipeline-number: << pipeline.number >>
vcs-type: << pipeline.project.type >>
requires: [orb-tools/publish]
filters: *filters
68 changes: 68 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
version: 2.1
orbs:
cmake-orb: loomhq/cmake-orb@dev:<<pipeline.git.revision>>
orb-tools: circleci/orb-tools@11.5
win: circleci/windows@5.0.0
macos: circleci/macos@2.0.1

filters: &filters
tags:
only: /.*/

jobs:
# Create a job to test the commands of your orbs.
# You may want to add additional validation steps to ensure the commands are working as expected.
command-tests-linux:
docker:
- image: cimg/base:current
steps:
- checkout
- cmake-orb/install:
os: 'linux'
command-tests-windows:
executor:
name: win/server-2022 # executor type
shell: bash.exe
size: medium
steps:
- checkout
- cmake-orb/install:
os: 'windows'
command-tests-macos:
macos:
xcode: 13.3.1 # macOS 12.3.1
steps:
- checkout
- cmake-orb/install:
os: 'mac'

workflows:
test-deploy:
jobs:
# Make sure to include "filters: *filters" in every test job you want to run as part of your deployment.
- command-tests-linux:
filters: *filters
- command-tests-windows:
filters: *filters
- command-tests-macos:
filters: *filters
- orb-tools/pack:
filters: *filters
- orb-tools/publish:
orb-name: loomhq/cmake-orb
vcs-type: << pipeline.project.type >>
pub-type: production
requires:
- orb-tools/pack
- command-tests-linux
- command-tests-windows
- command-tests-macos
context:
- orb-publishing
- github-token
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/
# VS Code Extension Version: 1.4.0
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# orb.yml is "packed" from source, and not published directly from the repository.
orb.yml
.DS_Store
7 changes: 7 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends: relaxed

rules:
line-length:
max: 200
allow-non-breakable-inline-mappings: true

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Loom, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# cmake-orb
CircleCI Orb for CMake Installation and Caching
CircleCI Orb for CMake Installation.

This orb is used internally by the @loomhq/desktop repository to build Loom desktop native recorders.

Inspired by https://github.com/sensu/cmake-orb. Added supports for MacOS, Windows and Linux.


[![CircleCI Build Status](https://circleci.com/gh/loomhq/cmake-orb.svg?style=shield "CircleCI Build Status")](https://circleci.com/gh/loomhq/cmake-orb)

[![CircleCI Orb Version](https://badges.circleci.com/orbs/loomhq/cmake-orb.svg)](https://circleci.com/orbs/registry/orb/loomhq/cmake-orb)

[![GitHub License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://github.com/loomhq/cmake-orb/blob/main/LICENSE)
12 changes: 12 additions & 0 deletions src/@orb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2.1

description: >
CMake Orb used by @loomhq/desktop to run CIs.
Easily install CMake on all the operating system's Loom deskotp is running CI on.
Most importantly, it will cache the cmake executable so each run do not need to
install CMake again and again. Save time and money.
# This information will be displayed in the orb registry and is not mandatory.
display:
home_url: 'https://www.loom.com/'
source_url: 'https://github.com/loomhq/cmake-orb'
85 changes: 85 additions & 0 deletions src/commands/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
description: >
This command install CMake onto the host machine. It support windows, macos, and linux.
It will also cache the install so we won't be downloading it from Kitware all the time.
It is used internally by @loomhq/desktop.
parameters:
version:
description: The version of CMake to install.
type: string
default: '3.25.2'
cache:
description: Whether or not to cache the installation.
type: boolean
default: true
cache-key:
description: String to use in cache key. Typically overridden when needed to bust cache.
type: string
default: 'v1'
os:
description: Operating system of the host we are installing cmake
type: enum
enum: [windows, mac, linux]

steps:
- run:
name: Setup Environment Variables
command: |
echo 'export CMAKE_VERSION="<< parameters.version >>"' >> "$BASH_ENV"
echo 'export CMAKE_INSTALL_DIR="$HOME/cmake"' >> "$BASH_ENV"
- when:
condition:
equal: [<< parameters.cache >>, true]
steps:
- run:
name: Prep cache restore
command: mkdir -pv $HOME/cmake
- restore_cache:
keys:
- cmake-<< parameters.os >>-<< parameters.cache-key >>-<< parameters.version >>
- run:
name: List install directory
command: ls -lL "$HOME/cmake/bin" || true
- run:
name: Add CMake to PATH
command: |
echo 'export PATH="$HOME/cmake/bin:$PATH"' >> $BASH_ENV
- when:
condition:
equal: ['mac', << parameters.os >>]
steps:
- run:
name: 'Install CMake'
command: <<include(scripts/install-cmake-macos.sh)>>

- when:
condition:
equal: ['windows', << parameters.os >>]
steps:
- run:
name: 'Install CMake'
command: <<include(scripts/install-cmake-windows.sh)>>

- when:
condition:
equal: ['linux', << parameters.os >>]
steps:
- run:
name: 'Install CMake'
command: <<include(scripts/install-cmake-linux.sh)>>

- run:
name: Verify CMake Installation
command: |
ls -lL "$HOME/cmake/bin"
which cmake
cmake --version
- when:
condition:
equal: [<< parameters.cache >>, true]
steps:
- save_cache:
key: cmake-<< parameters.os >>-<< parameters.cache-key >>-<< parameters.version >>
paths:
- '~/cmake'
12 changes: 12 additions & 0 deletions src/examples/example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
description: >
Sample usage of loomhq/cmake-orb
usage:
version: 2.1
orbs:
cmake-orb: loomhq/cmake-orb@1.0.0
workflows:
install-on-windows:
jobs:
- cmake-orb/install:
os: 'windows'
23 changes: 23 additions & 0 deletions src/scripts/install-cmake-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

if which cmake; then
if cmake --version | grep "$CMAKE_VERSION"; then
echo "CMake is already installed."
exit 0
else
echo "CMake is already installed but it is the wrong version."
cmake --version
fi
fi
rm -rf "${CMAKE_INSTALL_DIR:?}/*"

echo "Installing the requested version of CMake."
baseUrl="https://github.com/Kitware/CMake/releases/download/"
url="${baseUrl}/v$CMAKE_VERSION/cmake-$CMAKE_VERSION-Linux-x86_64.tar.gz"

echo "Downloading from: $url"
curl -sSL -o /tmp/cmake.tar.gz "$url"
tar -C "${CMAKE_INSTALL_DIR:?}" --strip-components 1 -zxf /tmp/cmake.tar.gz

# Remove unnecessary files
rm -rf "${CMAKE_INSTALL_DIR:?}"/{doc,man,share}
31 changes: 31 additions & 0 deletions src/scripts/install-cmake-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# shellcheck disable=SC1090
source "${BASH_ENV:?}"

echo "PATH $PATH"

if which cmake; then
if cmake --version | grep "$CMAKE_VERSION"; then
echo "CMake is already installed."
exit 0
else
echo "CMake is already installed but it is the wrong version."
cmake --version
fi
fi
rm -rf "${CMAKE_INSTALL_DIR:?}/*"

echo "Installing the requested version of CMake."
baseUrl="https://github.com/Kitware/CMake/releases/download/"
url="${baseUrl}/v$CMAKE_VERSION/cmake-$CMAKE_VERSION-macos-universal.tar.gz"

echo "Downloading from: $url"
curl -sSL -o /tmp/cmake.tar.gz "$url"
tar -C "${CMAKE_INSTALL_DIR:?}" --strip-components 1 -zxf /tmp/cmake.tar.gz

# copy binary
cp -r "${CMAKE_INSTALL_DIR:?}/CMake.app/Contents/bin" "${CMAKE_INSTALL_DIR:?}/bin"

# remove unnecessary files
rm -rf "${CMAKE_INSTALL_DIR:?}/CMake.app"
28 changes: 28 additions & 0 deletions src/scripts/install-cmake-windows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# shellcheck disable=SC1090
source "${BASH_ENV:?}"

echo "PATH $PATH"

if which cmake; then
if cmake --version | grep "$CMAKE_VERSION"; then
echo "CMake is already installed."
exit 0
else
echo "CMake is already installed but it is the wrong version."
cmake --version
fi
fi
rm -rf "${CMAKE_INSTALL_DIR:?}/*"

echo "Installing the requested version of CMake."
baseUrl="https://github.com/Kitware/CMake/releases/download/"
url="${baseUrl}/v$CMAKE_VERSION/cmake-$CMAKE_VERSION-windows-x86_64.zip"

echo "Downloading from: $url"
curl -sSL -o /tmp/cmake.zip "$url"
tar -C "${CMAKE_INSTALL_DIR:?}" --strip-components 1 -zxf /tmp/cmake.zip

# Remove unnecessary files
rm -rf "${CMAKE_INSTALL_DIR:?}"/{doc,man,share}

0 comments on commit 97180ef

Please sign in to comment.