From b13283e664501d351d158401c4ad57bbd134e8d9 Mon Sep 17 00:00:00 2001 From: Sameer Naik Date: Thu, 1 Dec 2022 16:31:00 +0530 Subject: [PATCH] tgoreleaser: generate completions from brew Formula --- .goreleaser.yaml | 9 +++++++-- README.md | 5 +++-- hack/install.sh | 27 ++++++++++++++++++++++----- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index e56be66a..b8a72127 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -24,10 +24,12 @@ builds: archives: - id: default - format: binary - name_template: '{{ .Binary }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}' + name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}' replacements: darwin: macOS + format_overrides: + - goos: windows + format: zip checksum: name_template: 'checksums.txt' @@ -52,3 +54,6 @@ brews: owner: triggermesh name: homebrew-cli token: "{{ .Env.TAP_GITHUB_TOKEN }}" + install: | + bin.install "tmctl" + generate_completions_from_executable(bin/"tmctl", "completion", shells: [:bash, :zsh]) diff --git a/README.md b/README.md index 7acf09b5..2241f6c4 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,9 @@ brew install triggermesh/cli/tmctl Download and install the latest version for your platform from the [releases page](https://github.com/triggermesh/tmctl/releases). For example, ```bash -curl -L https://github.com/triggermesh/tmctl/releases/latest/download/tmctl_macOS_amd64 -o /tmp/tmctl -mv /tmp/tmctl /usr/local/bin/tmctl +curl -L https://github.com/triggermesh/tmctl/releases/latest/download/tmctl_macOS_amd64.tar.gz +tar -zxf tmctl_macOS_amd64.tar.gz +mv tmctl /usr/local/bin/tmctl chmod +x /usr/local/bin/tmctl ``` diff --git a/hack/install.sh b/hack/install.sh index c99c4c83..afc55e86 100644 --- a/hack/install.sh +++ b/hack/install.sh @@ -6,7 +6,6 @@ PKG_VERSION= GITHUB_URL=https://github.com/triggermesh/tmctl PLATFORM= -EXT= ARCH= SUDO=sudo @@ -36,6 +35,7 @@ if [ -z "${BIN_DIR}" ]; then fi # os platform +EXT=".tar.gz" if [ -z "${PLATFORM}" ]; then case $(uname) in Linux) @@ -46,7 +46,7 @@ if [ -z "${PLATFORM}" ]; then ;; Windows) PLATFORM="windows" - EXT=".exe" + EXT=".zip" ;; *) fatal "Unsupported platform ${PLATFORM}" @@ -82,9 +82,26 @@ else DOWNLOAD_URL="${GITHUB_URL}/releases/latest/download/${PKG_NAME}_${PLATFORM}_${ARCH}${EXT}" fi -info "Downloading ${DOWNLOAD_URL}..." -TMP_BIN=$(mktemp -u /tmp/${PKG_NAME}.XXXXXX) -${CURL} -sfL ${DOWNLOAD_URL} -o ${TMP_BIN} +TMP_DIR=$(mktemp -d -t tmctl-install.XXXXXX) +TMP_ARCHIVE=${TMP_DIR}/${PKG_NAME}_${PLATFORM}_${ARCH}${EXT} +TMP_BIN=${TMP_DIR}/tmctl +cleanup() { + code=$? + set +e + trap - EXIT + rm -rf ${TMP_DIR} + exit $code +} +trap cleanup INT EXIT + +info "Downloading ${DOWNLOAD_URL}... to ${TMP_ARCHIVE}" +${CURL} -sfL ${DOWNLOAD_URL} -o ${TMP_ARCHIVE} + +if [ "${EXT}" = ".zip" ]; then + unzip ${TMP_ARCHIVE} -d ${TMP_DIR} +else + tar xzf ${TMP_ARCHIVE} -C ${TMP_DIR} +fi info "Installing to ${BIN_DIR}/${PKG_NAME}" chmod 755 ${TMP_BIN}