-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting up the project with small boilerplate.
- Loading branch information
0 parents
commit 27fd3d6
Showing
12 changed files
with
402 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
release: | ||
name: release | ||
runs-on: [ubuntu-latest] | ||
|
||
steps: | ||
- name: checkout the code | ||
uses: actions/checkout@v4 | ||
|
||
- name: setup go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22.x' | ||
|
||
- name: unshallow | ||
run: git fetch --prune --unshallow | ||
|
||
- name: run goreleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
with: | ||
version: latest | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: test | ||
runs-on: [ubuntu-latest] | ||
|
||
steps: | ||
- name: checkout the code | ||
uses: actions/checkout@v4 | ||
|
||
- name: setup go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22.x' | ||
|
||
- name: unshallow | ||
run: git fetch --prune --unshallow | ||
|
||
- name: golanci-linter | ||
uses: golangci/golangci-lint-action@v4 | ||
with: | ||
version: v1.56.2 | ||
|
||
- name: configure | ||
run: make configure | ||
|
||
- name: build | ||
run: make build | ||
|
||
- name: run unit tests | ||
run: make test | ||
|
||
- name: run goreleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
with: | ||
version: latest | ||
args: check | ||
|
||
- name: upload code coverage | ||
uses: codecov/codecov-action@v4 | ||
if: contains(github.ref, 'main') | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
file: ./cover.text |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cover* | ||
vendor | ||
build | ||
dist/ |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
run: | ||
timeout: "120s" | ||
|
||
output: | ||
formats: "colored-line-number" | ||
|
||
linters: | ||
enable: | ||
- gocyclo | ||
- unconvert | ||
- goimports | ||
- unused | ||
- vetshadow | ||
- misspell | ||
- nakedret | ||
- errcheck | ||
- revive | ||
- ineffassign | ||
- goconst | ||
- vet | ||
- unparam | ||
- gofumpt | ||
- prealloc | ||
- gomnd | ||
- gocritic | ||
|
||
|
||
linters-settings: | ||
revive: | ||
rules: | ||
- name: package-comments | ||
disabled: true | ||
|
||
issues: | ||
exclude-use-default: false |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj | ||
|
||
version: 1 | ||
|
||
project_name: lb | ||
|
||
before: | ||
hooks: | ||
- go mod tidy | ||
- make clean | ||
|
||
builds: | ||
- id: lb | ||
main: './' | ||
binary: lb | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
goarch: | ||
- amd64 | ||
mod_timestamp: "{{ .CommitTimestamp }}" | ||
flags: | ||
- -trimpath | ||
ldflags: | ||
- "-s" | ||
- "-w" | ||
- "-X github.com/faabiosr/lb/cmd.releaseVersion={{ .Version }}" | ||
- "-X github.com/faabiosr/lb/cmd.releaseCommit={{ .ShortCommit }}" | ||
- "-X github.com/faabiosr/lb/cmd.releaseOS={{ .Os }}/{{ .Arch }}" | ||
|
||
archives: | ||
- id: lb | ||
format: tar.gz | ||
builds: | ||
- lb | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- .Version}}_ | ||
{{- .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
checksum: | ||
name_template: 'checksums.txt' | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 Fabio da Silva Ribeiro | ||
|
||
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. |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.DEFAULT_GOAL := help | ||
|
||
build: ## builds the app (only for testing purpose) | ||
@go build -v -o ./build/lb . | ||
.PHONY: build | ||
|
||
clean: ## clean up files generated by coverage or go mod | ||
@rm -fR ./vendor/ ./cover.* ./build/ ./dist/ | ||
.PHONY: clean | ||
|
||
configure: ## creates folders and download dependencies | ||
@mkdir -p ./build | ||
@go mod download | ||
.PHONY: configure | ||
|
||
cover: test ## run unit tests and generates the html coverage file | ||
@go tool cover -html=./cover.text -o ./cover.html | ||
@test -f ./cover.text && rm ./cover.text; | ||
.PHONY: cover | ||
|
||
help: ## display help screen | ||
@sed \ | ||
-e '/^[a-zA-Z0-9_\-]*:.*##/!d' \ | ||
-e 's/:.*##\s*/:/' \ | ||
-e 's/^\(.\+\):\(.*\)/$(shell tput setaf 6)\1$(shell tput sgr0):\2/' \ | ||
$(MAKEFILE_LIST) | column -c2 -t -s : | ||
@echo '' | ||
.PHONY: help | ||
|
||
lint: ## golangci linters | ||
@golangci-lint run ./... | ||
.PHONY: lint | ||
|
||
release: ## runs the goreleaser and creates the release for local testing. | ||
@goreleaser release --snapshot | ||
.PHONY: release | ||
|
||
test: ## run unit tests | ||
@go test -v -race -coverprofile=./cover.text -covermode=atomic $(shell go list ./...) | ||
.PHONY: test |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# LB - (Lambda) Layer Balancer | ||
Balance your AWS lambda layers cross regions. | ||
|
||
## Development | ||
|
||
### Requirements | ||
|
||
The entire environment is based in Golang, and you need install the tools below: | ||
- Install [Go](https://golang.org) | ||
- Install [GolangCI-Lint](https://github.com/golangci/golangci-lint#install) - Linter | ||
|
||
### Makefile | ||
|
||
Please run the make target below to see the provided targets. | ||
|
||
```sh | ||
$ make help | ||
``` | ||
|
||
## License | ||
|
||
This project is released under the MIT licence. See [LICENSE](https://github.com/faabiosr/lb/blob/master/LICENSE) for more details. |
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (c) Fabio da Silva Ribeiro <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// Execute runs root cmd. | ||
func Execute(ctx context.Context, args []string) { | ||
if err := newCmd().RunContext(ctx, args); err != nil { | ||
fmt.Fprintf(os.Stdout, "%v\n\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
const unknown = "unknown" | ||
|
||
// variables are expected to be set at build time. | ||
var ( | ||
releaseVersion = unknown | ||
releaseCommit = unknown | ||
releaseOS = unknown | ||
) | ||
|
||
// variables that defines custom app templates. | ||
var ( | ||
helpHeaderTemplate = `{{template "helpNameTemplate" .}} | ||
Usage: {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[options]{{end}}{{if .Commands}} command [command options]{{end}}{{end}}{{ if .Description}} | ||
{{wrap .Description 0}}{{end}}` | ||
|
||
rootCommandTemplate = `%s | ||
For listing options and commands, use '{{.HelpName}} --help or {{.HelpName}} -h'. | ||
` | ||
|
||
appHelpTemplate = `%s{{if .VisibleFlags}} | ||
Options: {{template "visibleFlagTemplate" .}}{{end}}{{if .VisibleCommands}} | ||
Commands:{{template "visibleCommandCategoryTemplate" .}}{{end}} | ||
For more information on a command, use '{{.HelpName}} [command] --help'. | ||
` | ||
|
||
// nolint:unused | ||
commandHelpTemplate = `{{.HelpName}}{{if .Description}} - {{template "descriptionTemplate" .}}{{end}} | ||
Usage: {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}}[arguments...]{{end}}[arguments...]{{end}}{{end}}{{if .VisibleFlags}} | ||
Options: {{template "visibleFlagTemplate" .}}{{end}}{{if .VisibleCommands}} | ||
Commands:{{template "visibleCommandCategoryTemplate" .}}{{end}} | ||
` | ||
) | ||
|
||
// newCmd creates cli application defining custom help templates and default values. | ||
func newCmd() *cli.App { | ||
app := &cli.App{} | ||
app.Name = "lb" | ||
app.Usage = "balance your AWS lambda layers cross regions" | ||
app.Description = "Layer Balancer or 'lb' is a tool for balancing the layer version of your Lambda\nacross AWS regions, so each region has the same Lambda layer version." | ||
app.Version = fmt.Sprintf("%s, build: %s, os: %s", releaseVersion, releaseCommit, releaseOS) | ||
app.CustomAppHelpTemplate = fmt.Sprintf(appHelpTemplate, helpHeaderTemplate) | ||
app.HideHelpCommand = true | ||
app.Suggest = true | ||
|
||
app.EnableBashCompletion = true | ||
app.BashComplete = func(ctx *cli.Context) { | ||
for _, cmd := range ctx.App.Commands { | ||
_, _ = fmt.Fprintln(ctx.App.Writer, cmd.Name) | ||
} | ||
} | ||
|
||
app.Action = func(cc *cli.Context) error { | ||
tpl := fmt.Sprintf(rootCommandTemplate, helpHeaderTemplate) | ||
cli.HelpPrinterCustom(cc.App.Writer, tpl, cc.App, nil) | ||
|
||
return nil | ||
} | ||
|
||
return app | ||
} | ||
|
||
// commands sets custom help templates and default values. | ||
// | ||
// nolint:unused | ||
func commands(cmds ...*cli.Command) []*cli.Command { | ||
for _, cmd := range cmds { | ||
cmd.Usage = cmd.Description | ||
cmd.HideHelpCommand = true | ||
cmd.CustomHelpTemplate = commandHelpTemplate | ||
} | ||
|
||
return cmds | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module github.com/faabiosr/lb | ||
|
||
go 1.22 | ||
|
||
require github.com/urfave/cli/v2 v2.27.1 | ||
|
||
require ( | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect | ||
) |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= | ||
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= |
Oops, something went wrong.