fix(install): fix running on windows host (#43)

Co-authored-by: Yegor Bayev <233409+kodx@users.noreply.github.com>
This commit is contained in:
Yegor Bayev
2024-12-04 19:45:31 +03:00
committed by GitHub
parent e364f07989
commit 4a4a951bc4
2 changed files with 26 additions and 13 deletions

View File

@@ -4,9 +4,11 @@ if [[ -n "$DEBUG" ]]; then
set -x set -x
fi 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 case "${RUNNER_OS}" in
macOS) macOS)
@@ -14,7 +16,9 @@ case "${RUNNER_OS}" in
;; ;;
Windows) Windows)
OS=pc-windows-msvc 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 OS=unknown-linux-gnu
@@ -27,11 +31,13 @@ case "${RUNNER_ARCH}" in
*) ARCH=x86_64 ;; *) ARCH=x86_64 ;;
esac esac
echo "git-cliff-${ARCH}-${OS}.${ARCHIVE_EXT}"
RELEASE_URL='https://api.github.com/repos/orhun/git-cliff/releases/latest' RELEASE_URL='https://api.github.com/repos/orhun/git-cliff/releases/latest'
if [[ "${VERSION}" != 'latest' ]]; then if [[ "${VERSION}" != 'latest' ]]; then
RELEASE_URL="https://api.github.com/repos/orhun/git-cliff/releases/tags/${VERSION}" RELEASE_URL="https://api.github.com/repos/orhun/git-cliff/releases/tags/${VERSION}"
fi 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. # Caching is disabled in order not to receive stale responses from Varnish cache fronting GitHub API.
if [[ -z "${GITHUB_API_TOKEN}" ]]; then if [[ -z "${GITHUB_API_TOKEN}" ]]; then
@@ -49,7 +55,7 @@ else
fi fi
TAG_NAME="$(echo "${RELEASE_INFO}" | jq --raw-output ".tag_name")" 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}" | LOCATION="$(echo "${RELEASE_INFO}" |
jq --raw-output ".assets[].browser_download_url" | jq --raw-output ".assets[].browser_download_url" |
grep "${TARGET}$")" grep "${TARGET}$")"
@@ -62,8 +68,9 @@ mkdir -p ./bin
if [[ ! -e "$TARGET" ]]; then if [[ ! -e "$TARGET" ]]; then
echo "Downloading ${TARGET}..." echo "Downloading ${TARGET}..."
curl --silent --show-error --fail --location --output "$TARGET" "$LOCATION" curl --silent --show-error --fail --location --output "$TARGET" "$LOCATION"
tar -xf "$TARGET" echo "Unpacking ${TARGET}..."
mv git-cliff-${TAG_NAME:1}/git-cliff ./bin/git-cliff ${ARCHVIE_CMD} "$TARGET"
mv git-cliff-${TAG_NAME:1}/${GIT_CLIFF_BIN} ./bin/${GIT_CLIFF_BIN}
else else
echo "Using cached git-cliff binary." echo "Using cached git-cliff binary."
fi fi

18
run.sh
View File

@@ -5,6 +5,12 @@ set -uxo pipefail
# Avoid file expansion when passing parameters like with '*' # Avoid file expansion when passing parameters like with '*'
set -o noglob 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 # Set up working directory
owner=$(stat -c "%u:%g" .) owner=$(stat -c "%u:%g" .)
chown -R "$(id -u)" . chown -R "$(id -u)" .
@@ -17,12 +23,12 @@ mkdir -p "$(dirname $OUTPUT)"
args=$(echo "$@" | xargs) args=$(echo "$@" | xargs)
# Execute git-cliff # Execute git-cliff
GIT_CLIFF_OUTPUT="$OUTPUT" ./bin/git-cliff $args GIT_CLIFF_OUTPUT="$OUTPUT" ./bin/${GIT_CLIFF_BIN} $args
exit_code=$? exit_code=$?
# Retrieve context # Retrieve context
CONTEXT="$(mktemp)" CONTEXT="$(mktemp)"
GIT_CLIFF_OUTPUT="$CONTEXT" ./bin/git-cliff $args --context GIT_CLIFF_OUTPUT="$CONTEXT" ./bin/${GIT_CLIFF_BIN} $args --context
# Revert permissions # Revert permissions
chown -R "$owner" . chown -R "$owner" .
@@ -31,10 +37,10 @@ chown -R "$owner" .
FILESIZE=$(stat -c%s "$OUTPUT") FILESIZE=$(stat -c%s "$OUTPUT")
MAXSIZE=$((40 * 1024 * 1024)) MAXSIZE=$((40 * 1024 * 1024))
if [ "$FILESIZE" -le "$MAXSIZE" ]; then if [ "$FILESIZE" -le "$MAXSIZE" ]; then
echo "content<<EOF" >>$GITHUB_OUTPUT echo "content<<EOF" >>$GITHUB_OUTPUT
cat "$OUTPUT" >>$GITHUB_OUTPUT cat "$OUTPUT" >>$GITHUB_OUTPUT
echo "EOF" >>$GITHUB_OUTPUT echo "EOF" >>$GITHUB_OUTPUT
cat "$OUTPUT" cat "$OUTPUT"
fi fi
# Set output file # Set output file