-
Notifications
You must be signed in to change notification settings - Fork 2
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
15 changed files
with
403 additions
and
14 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 @@ | ||
*.go text eol=lf |
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,58 @@ | ||
name: deployment | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
tags: | ||
- "v*" | ||
pull_request: | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.20 | ||
|
||
- name: Cache Go modules | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Generate changelog | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
run: | | ||
echo "GORELEASER_CURRENT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | ||
git fetch --unshallow | ||
scripts/changelog | tee CHANGELOG.md | ||
- name: Release | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
version: latest | ||
install-only: true | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
if [[ $GITHUB_REF == refs/tags/v* ]]; then | ||
goreleaser release --release-notes=CHANGELOG.md | ||
elif [[ $GITHUB_REF == refs/heads/trunk ]]; then | ||
goreleaser --snapshot | ||
fi | ||
- name: Bump Homebrew formula | ||
uses: mislav/bump-homebrew-formula-action@v1 | ||
if: "!contains(github.ref, '-') && startsWith(github.ref, 'refs/tags/v')" # skip prereleases and run on tags | ||
with: | ||
formula-name: glab | ||
env: | ||
COMMITTER_TOKEN: ${{ secrets.GITHUB_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,39 @@ | ||
name: Tests | ||
on: [push, pull_request] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.20 | ||
|
||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Restore Go modules cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: go-${{ runner.os }}-${{ hashFiles('go.mod') }} | ||
restore-keys: | | ||
go-${{ runner.os }}- | ||
- name: Download dependencies | ||
run: go mod download | ||
|
||
- name: Run tests | ||
run: go test -race ./... | ||
|
||
- name: Build | ||
run: go build -v ./cmd/g |
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,47 @@ | ||
name: Lint | ||
on: | ||
push: | ||
paths: | ||
- "**.go" | ||
- go.mod | ||
- go.sum | ||
pull_request: | ||
paths: | ||
- "**.go" | ||
- go.mod | ||
- go.sum | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.20 | ||
|
||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Restore Go modules cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: go-${{ runner.os }}-${{ hashFiles('go.mod') }} | ||
restore-keys: | | ||
go-${{ runner.os }}- | ||
- name: Verify dependencies | ||
run: | | ||
go mod verify | ||
go mod download | ||
- name: Run checks | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: v1.53 | ||
args: --timeout=3m --issues-exit-code=1 |
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
*.so | ||
*.dylib | ||
/bin | ||
/dist | ||
/share | ||
|
||
# Test binary, built with `go test -c` | ||
*.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,8 @@ | ||
linters: | ||
enable: | ||
- gofmt | ||
- nolintlint | ||
|
||
issues: | ||
max-issues-per-linter: 0 | ||
max-same-issues: 0 |
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,86 @@ | ||
project_name: compozify | ||
|
||
release: | ||
prerelease: auto | ||
draft: true | ||
name_template: "Compozify {{.Version}}" | ||
|
||
before: | ||
hooks: | ||
- >- | ||
{{ if ne .Runtime.Goos "linux" }}echo{{ end }} make completions | ||
- >- | ||
{{ if ne .Runtime.Goos "linux" }}echo{{ end }} COMPOZIFY_VERSION={{.Version}} make manpages | ||
builds: | ||
- id: macos #build:macos | ||
goos: [darwin] | ||
goarch: [amd64, arm64] | ||
binary: bin/compozify | ||
main: ./cmd/compozify | ||
ldflags: | ||
- -s -w -X github.com/profclems/compozify/internal/version.Version={{.Version}} -X github.com/profclems/compozify/internal/version.BuildDate={{time "2006-01-02"}} | ||
|
||
- id: linux #build:linux | ||
goos: [linux] | ||
goarch: [386, arm, amd64, arm64] | ||
env: | ||
- CGO_ENABLED=0 | ||
binary: bin/compozify | ||
main: ./cmd/compozify | ||
ldflags: | ||
- -s -w -X github.com/profclems/compozify/internal/version.Version={{.Version}} -X github.com/profclems/compozify/internal/version.BuildDate={{time "2006-01-02"}} | ||
|
||
- id: windows #build:windows | ||
goos: [windows] | ||
goarch: [386, amd64, arm64] | ||
binary: bin/compozify | ||
main: ./cmd/compozify | ||
ldflags: | ||
- -s -w -X github.com/profclems/compozify/internal/version.Version={{.Version}} -X github.com/profclems/compozify/internal/version.BuildDate={{time "2006-01-02"}} | ||
|
||
archives: | ||
- id: linux-archive | ||
builds: [linux] | ||
name_template: "compozify_{{ .Version }}_linux_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" | ||
wrap_in_directory: true | ||
format: tar.gz | ||
files: | ||
- LICENSE | ||
- ./share/man/man1/compozify*.1 | ||
- id: macos-archive | ||
builds: [macos] | ||
name_template: "compozify_{{ .Version }}_macOS_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" | ||
wrap_in_directory: true | ||
format: zip | ||
files: | ||
- LICENSE | ||
- ./share/man/man1/compozify*.1 | ||
- id: windows-archive | ||
builds: [windows] | ||
name_template: "compozify_{{ .Version }}_windows_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" | ||
wrap_in_directory: false | ||
format: zip | ||
files: | ||
- LICENSE | ||
|
||
nfpms: #build:linux | ||
- license: MIT | ||
maintainer: Clement Sam | ||
homepage: https://github.com/profclems/compozify | ||
bindir: /usr | ||
dependencies: | ||
- git | ||
description: Compozify is a tool mainly for converting docker run commands to docker-compose files | ||
formats: | ||
- deb | ||
- rpm | ||
contents: | ||
- src: "./share/man/man1/compozify*.1" | ||
dst: "/usr/share/man/man1" | ||
- src: "./share/bash-completion/completions/compozify" | ||
dst: "/usr/share/bash-completion/completions/compozify" | ||
- src: "./share/fish/vendor_completions.d/compozify.fish" | ||
dst: "/usr/share/fish/vendor_completions.d/compozify.fish" | ||
- src: "./share/zsh/site-functions/_compozify" | ||
dst: "/usr/share/zsh/site-functions/_compozify" |
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,14 +1,53 @@ | ||
export CGO_ENABLED ?= 0 | ||
|
||
CGO_CPPFLAGS ?= ${CPPFLAGS} | ||
export CGO_CPPFLAGS | ||
CGO_CFLAGS ?= ${CFLAGS} | ||
export CGO_CFLAGS | ||
CGO_LDFLAGS ?= $(filter -g -L% -l% -O%,${LDFLAGS}) | ||
export CGO_LDFLAGS | ||
|
||
DATE_FMT = +%Y-%m-%d | ||
ifdef SOURCE_DATE_EPOCH | ||
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)") | ||
else | ||
BUILD_DATE ?= $(shell date "$(DATE_FMT)") | ||
endif | ||
|
||
GO_LDFLAGS := -X github.com/profclems/compozify/internal/version.BuildDate=$(BUILD_DATE) $(GO_LDFLAGS) | ||
ifdef COMPOZIFY_VERSION | ||
GO_LDFLAGS := $(GO_LDFLAGS) -X github.com/profclems/compozify/internal/version.Version=$(COMPOZIFY_VERSION) | ||
endif | ||
|
||
EXE = | ||
ifeq ($(shell go env GOOS),windows) | ||
EXE = .exe | ||
endif | ||
|
||
install: | ||
go install -v ./cmd/... | ||
go install -v -trimpath -ldflags "$(GO_LDFLAGS)" ./cmd/compozify | ||
|
||
.PHONY: build | ||
build: | ||
go build -o ./bin/ ./cmd/... | ||
go build -trimpath -ldflags "$(GO_LDFLAGS)" -o ./bin/compozify ./cmd/compozify | ||
|
||
.PHONY: test | ||
test: | ||
go test -race ./... | ||
|
||
.PHONY: fix | ||
fix: ## Fix lint violations | ||
golangci-lint run --fix | ||
gofmt -s -w . | ||
goimports -local "github.com/profclems/compozify" -w $$(find . -type f -name '*.go' -not -path "*/vendor/*") | ||
|
||
.PHONY: fix | ||
.PHONY: completions | ||
completions: build | ||
mkdir -p ./share/bash-completion/completions ./share/fish/vendor_completions.d ./share/zsh/site-functions | ||
bin/compozify$(EXE) completion bash > ./share/bash-completion/completions/compozify | ||
bin/compozify$(EXE) completion fish > ./share/fish/vendor_completions.d/compozify.fish | ||
bin/compozify$(EXE) completion zsh > ./share/zsh/site-functions/_compozify | ||
|
||
.PHONY: manpage | ||
manpage: ## Generate manual pages | ||
go run -trimpath -ldflags "$(GO_LDFLAGS)" ./cmd/gen-docs/main.go --manpage --path ./share/man/man1 |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/profclems/compozify/internal/version" | ||
"github.com/rs/zerolog" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/cobra/doc" | ||
"os" | ||
|
||
"github.com/profclems/compozify/internal/commands" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
func main() { | ||
var flagErr pflag.ErrorHandling | ||
docsCmd := pflag.NewFlagSet("", flagErr) | ||
manpage := docsCmd.BoolP("manpage", "m", false, "Generate manual pages instead of web docs") | ||
path := docsCmd.StringP("path", "p", "./docs/source/", "Path where you want the generated docs saved") | ||
help := docsCmd.BoolP("help", "h", false, "Help about any command") | ||
|
||
if err := docsCmd.Parse(os.Args); err != nil { | ||
fatal(err) | ||
} | ||
if *help { | ||
_, err := fmt.Fprintf(os.Stderr, "Usage of %s:\n\n%s", os.Args[0], docsCmd.FlagUsages()) | ||
if err != nil { | ||
fatal(err) | ||
} | ||
os.Exit(1) | ||
} | ||
err := os.MkdirAll(*path, 0o755) | ||
if err != nil { | ||
fatal(err) | ||
} | ||
|
||
logger := zerolog.Nop() | ||
cmd := commands.NewRootCmd(&logger, version.GetVersion()) | ||
cmd.DisableAutoGenTag = true | ||
if *manpage { | ||
if err := genManPage(cmd, *path); err != nil { | ||
fatal(err) | ||
} | ||
} else { | ||
err := doc.GenMarkdownTree(cmd, *path) | ||
if err != nil { | ||
fatal(err) | ||
} | ||
} | ||
} | ||
|
||
func genManPage(cmd *cobra.Command, path string) error { | ||
header := &doc.GenManHeader{ | ||
Title: "compozify", | ||
Section: "1", | ||
Source: "", | ||
Manual: "", | ||
} | ||
err := doc.GenManTree(cmd, header, path) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func fatal(err error) { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} |
Oops, something went wrong.