diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..657ac38 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,27 @@ +name: release +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Go + uses: actions/setup-go@v3.5.0 + with: + go-version: "^1.20" + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@@v4.2.0 + with: + version: latest + args: release --rm-dist + env: + # To upload homebrew formula to other repos, + # need to set the dedicated token having enough permissions + # https://github.com/goreleaser/goreleaser/issues/982 + GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..6e07878 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,37 @@ +project_name: ecsource +before: + hooks: + - go mod tidy +builds: + - main: . + binary: ecsource + ldflags: + - -s -w + - -X github.com/tatsuo48/ecsource/main.Version={{.Version}} + - -X github.com/tatsuo48/ecsource/main.Revision={{.ShortCommit}} + env: + - CGO_ENABLED=0 +archives: + - name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" + replacements: + darwin: darwin + linux: linux + windows: windows + 386: i386 + amd64: x86_64 + format_overrides: + - goos: windows + format: zip +release: + prerelease: auto + +brews: + - tap: + owner: tatsuo48 + name: homebrew-tap + folder: Formula + homepage: https://github.com/tatsuo48/ecsource + description: ECS Task Definition tool to display resources such as CPU, memory, and memory reservations in an easy-to-read format. + skip_upload: auto + test: | + system "#{bin}/ecsource", "-v" diff --git a/Makefile b/Makefile index aba3c0a..a3d22dc 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build +.PHONY: build install clean build: @echo "Building..." diff --git a/main.go b/main.go index 42abebc..ea497ad 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,12 @@ import ( "github.com/olekukonko/tablewriter" ) +// These variables are set in build step +var ( + Version = "unset" + Revision = "unset" +) + // Generated by https://quicktype.io type TaskDefinitionJson struct { @@ -92,7 +98,16 @@ type Secret struct { func main() { if len(os.Args) < 2 { - log.Fatal("ファイル名を指定してくだい") + log.Fatal("please specify file path") + } + if os.Args[1] == "-h" || os.Args[1] == "--help" { + fmt.Printf("Usage: %s [file path]", os.Args[0]) + os.Exit(0) + } + if os.Args[1] == "--version" || os.Args[1] == "-v" { + fmt.Printf("version: %s\n", Version) + fmt.Printf("revision: %s\n", Revision) + os.Exit(0) } src, err := os.ReadFile(os.Args[1]) if err != nil {