diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f443076 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +.idea +bin +dist \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..2e0774c --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,26 @@ +builds: + - binary: go-cli-boilerplate + goos: + - windows + - darwin + - linux + - openbsd + - freebsd + goarch: + - amd64 + - arm + - arm64 + - 386 + goarm: + - 6 + - 7 + env: + - CGO_ENABLED=0 + flags: + - -mod=vendor + - -trimpath + +archives: + - files: + - none* + name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}" diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7f9c1d5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "go.addTags": { + "tags": "json", + "options": "json=omitempty", + "promptForTags": false, + "transform": "snakecase" + }, + "go.buildFlags": ["-mode=vendor"], + "go.toolsEnvVars": { + "GOFLAGS": "-mod=vendor" + } +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cf7bf2d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Axetroy + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e06a936 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +test: + go test --cover -covermode=count -coverprofile=coverage.out ./... + +build: + goreleaser release --snapshot --rm-dist --skip-publish + +lint: + golangci-lint run ./... -v + +format: + go fmt ./... + +format-check: + gofmt -l ./internal main.go \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4a199cf --- /dev/null +++ b/README.md @@ -0,0 +1,84 @@ +[![Build Status](https://github.com/axetroy/go-cli-boilerplate/workflows/ci/badge.svg)](https://github.com/axetroy/go-cli-boilerplate/actions) +[![Go Report Card](https://goreportcard.com/badge/github.com/axetroy/go-cli-boilerplate)](https://goreportcard.com/report/github.com/axetroy/go-cli-boilerplate) +![Latest Version](https://img.shields.io/github/v/release/axetroy/go-cli-boilerplate.svg) +![License](https://img.shields.io/github/license/axetroy/go-cli-boilerplate.svg) +![Repo Size](https://img.shields.io/github/repo-size/axetroy/go-cli-boilerplate.svg) + +## go-cli-boilerplate + +`go-cli-boilerplate` is a command-line tool to manage Deno versions. + +Focus on the simplest way to manage versions. + +Features: + +- [x] Cross-platform support +- [x] Easy to use +- [x] No runtime dependencies +- [x] Zero configuration +- [x] Fully compatible with installed Deno + +### Usage + +```bash + +``` + +### Installation + +If you are using Linux/macOS. you can install it with the following command: + +```shell +# install latest version +curl -fsSL https://raw.githubusercontent.com/axetroy/go-cli-boilerplate/master/install.sh | bash +# or install specified version +curl -fsSL https://raw.githubusercontent.com/axetroy/go-cli-boilerplate/master/install.sh | bash -s v1.3.0 +# or install from gobinaries.com +curl -sf https://gobinaries.com/axetroy/go-cli-boilerplate@v1.3.0 | sh +``` + +Or + +Download the executable file for your platform at [release page](https://github.com/axetroy/go-cli-boilerplate/releases) + +Then set the environment variable. + +eg, the executable file is in the `~/bin` directory. + +```bash +# ~/.bash_profile +export PATH="$PATH:$HOME/bin" +``` + +then, try it out. + +```bash +go-cli-boilerplate --help +``` + +Finally, to use Deno correctly, you also need to set environment variables + +```bash +# ~/.bash_profile +export PATH="$PATH:$HOME/.deno/bin" +``` + +### Build from source code + +Make sure you have `Golang@v1.15.x` installed. + +```shell +$ git clone https://github.com/axetroy/go-cli-boilerplate.git $GOPATH/src/github.com/axetroy/go-cli-boilerplate +$ cd $GOPATH/src/github.com/axetroy/go-cli-boilerplate +$ make build +``` + +### Test + +```bash +$ make test +``` + +### License + +The [MIT License](LICENSE) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..837c8cc --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/axetroy/dvm + +go 1.15 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..8284512 --- /dev/null +++ b/install.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +set -e + +downloadFolder="${HOME}/Downloads" + +mkdir -p ${downloadFolder} + +get_arch() { + a=$(uname -m) + case ${a} in + "x86_64" | "amd64" ) + echo "amd64" + ;; + "i386" | "i486" | "i586") + echo "386" + ;; + *) + echo ${NIL} + ;; + esac +} + +get_os(){ + echo $(uname -s | awk '{print tolower($0)}') +} + +main() { + local os=$(get_os) + local arch=$(get_arch) + local dest_file="${downloadFolder}/dvm_${os}_${arch}.tar.gz" + + if [[ $# -eq 0 ]]; then + asset_path=$( + command curl -sSf https://github.com/axetroy/dvm/releases | + command grep -o "/axetroy/dvm/releases/download/.*/dvm_${os}_${arch}\\.tar.gz" | + command head -n 1 + ) + if [[ ! "$asset_path" ]]; then exit 1; fi + asset_uri="https://github.com${asset_path}" + else + asset_uri="https://github.com/axetroy/dvm/releases/download/${1}/dvm_${os}_${arch}\\.tar.gz" + fi + + mkdir -p ${downloadFolder} + + echo "[1/3] Download ${asset_uri} to ${downloadFolder}" + rm -f ${dest_file} + # wget -P "${downloadFolder}" "${asset_uri}" + curl --location --output "${dest_file}" "${asset_uri}" + + binDir=/usr/local/bin + + echo "[2/3] Install dvm to the ${binDir}" + mkdir -p ${HOME}/bin + tar -xz -f ${dest_file} -C ${binDir} + exe=${binDir}/dvm + chmod +x ${exe} + + echo "[3/3] Set environment variables" + echo "dvm was installed successfully to ${exe}" + if command -v dvm --version >/dev/null; then + echo "Run 'dvm --help' to get started" + else + echo "Manually add the directory to your \$HOME/.bash_profile (or similar)" + echo " export PATH=${HOME}/bin:\$PATH" + echo "Run '$exe --help' to get started" + fi + + exit 0 +} + +main \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..b23a881 --- /dev/null +++ b/main.go @@ -0,0 +1,14 @@ +package main + +import "fmt" + +var ( + version = "dev" + commit = "none" + date = "unknown" + builtBy = "unknown" +) + +func main() { + fmt.Printf("hello world: %s, commit %s, built at %s by %s", version, commit, date, builtBy) +} diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..fd1a921 --- /dev/null +++ b/run.sh @@ -0,0 +1,3 @@ +#! /bin/sh +# run main.go +go run -mod=vendor main.go "$@" diff --git a/workflows/build.yml b/workflows/build.yml new file mode 100644 index 0000000..bb452f3 --- /dev/null +++ b/workflows/build.yml @@ -0,0 +1,65 @@ +name: ci + +on: [push, pull_request] + +jobs: + ci: + runs-on: ${{ matrix.os }} + timeout-minutes: 30 + strategy: + matrix: + go: ["^1.15.0"] + os: [ubuntu-latest, macOS-latest, windows-latest] + name: Go ${{ matrix.go }} in ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Environment + run: | + go version + go env + + - name: Install tools + env: + GO111MODULE: on + run: | + go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.27.0 + golangci-lint --version + + - name: Lint + run: make lint + + - name: Format + run: make format-check + + - name: Test + run: | + make test + go mod tidy + git checkout ./ + + - name: Build + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist --skip-publish + + release: + name: Release to Github + if: startsWith(github.ref, 'refs/tags/') && github.repository == 'axetroy/go-cli-boilerplate' + needs: [ci] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}