Skip to content

Commit

Permalink
feat: use own command for github cli install to allow for when use (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ankorstore-haddowg authored Aug 8, 2023
1 parent 191b6fa commit 89f4dad
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/@orb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ description: >
display:
source_url: "https://github.com/ankorstore/orb-toolbelt"

orbs:
github-cli: circleci/[email protected]
2 changes: 1 addition & 1 deletion src/commands/get_pr_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ parameters:
description: If true, this command will fail if there is no associated PR, if false the job will continue anyway.
type: boolean
steps:
- github-cli/install
- install_github_cli
- run:
name: Get PR information
environment:
Expand Down
23 changes: 23 additions & 0 deletions src/commands/install_github_cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
description: >-
Install the gh cli without authenticating or configuring. This command should
be run before invoking the gh cli.
parameters:
version:
default: 2.3.0
description: Specify the full semver versioned tag to use.
type: string
when:
default: on_success
description: When to run this command.
enum:
- always
- on_success
- on_fail
type: enum
steps:
- run:
when: << parameters.when >>
command: << include(scripts/install_github_cli.sh) >>
environment:
PARAM_GH_CLI_VERSION: <<parameters.version>>
name: Install GH CLI v<<parameters.version>>
12 changes: 11 additions & 1 deletion src/commands/post_pr_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ description: >
This command requires a GITHUB_TOKEN env var to be set with a valid GitHub API Token.
parameters:
when:
default: always
description: When to run this command.
enum:
- always
- on_success
- on_fail
type: enum
comment:
default: ""
description: The comment to post on the PR.
Expand All @@ -24,9 +32,11 @@ parameters:
description: If true, this command will fail if there is no associated PR, if false the job will continue anyway.
type: boolean
steps:
- github-cli/install
- install_github_cli:
when: << parameters.when >>
- run:
name: Post PR comment
when: << parameters.when >>
environment:
COMMENT: << parameters.comment >>
COMMENT_FILE: << parameters.comment_file >>
Expand Down
48 changes: 48 additions & 0 deletions src/scripts/install_github_cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
# set smart sudo
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi

# Define current platform
if [[ "$(uname -s)" == "Darwin" && "$(uname -m)" == "x86_64" ]]; then
export SYS_ENV_PLATFORM=macos
elif [[ "$(uname -s)" == "Linux" && "$(uname -m)" == "x86_64" ]]; then
export SYS_ENV_PLATFORM=linux_x86
elif [[ "$(uname -s)" == "Linux" && "$(uname -m)" == "aarch64" ]]; then
export SYS_ENV_PLATFORM=linux_arm
else
echo "This platform appears to be unsupported."
uname -a
exit 1
fi

# If not installed
if ! command -v gh >/dev/null 2>&1; then
echo "Installing the GitHub CLI"
case $SYS_ENV_PLATFORM in
linux_x86)
curl -sSL "https://github.com/cli/cli/releases/download/v${PARAM_GH_CLI_VERSION}/gh_${PARAM_GH_CLI_VERSION}_linux_amd64.deb" -o "gh-cli.deb"
$SUDO apt install ./gh-cli.deb
rm gh-cli.deb
;;
macos)
curl -sSL "https://github.com/cli/cli/releases/download/v${PARAM_GH_CLI_VERSION}/gh_${PARAM_GH_CLI_VERSION}_macOS_amd64.tar.gz" -o "gh-cli.tar.gz"
$SUDO tar -xf ./gh-cli.tar.gz -C /usr/local/ --strip-components=1
rm gh-cli.tar.gz
;;
linux_arm)
curl -sSL "https://github.com/cli/cli/releases/download/v${PARAM_GH_CLI_VERSION}/gh_${PARAM_GH_CLI_VERSION}_linux_arm64.tar.gz" -o "gh-cli.tar.gz"
$SUDO tar -xf ./gh-cli.tar.gz -C /usr/local/ --strip-components=1
rm gh-cli.tar.gz
;;
*)
echo "This orb does not currently support your platform."
exit 1
;;
esac
# Validate install.
echo
echo "GH CLI installed"
command -v gh
else
echo "GH CLI is already installed."
fi

0 comments on commit 89f4dad

Please sign in to comment.