From 4a4a951bc43fafe41cd2348d181853f52356bee7 Mon Sep 17 00:00:00 2001 From: Yegor Bayev Date: Wed, 4 Dec 2024 19:45:31 +0300 Subject: [PATCH] fix(install): fix running on windows host (#43) Co-authored-by: Yegor Bayev <233409+kodx@users.noreply.github.com> --- install.sh | 21 ++++++++++++++------- run.sh | 18 ++++++++++++------ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index bfeebf3..42a817d 100755 --- a/install.sh +++ b/install.sh @@ -4,9 +4,11 @@ if [[ -n "$DEBUG" ]]; then set -x fi -set -uo pipefail +set -euo pipefail -ARCHIVE_EXT='.tar.gz' +ARCHIVE_EXT='tar.gz' +ARCHVIE_CMD='tar -xf' +GIT_CLIFF_BIN='git-cliff' case "${RUNNER_OS}" in macOS) @@ -14,7 +16,9 @@ case "${RUNNER_OS}" in ;; Windows) OS=pc-windows-msvc - ARCHIVE_EXT='.zip' + ARCHIVE_EXT='zip' + ARCHVIE_CMD='7z x -aoa' + GIT_CLIFF_BIN="${GIT_CLIFF_BIN}.exe" ;; *) OS=unknown-linux-gnu @@ -27,11 +31,13 @@ case "${RUNNER_ARCH}" in *) ARCH=x86_64 ;; esac +echo "git-cliff-${ARCH}-${OS}.${ARCHIVE_EXT}" + RELEASE_URL='https://api.github.com/repos/orhun/git-cliff/releases/latest' if [[ "${VERSION}" != 'latest' ]]; then RELEASE_URL="https://api.github.com/repos/orhun/git-cliff/releases/tags/${VERSION}" fi -echo "Downloading git-cliff ${VERSION} from ${RELEASE_URL}" +echo "Getting git-cliff ${VERSION} from ${RELEASE_URL}" # Caching is disabled in order not to receive stale responses from Varnish cache fronting GitHub API. if [[ -z "${GITHUB_API_TOKEN}" ]]; then @@ -49,7 +55,7 @@ else fi TAG_NAME="$(echo "${RELEASE_INFO}" | jq --raw-output ".tag_name")" -TARGET="git-cliff-${TAG_NAME:1}-${ARCH}-${OS}${ARCHIVE_EXT}" +TARGET="git-cliff-${TAG_NAME:1}-${ARCH}-${OS}.${ARCHIVE_EXT}" LOCATION="$(echo "${RELEASE_INFO}" | jq --raw-output ".assets[].browser_download_url" | grep "${TARGET}$")" @@ -62,8 +68,9 @@ mkdir -p ./bin if [[ ! -e "$TARGET" ]]; then echo "Downloading ${TARGET}..." curl --silent --show-error --fail --location --output "$TARGET" "$LOCATION" - tar -xf "$TARGET" - mv git-cliff-${TAG_NAME:1}/git-cliff ./bin/git-cliff + echo "Unpacking ${TARGET}..." + ${ARCHVIE_CMD} "$TARGET" + mv git-cliff-${TAG_NAME:1}/${GIT_CLIFF_BIN} ./bin/${GIT_CLIFF_BIN} else echo "Using cached git-cliff binary." fi diff --git a/run.sh b/run.sh index 012a088..2673411 100755 --- a/run.sh +++ b/run.sh @@ -5,6 +5,12 @@ set -uxo pipefail # Avoid file expansion when passing parameters like with '*' set -o noglob +GIT_CLIFF_BIN='git-cliff' + +if [[ "${RUNNER_OS}" == 'Windows' ]]; then + GIT_CLIFF_BIN="${GIT_CLIFF_BIN}.exe" +fi + # Set up working directory owner=$(stat -c "%u:%g" .) chown -R "$(id -u)" . @@ -17,12 +23,12 @@ mkdir -p "$(dirname $OUTPUT)" args=$(echo "$@" | xargs) # Execute git-cliff -GIT_CLIFF_OUTPUT="$OUTPUT" ./bin/git-cliff $args +GIT_CLIFF_OUTPUT="$OUTPUT" ./bin/${GIT_CLIFF_BIN} $args exit_code=$? # Retrieve context CONTEXT="$(mktemp)" -GIT_CLIFF_OUTPUT="$CONTEXT" ./bin/git-cliff $args --context +GIT_CLIFF_OUTPUT="$CONTEXT" ./bin/${GIT_CLIFF_BIN} $args --context # Revert permissions chown -R "$owner" . @@ -31,10 +37,10 @@ chown -R "$owner" . FILESIZE=$(stat -c%s "$OUTPUT") MAXSIZE=$((40 * 1024 * 1024)) if [ "$FILESIZE" -le "$MAXSIZE" ]; then - echo "content<>$GITHUB_OUTPUT - cat "$OUTPUT" >>$GITHUB_OUTPUT - echo "EOF" >>$GITHUB_OUTPUT - cat "$OUTPUT" + echo "content<>$GITHUB_OUTPUT + cat "$OUTPUT" >>$GITHUB_OUTPUT + echo "EOF" >>$GITHUB_OUTPUT + cat "$OUTPUT" fi # Set output file