Skip to content

Commit

Permalink
fix(install): fix running on windows host (#43)
Browse files Browse the repository at this point in the history
Co-authored-by: Yegor Bayev <233409+kodx@users.noreply.github.com>
  • Loading branch information
kodx and kodx authored Dec 4, 2024
1 parent e364f07 commit 4a4a951
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
21 changes: 14 additions & 7 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ 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)
OS=apple-darwin
;;
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
Expand All @@ -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
Expand All @@ -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}$")"
Expand All @@ -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
Expand Down
18 changes: 12 additions & 6 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)" .
Expand All @@ -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" .
Expand All @@ -31,10 +37,10 @@ chown -R "$owner" .
FILESIZE=$(stat -c%s "$OUTPUT")
MAXSIZE=$((40 * 1024 * 1024))
if [ "$FILESIZE" -le "$MAXSIZE" ]; then
echo "content<<EOF" >>$GITHUB_OUTPUT
cat "$OUTPUT" >>$GITHUB_OUTPUT
echo "EOF" >>$GITHUB_OUTPUT
cat "$OUTPUT"
echo "content<<EOF" >>$GITHUB_OUTPUT
cat "$OUTPUT" >>$GITHUB_OUTPUT
echo "EOF" >>$GITHUB_OUTPUT
cat "$OUTPUT"
fi

# Set output file
Expand Down

0 comments on commit 4a4a951

Please sign in to comment.