diff --git a/action.yml b/action.yml index 1cd567b..f2d7890 100644 --- a/action.yml +++ b/action.yml @@ -9,7 +9,7 @@ inputs: version: description: "The exact version tag of the go-coverage-report tool to use." required: true - default: "v1.0.1" + default: "main" sha256sum: description: "Optional SHA256 checksum of the tarball when downloading the go-coverage-report binary." @@ -57,10 +57,7 @@ runs: - name: Download go-coverage-report shell: bash id: download - run: $GITHUB_ACTION_PATH/scripts/download-cli-tool.sh "${{ inputs.version }}" "${{ inputs.sha256sum }}" - env: - RUNNER_OS: ${{ runner.os }} - RUNNER_ARCH: ${{ runner.arch }} + run: go install -v "github.com/Striveworks/go-coverage-report@${{ inputs.version }}" - name: Determine changed files id: changed-files diff --git a/scripts/download-cli-tool.sh b/scripts/download-cli-tool.sh deleted file mode 100755 index 466df7c..0000000 --- a/scripts/download-cli-tool.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bash - -set -e -o pipefail - -type curl > /dev/null 2>&1 || { echo >&2 'ERROR: Script requires "curl"'; exit 1; } -type sha256sum > /dev/null 2>&1 || { echo >&2 'ERROR: Script requires "sha256sum"'; exit 1; } -type tar > /dev/null 2>&1 || { echo >&2 'ERROR: Script requires "tar"'; exit 1; } - -USAGE="$0: Download the go-coverage-report binary from GitHub. - -This script is meant to be used as part of a GitHub action and makes use of Workflow commands as -described in https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions - -Usage: - $0 version [sha256sum] - -Example: - $0 Linux X64 - -You can use the following environment variables to configure the script: -- RUNNER_OS: The operating system of the runner (default: Linux) -- RUNNER_ARCH: The architecture of the runner (default: X64) -- DRY_RUN: Do not actually move the binary to /usr/bin (default: false) -" - -if [[ $# == 0 ]]; then - echo -e "Error: script requires at least one argument\n" - echo "$USAGE" - exit 1 -fi - -VERSION=$1 -RUNNER_OS=${RUNNER_OS:-Linux} -RUNNER_ARCH=${RUNNER_ARCH:-X64} - -if [[ -z ${VERSION+x} ]]; then - echo "Missing version argument" - exit 1 -fi - -if [[ $# == 2 ]]; then - SHA256SUM=$2 -fi - -sudo_or_dry_run="sudo" -if [[ "$DRY_RUN" == "true" ]]; then - sudo_or_dry_run='echo [DRY-RUN]: sudo' -fi - -start_group(){ - echo "::group::$*" - { set -x; return; } 2>/dev/null -} - -end_group(){ - { set +x; return; } 2>/dev/null - echo "::endgroup::" -} - -if [[ $VERSION == "local" ]]; then - start_group "Installing go-coverage-report from local source" - go install -v ./cmd/go-coverage-report - end_group - exit 0 -fi - -if [[ ${#VERSION} == 40 ]]; then - start_group "Installing go-coverage-report from remote source" - go install -v "github.com/fgrosse/go-coverage-report@$VERSION" - end_group - exit 0 -fi - -start_group "Determining runner architecture" -if [ "$RUNNER_ARCH" = "ARM64" ]; then - ARCH="arm64" -elif [ "$RUNNER_ARCH" = "ARM" ]; then - ARCH="arm" -elif [ "$RUNNER_ARCH" = "X86" ]; then - ARCH="386" -elif [ "$RUNNER_ARCH" = "X64" ]; then - ARCH="amd64" -else - ARCH="amd64" -fi -end_group - -start_group "Downloading tar archive from GitHub" -mkdir -p .github/outputs -OS=$(echo "$RUNNER_OS" | tr '[:upper:]' '[:lower:]') -FILENAME="go-coverage-report-${VERSION}-${OS}-${ARCH}.tar.gz" -URL="https://github.com/fgrosse/go-coverage-report/releases/download/${VERSION}/${FILENAME}" -curl --fail --location "$URL" --output ".github/outputs/$FILENAME" -end_group - -if ! [[ "$SHA256SUM" ]] ; then - start_group "Checking checksum using checksums.txt file from GitHub release" - URL="https://github.com/fgrosse/go-coverage-report/releases/download/${VERSION}/checksums.txt" - cd .github/outputs - curl -fsSL "$URL" | sha256sum --check --ignore-missing - cd - - end_group -else - start_group "Checking checksum using provided SHA256 hash" - echo "Actual sha256:" - sha256sum ".github/outputs/$FILENAME" - echo "Checking checksum" - echo "$SHA256SUM .github/outputs/$FILENAME" | sha256sum -c - end_group -fi - -start_group "Decompressing tar archive" -tar -xzf ".github/outputs/$FILENAME" -C .github/outputs/ go-coverage-report -rm ".github/outputs/$FILENAME" -end_group - -start_group "Move binary to /usr/bin" -$sudo_or_dry_run mv .github/outputs/go-coverage-report /usr/bin -end_group