fix(install): install in temp path instead of user working dir (#51)

* fix: install and run binary from action path instead of working dir

* refactor: use INSTALL_DIR

* refactor: remove GIT_CLIFF_DIR and INSTALL_DIR
This commit is contained in:
Eligio Mariño
2025-04-12 11:19:35 +02:00
committed by GitHub
parent 776c932aba
commit 104a6cf3c9
2 changed files with 12 additions and 6 deletions

View File

@@ -7,7 +7,7 @@ fi
set -euo pipefail
ARCHIVE_EXT='tar.gz'
ARCHVIE_CMD='tar -xf'
ARCHIVE_CMD='tar -xf'
GIT_CLIFF_BIN='git-cliff'
case "${RUNNER_OS}" in
@@ -17,7 +17,7 @@ case "${RUNNER_OS}" in
Windows)
OS=pc-windows-msvc
ARCHIVE_EXT='zip'
ARCHVIE_CMD='7z x -aoa'
ARCHIVE_CMD='7z x -aoa'
GIT_CLIFF_BIN="${GIT_CLIFF_BIN}.exe"
;;
*)
@@ -31,6 +31,10 @@ case "${RUNNER_ARCH}" in
*) ARCH=x86_64 ;;
esac
INSTALL_DIR="$RUNNER_TEMP/git-cliff"
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
echo "git-cliff-${ARCH}-${OS}.${ARCHIVE_EXT}"
RELEASE_URL='https://api.github.com/repos/orhun/git-cliff/releases/latest'
@@ -69,8 +73,8 @@ if [[ ! -e "$TARGET" ]]; then
echo "Downloading ${TARGET}..."
curl --silent --show-error --fail --location --output "$TARGET" "$LOCATION"
echo "Unpacking ${TARGET}..."
${ARCHVIE_CMD} "$TARGET"
mv git-cliff-${TAG_NAME:1}/${GIT_CLIFF_BIN} ./bin/${GIT_CLIFF_BIN}
${ARCHIVE_CMD} "$TARGET"
mv git-cliff-${TAG_NAME:1}/${GIT_CLIFF_BIN} "./bin/$GIT_CLIFF_BIN"
else
echo "Using cached git-cliff binary."
fi

6
run.sh
View File

@@ -11,6 +11,8 @@ if [[ "${RUNNER_OS}" == 'Windows' ]]; then
GIT_CLIFF_BIN="${GIT_CLIFF_BIN}.exe"
fi
GIT_CLIFF_PATH="$RUNNER_TEMP/git-cliff/bin/$GIT_CLIFF_BIN"
# Set up working directory
owner=$(stat -c "%u:%g" .)
chown -R "$(id -u)" .
@@ -23,12 +25,12 @@ mkdir -p "$(dirname $OUTPUT)"
args=$(echo "$@" | xargs)
# Execute git-cliff
GIT_CLIFF_OUTPUT="$OUTPUT" ./bin/${GIT_CLIFF_BIN} $args
GIT_CLIFF_OUTPUT="$OUTPUT" "$GIT_CLIFF_PATH" $args
exit_code=$?
# Retrieve context
CONTEXT="$(mktemp)"
GIT_CLIFF_OUTPUT="$CONTEXT" ./bin/${GIT_CLIFF_BIN} --context $args
GIT_CLIFF_OUTPUT="$CONTEXT" "$GIT_CLIFF_PATH" --context $args
# Revert permissions
chown -R "$owner" .