Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Nov 19, 2020
0 parents commit 824d351
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 }}
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"go.addTags": {
"tags": "json",
"options": "json=omitempty",
"promptForTags": false,
"transform": "snakecase"
},
"go.buildFlags": ["-mode=vendor"],
"go.toolsEnvVars": {
"GOFLAGS": "-mod=vendor"
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 main.go
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[![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
### 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/[email protected] | 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 `[email protected]` 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)
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/axetroy/go-cli-boilerplate

go 1.15
Empty file added go.sum
Empty file.
72 changes: 72 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 3 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/sh
# run main.go
go run -mod=vendor main.go "$@"

0 comments on commit 824d351

Please sign in to comment.