-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
85 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,59 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'fileutils' | ||
require 'open3' | ||
require 'open-uri' | ||
|
||
class Style | ||
class << self | ||
INSTALLER_URL = 'https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh' | ||
EXECUTABLE = 'golangci-lint' | ||
VERSION = '1.49.0' | ||
VERSION_TAG = "v#{VERSION}" | ||
|
||
def call | ||
install unless up_to_date? | ||
run(*ARGV) | ||
end | ||
|
||
private | ||
|
||
def install_path | ||
gopath = ENV.fetch('GOPATH', ENV.fetch('HOME')).split(':').first | ||
File.join(gopath, 'bin') | ||
end | ||
|
||
def bin_path | ||
File.join(install_path, EXECUTABLE) | ||
end | ||
|
||
def exist? | ||
File.executable?(bin_path) | ||
end | ||
|
||
def up_to_date? | ||
return false unless exist? | ||
out, stat = Open3.capture2(bin_path, '--version') | ||
raise("Unable to check version of #{bin_path}") unless stat.success? | ||
out.match(/\b#{VERSION}\b/) | ||
end | ||
|
||
def install | ||
puts "Installing #{EXECUTABLE}..." | ||
|
||
open(INSTALLER_URL) do |installer| | ||
Open3.popen2('sh', '-s', '--', '-b', install_path, VERSION_TAG) do |stdin, out, stat| | ||
IO.copy_stream(installer, stdin) | ||
stdin.close | ||
print out.read | ||
|
||
raise("failed to install #{EXECUTABLE} #{VERSION_TAG}") unless stat.value.success? | ||
end | ||
end | ||
end | ||
|
||
def run(*argv) | ||
config = ENV.fetch('GOLANGCI_CONFIG', '.golangci.yml') | ||
exec(bin_path, 'run', '--config', config, *argv) | ||
end | ||
end | ||
end | ||
|
||
__FILE__ == $PROGRAM_NAME and Style.call | ||
#!/bin/sh | ||
|
||
# This script is intentionally written to be POSIX compliant to be as portable as possible | ||
|
||
set -e | ||
|
||
VERSION="1.51.1" | ||
VERSION_TAG="v${VERSION}" | ||
|
||
INSTALLER_URL="github.com/golangci/golangci-lint/cmd/golangci-lint" | ||
EXECUTABLE="$(basename "${INSTALLER_URL}")" | ||
|
||
INSTALL_PATH="${HOME}/.local/share/${EXECUTABLE}/${VERSION}" | ||
EXECUTABLE_PATH="${INSTALL_PATH}/${EXECUTABLE}" # e.g. $HOME/.local/share/golangci/1.32.0/golangci-lint | ||
|
||
GOPATH="${GOPATH:-${HOME}}" | ||
GOPATH_PRIMARY="${GOPATH%%:*}" # Delete :* from the end, yielding the first path | ||
BIN_INSTALL_PATH="${GOPATH_PRIMARY}/bin" | ||
BIN_EXECUTABLE_PATH="${BIN_INSTALL_PATH}/${EXECUTABLE}" # e.g. $HOME/bin/golangci-lint | ||
|
||
installed() { | ||
[ -x "${EXECUTABLE_PATH}" ] | ||
} | ||
|
||
install() { | ||
echo "Installing ${EXECUTABLE} version ${VERSION}" >&2 | ||
|
||
mkdir -p "${INSTALL_PATH}" | ||
GOBIN="${INSTALL_PATH}" go install "${INSTALLER_URL}@${VERSION_TAG}" | ||
} | ||
|
||
linked() { | ||
[ -L "${BIN_EXECUTABLE_PATH}" ] && [ "$(readlink "${BIN_EXECUTABLE_PATH}")" = "${EXECUTABLE_PATH}" ] | ||
} | ||
|
||
link() { | ||
mkdir -p "${BIN_INSTALL_PATH}" | ||
rm -fv "${BIN_EXECUTABLE_PATH}" | ||
ln -sfv "${EXECUTABLE_PATH}" "${BIN_EXECUTABLE_PATH}" | ||
} | ||
|
||
case "$1" in | ||
"--installed") | ||
installed | ||
;; | ||
"--install") | ||
installed || install | ||
;; | ||
"--linked") | ||
installed && linked | ||
;; | ||
"--link") | ||
(installed || install) && (linked || link) | ||
;; | ||
*) | ||
installed || install | ||
exec "${EXECUTABLE_PATH}" "$@" | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters