Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #247] ♻️ remove dependency on talisman_hook_script #254

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/bash
# Hello there! If you update the talisman version, please remember to:
# - Test that this script works with no args, and the `pre-push` / `pre-commit` arg.
# - also update `install.sh` in the gh_pages branch of this repo, so that
# <https://thoughtworks.github.io/talisman/install.sh> gets updated too.
# Thanks!

set -euo pipefail

HOOK_NAME="${1:-pre-push}"
Expand All @@ -18,9 +24,7 @@ run() {

VERSION="v1.8.0"
GITHUB_URL="https://github.com/thoughtworks/talisman"
GITHUB_RAW_URL="https://raw.githubusercontent.com/thoughtworks/talisman"
BINARY_BASE_URL="$GITHUB_URL/releases/download/$VERSION/talisman"
HOOK_SCRIPT_URL="$GITHUB_RAW_URL/master/global_install_scripts/talisman_hook_script.bash"
REPO_HOOK_BIN_DIR=".git/hooks/bin"

DEFAULT_GLOBAL_TEMPLATE_DIR="$HOME/.git-templates"
Expand Down Expand Up @@ -95,7 +99,6 @@ run() {
ARCH_SUFFIX=$(binary_arch_suffix)

curl --location --silent "${BINARY_BASE_URL}_${ARCH_SUFFIX}" >"${TMP_DIR}/talisman"
curl --location --silent "$HOOK_SCRIPT_URL" >"${TMP_DIR}/talisman_hook_script.bash"

DOWNLOAD_SHA=$(shasum -b -a256 "${TMP_DIR}/talisman" | cut -d' ' -f1)

Expand All @@ -120,7 +123,6 @@ run() {
fi

DOWNLOADED_BINARY="$TMP_DIR/talisman"
DOWNLOADED_HOOK_SCRIPT="${TMP_DIR}/talisman_hook_script.bash"
}

install_to_repo() {
Expand All @@ -138,11 +140,14 @@ run() {
cp "$DOWNLOADED_BINARY" "$TALISMAN_BIN_TARGET"
chmod +x "$TALISMAN_BIN_TARGET"

HOOK_SCRIPT_TARGET="${REPO_HOOK_BIN_DIR}/pre-commit"
cp "$DOWNLOADED_HOOK_SCRIPT" "$HOOK_SCRIPT_TARGET"
chmod +x "$HOOK_SCRIPT_TARGET"

echo "TALISMAN_BINARY=\"${TALISMAN_BIN_TARGET}\" TALISMAN_INTERACTIVE=\"false\" ${HOOK_SCRIPT_TARGET}" >"$REPO_HOOK_TARGET"
cat >"$REPO_HOOK_TARGET" <<EOF
#!/bin/bash
[[ -n "\${TALISMAN_DEBUG}" ]] && DEBUG_OPTS="-d"
CMD="${PWD}/${TALISMAN_BIN_TARGET} \${DEBUG_OPTS} --githook ${HOOK_NAME}"
[[ -n "\${TALISMAN_DEBUG}" ]] && echo "ARGS are \$@"
[[ -n "\${TALISMAN_DEBUG}" ]] && echo "Executing: \${CMD}"
\${CMD}
EOF
chmod +x "$REPO_HOOK_TARGET"

echo_success "Talisman successfully installed to '$REPO_HOOK_TARGET'."
Expand Down