From 97180ef24dc014862e92fe62f8857b89856855ac Mon Sep 17 00:00:00 2001 From: Jiawei Ou Date: Thu, 2 Feb 2023 13:33:22 -0800 Subject: [PATCH] CMake Orb implementation --- .circleci/config.yml | 37 ++++++++++++ .circleci/test-deploy.yml | 68 ++++++++++++++++++++++ .gitignore | 3 + .yamllint | 7 +++ LICENSE | 21 +++++++ README.md | 13 ++++- src/@orb.yml | 12 ++++ src/commands/install.yml | 85 ++++++++++++++++++++++++++++ src/examples/example.yml | 12 ++++ src/scripts/install-cmake-linux.sh | 23 ++++++++ src/scripts/install-cmake-macos.sh | 31 ++++++++++ src/scripts/install-cmake-windows.sh | 28 +++++++++ 12 files changed, 339 insertions(+), 1 deletion(-) create mode 100644 .circleci/config.yml create mode 100644 .circleci/test-deploy.yml create mode 100644 .gitignore create mode 100644 .yamllint create mode 100644 LICENSE create mode 100755 src/@orb.yml create mode 100755 src/commands/install.yml create mode 100755 src/examples/example.yml create mode 100644 src/scripts/install-cmake-linux.sh create mode 100644 src/scripts/install-cmake-macos.sh create mode 100644 src/scripts/install-cmake-windows.sh diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..858f3b9 --- /dev/null +++ b/.circleci/config.yml @@ -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 diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml new file mode 100644 index 0000000..481d4b1 --- /dev/null +++ b/.circleci/test-deploy.yml @@ -0,0 +1,68 @@ +version: 2.1 +orbs: + cmake-orb: loomhq/cmake-orb@dev:<> + 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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c88c1b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# orb.yml is "packed" from source, and not published directly from the repository. +orb.yml +.DS_Store \ No newline at end of file diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..c9a8a2e --- /dev/null +++ b/.yamllint @@ -0,0 +1,7 @@ +extends: relaxed + +rules: + line-length: + max: 200 + allow-non-breakable-inline-mappings: true + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..13bd65a --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md index 8d3277f..6cabc84 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/src/@orb.yml b/src/@orb.yml new file mode 100755 index 0000000..f276b48 --- /dev/null +++ b/src/@orb.yml @@ -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' diff --git a/src/commands/install.yml b/src/commands/install.yml new file mode 100755 index 0000000..27513e4 --- /dev/null +++ b/src/commands/install.yml @@ -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: <> + + - when: + condition: + equal: ['windows', << parameters.os >>] + steps: + - run: + name: 'Install CMake' + command: <> + + - when: + condition: + equal: ['linux', << parameters.os >>] + steps: + - run: + name: 'Install CMake' + command: <> + + - 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' diff --git a/src/examples/example.yml b/src/examples/example.yml new file mode 100755 index 0000000..1f2923d --- /dev/null +++ b/src/examples/example.yml @@ -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' diff --git a/src/scripts/install-cmake-linux.sh b/src/scripts/install-cmake-linux.sh new file mode 100644 index 0000000..6513622 --- /dev/null +++ b/src/scripts/install-cmake-linux.sh @@ -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} \ No newline at end of file diff --git a/src/scripts/install-cmake-macos.sh b/src/scripts/install-cmake-macos.sh new file mode 100644 index 0000000..f5e6715 --- /dev/null +++ b/src/scripts/install-cmake-macos.sh @@ -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" \ No newline at end of file diff --git a/src/scripts/install-cmake-windows.sh b/src/scripts/install-cmake-windows.sh new file mode 100644 index 0000000..15e48ca --- /dev/null +++ b/src/scripts/install-cmake-windows.sh @@ -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}