Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
midzer committed Nov 19, 2022
0 parents commit df308e1
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "gomod"
directory: "/" # Location of package manifests
schedule:
interval: "daily"
56 changes: 56 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: ci
on:
push:
branches:
- master
paths-ignore:
- 'README.md'
pull_request:
paths-ignore:
- 'README.md'
jobs:
lint:
strategy:
matrix:
go-version: [1.19.x]
os: [windows-latest, macos-latest, ubuntu-latest]
name: golangci-lint
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
- name: go vet
run: go vet ./...
- name: go build
run: go build
test:
strategy:
matrix:
go-version: [1.19.x]
os: [windows-latest, macos-latest, ubuntu-latest]
name: test
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/[email protected]
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: go test
run: go test -v ./... -coverprofile=coverage.out
- uses: k1LoW/octocov-action@v0
if: runner.os == 'Linux'
74 changes: 74 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches:
- master
paths-ignore:
- 'README.md'
pull_request:
paths-ignore:
- 'README.md'
schedule:
- cron: '44 21 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
27 changes: 27 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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) 2022 midzer

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.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
![GitHub Repo stars](https://img.shields.io/github/stars/midzer/go-cli-template?style=social)
![GitHub](https://img.shields.io/github/license/midzer/go-cli-template)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/midzer/go-cli-template)
![GitHub all releases](https://img.shields.io/github/downloads/midzer/go-cli-template/total)
![GitHub CI Status](https://img.shields.io/github/workflow/status/midzer/go-cli-template/ci?label=CI)
![GitHub Release Status](https://img.shields.io/github/workflow/status/midzer/go-cli-template/Release?label=release)

# go-cli-template

Minimal Go CLI boilerplate/template with zero dependencies

## Features

- minimal CLI implementation
- CI/CD
- golangci-lint
- go test
- goreleaser
- Dependabot
- CodeQL Analysis (Go)

## How to use

1. fork/template this repository
2. replace `midzer` to your username
3. start hacking
31 changes: 31 additions & 0 deletions app/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package app

import (
"fmt"
"os"
)

func CLI(args []string) int {
var app appEnv
err := app.fromArgs(args)
if err != nil {
return 2
}
if err = app.run(); err != nil {
fmt.Fprintf(os.Stderr, "Runtime error: %v\n", err)
return 1
}

return 0
}

type appEnv struct {
}

func (app *appEnv) fromArgs(args []string) error {
return nil
}

func (app *appEnv) run() error {
return nil
}
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/midzer/go-cli-template

go 1.19
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"os"

"github.com/midzer/go-cli-template/app"
)
func main() {
os.Exit(app.CLI(os.Args[1:]))
}

0 comments on commit df308e1

Please sign in to comment.