Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
domino14 committed Jan 24, 2024
0 parents commit 5965c90
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
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) 2024 CodeComet

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.
37 changes: 37 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# action.yml
name: 'Install and run tests'
description: 'Install the CodeComet CLI and run tests'
inputs:
version: # id of input
description: 'The version of the CodeComet CLI to install'
required: true
default: '0.1.0'
test-suite:
description: 'The name of your test suite'
required: false
default: ''
test-command:
description: 'The test command you wish to run. If left blank, will not run any commands. You will be able to use the codecomet executable later in your action.'
required: false
default: ''
runs:
using: 'composite'
steps:
- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
shell: bash
- name: "Install codecomet"
run: install.sh ${{ inputs.version }}
shell: bash
- name: "Print out env variables"
run: env
shell: bash
- name: "Run tests"
if: ${{ inputs.test-suite != '' && inputs.test-command != ''}}
run: codecomet -s ${{ inputs.test-suite }} -- ${{ inputs.test-command }}
shell: bash
- name: "Run tests"
if: ${{ inputs.test-suite == '' && inputs.test-command != ''}}
run: codecomet -- ${{ inputs.test-command }}
shell: bash
# Otherwise if inputs.test-command is empty, don't run anything. User can use
# the codecomet cli directly.
105 changes: 105 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env bash
# Based on https://github.com/CircleCI-Public/github-cli-orb/blob/main/src/scripts/install.sh
set_sudo() {
if [[ $EUID == 0 ]]; then
echo ""
else
echo "sudo"
fi
}

# Function to check if a version is greater than or equal to a given version
version_ge() {
test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"
}

# Function to check if a version is less than or equal to a given version
version_le() {
test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" == "$1"
}

detect_platform() {
case "$(uname -s)-$(uname -m)" in
"Linux-x86_64") echo "linux-x86_64" ;;
# "Linux-aarch64") echo "linux-arm64" ;;
*) echo "unsupported" ;;
esac
}

download_cc_cli() {
local version=$1
local platform=$2
local file_extension=$3
local download_url="https://github.com/codecomet-io/cli/releases/download/v${version}/codecomet-v${version}-${platform}.${file_extension}"
echo "Downloading the CodeComet CLI from \"$download_url\"..."

if ! curl -sSL "$download_url" -o "cc-cli.$file_extension"; then
echo "Failed to download CodeComet CLI from $download_url" >&2
return 1
fi
}

install_cc_cli() {
local platform=$1
local file_extension=$2
local file_path="cc-cli.$file_extension"

if [ ! -f "$file_path" ]; then
echo "Downloaded file $file_path does not exist." >&2
return 1
fi

echo "Installing the CodeComet CLI..."
set -x; $sudo unzip -d /usr/local/bin ./"$file_path" ; set +x

}

sudo=$(set_sudo)

# Check for required commands
for cmd in curl unzip; do
if ! command -v "$cmd" &>/dev/null; then
echo "Error: $cmd is required. Please install it and try again." >&2
exit 1
fi
done

# Verify if the CLI is already installed. Exit if it is.
if command -v codecomet >/dev/null 2>&1; then
echo "CodeComet CLI is already installed."
exit 0
fi

version=$1

platform=$(detect_platform)
if [ "$platform" == "unsupported" ]; then
echo "$(uname -a)-$(uname -m) is not supported. If you believe it should be, please consider opening an issue."
exit 1
fi

file_extension="zip"

# Download and install CodeComet CLI
if ! download_cc_cli "$version" "$platform" "$file_extension"; then
echo "Failed to download the CodeComet CLI."
exit 1
fi

if ! install_cc_cli "$platform" "$file_extension"; then
echo "Failed to install the CodeComet CLI."
exit 1
fi

# Clean up
if ! rm "cc-cli.$file_extension"; then
echo "Failed to remove the downloaded file."
fi

# Verify installation
if ! command -v codecomet >/dev/null 2>&1; then
echo "Something went wrong installing the CodeComet CLI. Please try again or open an issue."
exit 1
else
codecomet -h
fi

0 comments on commit 5965c90

Please sign in to comment.