Skip to content

Commit

Permalink
Deal with different types of runniing, and output snyk version
Browse files Browse the repository at this point in the history
  • Loading branch information
garethr committed Sep 13, 2020
1 parent 8b57461 commit 8351bef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
9 changes: 8 additions & 1 deletion setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ inputs:
snyk-version:
description: "Which Snyk version to install"
default: latest
outputs:
version:
description: "The version of Snyk installed"
value: ${{ steps.version.outputs.version }}
runs:
using: "composite"
steps:
- run: ${{ github.action_path }}/setup_snyk.sh ${{ inputs.snyk-version }}
- run: ${{ github.action_path }}/setup_snyk.sh ${{ inputs.snyk-version }} ${{ runner.os }}
shell: bash
- id: version
shell: bash
run: echo "::set-output name=version::$(snyk version)"
31 changes: 22 additions & 9 deletions setup/setup_snyk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,42 @@ die () {
exit 1
}

[ "$#" -eq 1 ] || die "Setup Snyk requires a single argument, $# provided"
[ "$#" -eq 2 ] || die "Setup Snyk requires two argument, $# provided"

echo "Installing the $1 version of Snyk"
echo "Installing the $1 version of Snyk on $2"

if [ "$1" == "latest" ]; then
URL="https://api.github.com/repos/snyk/snyk/releases/${1}"
else
URL="https://api.github.com/repos/snyk/snyk/releases/tags/${1}"
fi

case "$2" in
Linux)
PREFIX=linux
;;
Windows)
die "Windows runner not currently supported"
;;
macOS)
PREFIX=macos
;;
*)
die "Invalid running specified: $2"
esac

{
echo "#!/bin/bash"
echo export SNYK_INTEGRATION_NAME="GITHUB_ACTIONS"
echo export SNYK_INTEGRATION_VERSION="setup"
echo eval snyk-linux \$@
echo export SNYK_INTEGRATION_VERSION="setup (${2})"
echo eval snyk-${PREFIX} \$@
} > snyk

chmod +x snyk
sudo mv snyk /usr/local/bin

wget -qO- ${URL} | grep "browser_download_url" | grep linux | cut -d '"' -f 4 | wget --progress=bar:force:noscroll -i -

sha256sum -c snyk-linux.sha256
chmod +x snyk-linux
sudo mv snyk-linux /usr/local/bin
wget -qO- ${URL} | grep "browser_download_url" | grep $PREFIX | cut -d '"' -f 4 | wget --progress=bar:force:noscroll -i -

sha256sum -c snyk-${PREFIX}.sha256
chmod +x snyk-${PREFIX}
sudo mv snyk-${PREFIX} /usr/local/bin

0 comments on commit 8351bef

Please sign in to comment.