diff --git a/.trunk/.gitignore b/.trunk/.gitignore index cf2f25470..695b51906 100644 --- a/.trunk/.gitignore +++ b/.trunk/.gitignore @@ -5,3 +5,4 @@ plugins user_trunk.yaml user.yaml +tools diff --git a/.trunk/configs/svgo.config.js b/.trunk/configs/svgo.config.js new file mode 100644 index 000000000..b257d1349 --- /dev/null +++ b/.trunk/configs/svgo.config.js @@ -0,0 +1,14 @@ +module.exports = { + plugins: [ + { + name: "preset-default", + params: { + overrides: { + removeViewBox: false, // https://github.com/svg/svgo/issues/1128 + sortAttrs: true, + removeOffCanvasPaths: true, + }, + }, + }, + ], +}; diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index ba71f43b0..91d4b99a9 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,25 +1,26 @@ version: 0.1 cli: - version: 1.6.1 + version: 1.13.0 plugins: sources: - id: trunk - ref: v0.0.13 + ref: v1.0.0 uri: https://github.com/trunk-io/plugins lint: enabled: - - cspell@6.31.1 - - actionlint@1.6.23 - - black@23.1.0 + - svgo@3.0.2 + - cspell@6.31.2 + - actionlint@1.6.25 + - black@23.7.0 - git-diff-check - - gitleaks@8.16.1 + - gitleaks@8.17.0 - isort@5.12.0 - - markdownlint@0.33.0 + - markdownlint@0.35.0 - oxipng@8.0.0 - - prettier@2.8.5 - - ruff@0.0.257 - - taplo@0.7.0 - - yamllint@1.29.0 + - prettier@3.0.0 + - ruff@0.0.280 + - taplo@0.8.1 + - yamllint@1.32.0 ignore: - linters: [prettier] paths: diff --git a/trunk b/trunk index 24a2be32e..7c1bf72af 100755 --- a/trunk +++ b/trunk @@ -8,7 +8,7 @@ set -euo pipefail -readonly TRUNK_LAUNCHER_VERSION="1.2.3" # warning: this line is auto-updated +readonly TRUNK_LAUNCHER_VERSION="1.2.5" # warning: this line is auto-updated readonly SUCCESS_MARK="\033[0;32m✔\033[0m" readonly FAIL_MARK="\033[0;31m✘\033[0m" @@ -18,6 +18,9 @@ readonly PROGRESS_MARKS=("⡿" "⢿" "⣻" "⣽" "⣾" "⣷" "⣯" "⣟") readonly TMPDIR="${TMPDIR:-/tmp}" KERNEL=$(uname | tr "[:upper:]" "[:lower:]") +if [[ ${KERNEL} == mingw64* || ${KERNEL} == msys* ]]; then + KERNEL="mingw" +fi readonly KERNEL MACHINE=$(uname -m) @@ -34,19 +37,22 @@ readonly PLATFORM_UNDERSCORE # [0K is "erase display" and clears from the cursor to the end of the screen readonly CLEAR_LAST_MSG="\033[1F\033[0K" -# NOTE(sam): TRUNK_LAUNCHER_QUIET was originally TRUNK_QUIET; it was renamed after 0.7.0-beta.9 -readonly TRUNK_LAUNCHER_QUIET=${TRUNK_LAUNCHER_QUIET:-${TRUNK_QUIET:-false}} +if [[ ! -z ${CI:-} && "${CI}" = true && -z ${TRUNK_LAUNCHER_QUIET:-} ]]; then + TRUNK_LAUNCHER_QUIET=1 +else + TRUNK_LAUNCHER_QUIET=${TRUNK_LAUNCHER_QUIET:-${TRUNK_QUIET:-false}} +fi + readonly TRUNK_LAUNCHER_DEBUG if [[ ${TRUNK_LAUNCHER_QUIET} != false ]]; then exec 3>&1 4>&2 &>/dev/null fi - TRUNK_CACHE="${TRUNK_CACHE:-}" -if [[ -n "${TRUNK_CACHE}" ]]; then +if [[ -n ${TRUNK_CACHE} ]]; then : -elif [[ -n "${XDG_CACHE_HOME:-}" ]]; then +elif [[ -n ${XDG_CACHE_HOME:-} ]]; then TRUNK_CACHE="${XDG_CACHE_HOME}/trunk" else TRUNK_CACHE="${HOME}/.cache/trunk" @@ -62,28 +68,32 @@ check_darwin_version() { osx_version="$(sw_vers -productVersion)" # trunk-ignore-begin(shellcheck/SC2312): the == will fail if anything inside the $() fails - if [[ "$(printf "%s\n%s\n" "${MINIMUM_MACOS_VERSION}" "${osx_version}" | \ - sort --version-sort | \ - head -n 1)" == "${MINIMUM_MACOS_VERSION}"* ]]; then + if [[ "$(printf "%s\n%s\n" "${MINIMUM_MACOS_VERSION}" "${osx_version}" | + sort --version-sort | + head -n 1)" == "${MINIMUM_MACOS_VERSION}"* ]]; then return fi # trunk-ignore-end(shellcheck/SC2312) echo -e "${FAIL_MARK} Trunk requires at least MacOS ${MINIMUM_MACOS_VERSION}" \ - "(yours is ${osx_version}). See https://docs.trunk.io for more info." + "(yours is ${osx_version}). See https://docs.trunk.io for more info." exit 1 } + if [[ ${PLATFORM} == "darwin-x86_64" || ${PLATFORM} == "darwin-arm64" ]]; then check_darwin_version -elif [[ ${PLATFORM} == "linux-x86_64" ]]; then +elif [[ ${PLATFORM} == "linux-x86_64" || ${PLATFORM} == "windows-x86_64" || ${PLATFORM} == "mingw-x86_64" ]]; then : else - echo -e "${FAIL_MARK} Trunk is only supported on Linux (x64_64) and MacOS (x86_64, arm64)." \ - "See https://docs.trunk.io for more info." + echo -e "${FAIL_MARK} Trunk is only supported on Linux (x64_64), MacOS (x86_64, arm64), and Windows (x86_64)." \ + "See https://docs.trunk.io for more info." exit 1 fi -TRUNK_TMPDIR="${TMPDIR}/trunk-$(set -e; id -u)/launcher_logs" +TRUNK_TMPDIR="${TMPDIR}/trunk-$( + set -e + id -u +)/launcher_logs" readonly TRUNK_TMPDIR mkdir -p "${TRUNK_TMPDIR}" @@ -93,7 +103,7 @@ readonly TOOL_TMPDIR cleanup() { rm -rf "${TOOL_TMPDIR}" - if [[ "$1" == "0" ]]; then + if [[ $1 == "0" ]]; then rm -rf "${TRUNK_TMPDIR}" fi } @@ -131,14 +141,20 @@ awk_test() { # trunk-ignore-begin(shellcheck/SC2310,shellcheck/SC2312) # SC2310 and SC2312 are about set -e not propagating to the $(); if that happens, the string # comparison will fail and we'll claim the user's awk doesn't work - if [[ $(set -e; printf 'k1: v1\n \tk2: v2\r\n' | lawk '/[ \t]+k2:/{print $2}') == 'v2' && \ - $(set -e; printf 'k1: v1\r\n\t k2: v2\r\n' | lawk '/[ \t]+k2:/{print $2}') == 'v2' ]]; then + if [[ $( + set -e + printf 'k1: v1\n \tk2: v2\r\n' | lawk '/[ \t]+k2:/{print $2}' + ) == 'v2' && + $( + set -e + printf 'k1: v1\r\n\t k2: v2\r\n' | lawk '/[ \t]+k2:/{print $2}' + ) == 'v2' ]]; then return fi # trunk-ignore-end(shellcheck/SC2310,shellcheck/SC2312) echo -e "${FAIL_MARK} Trunk does not work with your awk;" \ - "please report this at https://slack.trunk.io." + "please report this at https://slack.trunk.io." echo -e "Your version of awk is:" awk --version || awk -Wversion exit 1 @@ -147,7 +163,10 @@ awk_test readonly CURL_FLAGS="${CURL_FLAGS:- -vvv --max-time 120 --retry 3 --fail}" readonly WGET_FLAGS="${WGET_FLAGS:- --verbose --tries=3 --limit-rate=10M}" -TMP_DOWNLOAD_LOG="${TRUNK_TMPDIR}/download-$(set -e; dt_str).log" +TMP_DOWNLOAD_LOG="${TRUNK_TMPDIR}/download-$( + set -e + dt_str +).log" readonly TMP_DOWNLOAD_LOG # Detect whether we should use wget or curl. @@ -221,22 +240,25 @@ download_url() { while [[ -d "/proc/${download_pid}" && -n ${progress_message} ]]; do echo -e "${CLEAR_LAST_MSG}${PROGRESS_MARKS[${i_prog}]} ${progress_message}..." sleep 0.2 - i_prog=$(( (i_prog + 1) % ${#PROGRESS_MARKS[@]} )) + i_prog=$(((i_prog + 1) % ${#PROGRESS_MARKS[@]})) done local download_log if ! wait "${download_pid}"; then - download_log="${TRUNK_TMPDIR}/launcher-download-$(set -e; dt_str).log" + download_log="${TRUNK_TMPDIR}/launcher-download-$( + set -e + dt_str + ).log" mv "${TMP_DOWNLOAD_LOG}" "${download_log}" echo -e "${CLEAR_LAST_MSG}${FAIL_MARK} ${progress_message}... FAILED (see ${download_log})" echo -e "Please check your connection and try again." \ - "If you continue to see this error message," \ - "consider reporting it to us at https://slack.trunk.io." + "If you continue to see this error message," \ + "consider reporting it to us at https://slack.trunk.io." exit 1 fi if [[ -n ${progress_message} ]]; then - echo -e "${CLEAR_LAST_MSG}${SUCCESS_MARK} ${progress_message}... done" + echo -e "${CLEAR_LAST_MSG}${SUCCESS_MARK} ${progress_message}... done" fi } @@ -277,10 +299,13 @@ read_cli_version_from() { local config_abspath="${1}" local cli_version - cli_version="$(set -e; lawk '/[ \t]+version:/{print $2; exit;}' "${config_abspath}")" + cli_version="$( + set -e + lawk '/[ \t]+version:/{print $2; exit;}' "${config_abspath}" + )" if [[ -z ${cli_version} ]]; then echo -e "${FAIL_MARK} Invalid .trunk/trunk.yaml, no cli version found." \ - "See https://docs.trunk.io for more info." >&2 + "See https://docs.trunk.io for more info." >&2 exit 1 fi @@ -299,11 +324,11 @@ download_cli() { if sort --help 2>&1 | grep BusyBox; then readonly URL="https://trunk.io/releases/${dl_version}/trunk-${dl_version}-${PLATFORM}.tar.gz" else - if [[ "$(printf "%s\n%s\n" "${TRUNK_NEW_URL_VERSION}" "${dl_version}" | \ - sort --version-sort | \ - head -n 1)" == "${TRUNK_NEW_URL_VERSION}"* ]]; then + if [[ "$(printf "%s\n%s\n" "${TRUNK_NEW_URL_VERSION}" "${dl_version}" | + sort --version-sort | + head -n 1 || true)" == "${TRUNK_NEW_URL_VERSION}"* ]]; then readonly URL="https://trunk.io/releases/${dl_version}/trunk-${dl_version}-${PLATFORM}.tar.gz" - else + else readonly URL="https://trunk.io/releases/trunk-${dl_version}.${KERNEL}.tar.gz" fi fi @@ -316,7 +341,10 @@ download_cli() { local verifying_text="Verifying Trunk sha256..." echo -e "${PROGRESS_MARKS[0]} ${verifying_text}" - actual_sha256="$(set -e; sha256sum "${DOWNLOAD_TAR_GZ}" | lawk '{print $1}')" + actual_sha256="$( + set -e + sha256sum "${DOWNLOAD_TAR_GZ}" | lawk '{print $1}' + )" if [[ ${actual_sha256} != "${expected_sha256}" ]]; then echo -e "${CLEAR_LAST_MSG}${FAIL_MARK} ${verifying_text} FAILED" @@ -341,7 +369,7 @@ download_cli() { if [[ ! -e ${OLD_TOOL_DIR} ]]; then ln -sf "${TOOL_PART}" "${OLD_TOOL_DIR}" fi - mv -n "${TMP_INSTALL_DIR}/trunk" "${TOOL_DIR}/" + mv -n "${TMP_INSTALL_DIR}/trunk" "${TOOL_DIR}/" || true rm -rf "${TMP_INSTALL_DIR}" } @@ -351,20 +379,35 @@ download_cli() { # # ############################################################################### -CONFIG_ABSPATH="$(set -e; trunk_yaml_abspath)" +CONFIG_ABSPATH="$( + set -e + trunk_yaml_abspath +)" readonly CONFIG_ABSPATH version="${TRUNK_CLI_VERSION:-}" if [[ -n ${version:-} ]]; then : elif [[ -f ${CONFIG_ABSPATH} ]]; then - version="$(set -e; read_cli_version_from "${CONFIG_ABSPATH}")" - version_sha256="$(set -e; lawk "/${PLATFORM_UNDERSCORE}:/"'{print $2}' "${CONFIG_ABSPATH}")" + version="$( + set -e + read_cli_version_from "${CONFIG_ABSPATH}" + )" + version_sha256="$( + set -e + lawk "/${PLATFORM_UNDERSCORE}:/"'{print $2}' "${CONFIG_ABSPATH}" + )" else readonly LATEST_FILE="${LAUNCHER_TMPDIR}/latest" download_url "https://trunk.io/releases/latest" "${LATEST_FILE}" - version=$(set -e; lawk '/version:/{print $2}' "${LATEST_FILE}") - version_sha256=$(set -e; lawk "/${PLATFORM_UNDERSCORE}:/"'{print $2}' "${LATEST_FILE}") + version=$( + set -e + lawk '/version:/{print $2}' "${LATEST_FILE}" + ) + version_sha256=$( + set -e + lawk "/${PLATFORM_UNDERSCORE}:/"'{print $2}' "${LATEST_FILE}" + ) fi readonly TOOL_PART="${version}-${PLATFORM}" @@ -386,7 +429,7 @@ fi ############################################################################### if [[ -n ${LATEST_FILE:-} ]]; then - mv -n "${LATEST_FILE}" "${TOOL_DIR}/version" + mv -n "${LATEST_FILE}" "${TOOL_DIR}/version" >/dev/null 2>&1 || true fi # NOTE: exec will overwrite the process image, so trap will not catch the exit signal.