From 76368fdb2cd0c5aeb8344a1536b0013e57d753f6 Mon Sep 17 00:00:00 2001 From: Imam Omar Mochtar Date: Mon, 13 May 2024 10:42:54 +0700 Subject: [PATCH 1/4] feat(build): adding build output for mac m1 --- .github/workflows/release.yml | 4 +--- .goreleaser.yml | 26 +++++++++++--------------- CHANGELOG.md | 11 +++++++++++ Makefile | 8 ++++++-- app/cmd.go | 2 +- app/version.go | 4 +++- go.mod | 2 +- 7 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 CHANGELOG.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4bf690a..80054fe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,7 +5,7 @@ on: - v* env: - GO_VERSION: 1.17 + GO_VERSION: 1.22 jobs: release: @@ -16,8 +16,6 @@ jobs: - uses: actions/setup-go@v2 with: go-version: ${{ env.GO_VERSION }} - - name: install upx - run: sudo apt install upx-ucl -y - name: GoReleaser uses: goreleaser/goreleaser-action@v1 with: diff --git a/.goreleaser.yml b/.goreleaser.yml index eb08b69..c03bf2f 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -11,25 +11,21 @@ builds: goos: - darwin - linux - - windows goarch: - amd64 - hooks: - post: - - upx --brute "{{ .Path }}" + - arm64 + ignore: + - goos: linux + goarch: arm64 + ldflags: + - -s -w -X github.com/iomarmochtar/content-plus-totp/app.Version={{.Version}} checksum: name_template: 'checksums.txt' archives: - - name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}_{{ .Version }}' - format: tar.gz - replacements: - darwin: Darwin - linux: Linux - windows: Windows - 386: i386 - amd64: x86_64 - format_overrides: - - goos: windows - format: zip \ No newline at end of file + - files: + # Only include built binary in archive + - 'none*' + format: zip + name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a1173fa --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# 0.2.0 + +## Features and enhancements + +- add build target for Mac M1 processor. +- dynamic version injection in compilation process. +- bump go version to 1.22 . + +## Bug Fixes + +- remove the usage of upx due problematic in resulting macos binary ([ref](https://github.com/upx/upx/issues/424)). \ No newline at end of file diff --git a/Makefile b/Makefile index c54df74..e1d5e00 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,10 @@ lint: .PHONY: test-all test-all: test lint -.PHONY: compile -compile: +.PHONY: compile-linux +compile-linux: GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -o dist/${NAME} main.go + +# default compile target to linux +.PHONY: compile +compile: compile-linux diff --git a/app/cmd.go b/app/cmd.go index 835aa2b..4489ea1 100644 --- a/app/cmd.go +++ b/app/cmd.go @@ -19,7 +19,7 @@ func NewCmd() cli.App { return cli.App{ Name: "content-plus-totp", Usage: "an easy way to combine static content such as password with totp token", - Version: VERSION, + Version: Version, Compiled: time.Now(), EnableBashCompletion: true, Flags: []cli.Flag{ diff --git a/app/version.go b/app/version.go index 18a2159..614b747 100644 --- a/app/version.go +++ b/app/version.go @@ -1,3 +1,5 @@ package app -const VERSION = "0.1.0" +var ( + Version = "dev" +) diff --git a/go.mod b/go.mod index 28d3108..2634ed4 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/iomarmochtar/content-plus-totp -go 1.17 +go 1.22 require ( github.com/atotto/clipboard v0.1.4 From 4ddc626c1bb7920bb53993c1f308ef8afbacad56 Mon Sep 17 00:00:00 2001 From: Imam Omar Mochtar Date: Mon, 13 May 2024 12:06:29 +0700 Subject: [PATCH 2/4] fix(lint): remove unnecessary lint and lock linter version --- .github/workflows/tests.yml | 5 +++-- .golangci.yml | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fa1d64d..9a3d020 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,7 +2,8 @@ name: tests on: [pull_request, workflow_dispatch] env: - GO_VERSION: 1.17 + GO_VERSION: 1.22 + GOLANGCI_VERSION: 1.58 CGO_ENABLED: 0 jobs: @@ -16,7 +17,7 @@ jobs: go-version: ${{ env.GO_VERSION }} - uses: golangci/golangci-lint-action@v2 with: - version: latest + version: ${{ env.GOLANGCI_VERSION }} unit-test: name: unit-test diff --git a/.golangci.yml b/.golangci.yml index b4ece9c..22030ba 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,9 +27,7 @@ linters: - goimports - whitespace - misspell - - depguard - importas - contextcheck - nolintlint - revive - From 65513c9366d1d5286f969cfcf766506f056063c1 Mon Sep 17 00:00:00 2001 From: Imam Omar Mochtar Date: Mon, 13 May 2024 12:08:39 +0700 Subject: [PATCH 3/4] fix(pipeline): fixing version --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9a3d020..1fc9013 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,7 +17,7 @@ jobs: go-version: ${{ env.GO_VERSION }} - uses: golangci/golangci-lint-action@v2 with: - version: ${{ env.GOLANGCI_VERSION }} + version: v${{ env.GOLANGCI_VERSION }} unit-test: name: unit-test From 39daa95e028922aa4c9ead41d58c8221e0e0e21b Mon Sep 17 00:00:00 2001 From: Imam Omar Mochtar Date: Mon, 13 May 2024 12:21:38 +0700 Subject: [PATCH 4/4] fix(deprecations): remove usage of deprecated std lib --- .golangci.yml | 2 +- config/config.go | 3 +-- config/config_test.go | 5 ++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 22030ba..27abb39 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -13,7 +13,6 @@ linters-settings: linters: enable: - - megacheck - govet - revive - gocyclo @@ -31,3 +30,4 @@ linters: - contextcheck - nolintlint - revive + - staticcheck diff --git a/config/config.go b/config/config.go index 17d96eb..bd0cc17 100644 --- a/config/config.go +++ b/config/config.go @@ -3,7 +3,6 @@ package config import ( "encoding/json" "fmt" - "io/ioutil" "os" ) @@ -20,7 +19,7 @@ func NewByPath(path string) (*Config, error) { return nil, fmt.Errorf("%s is a directory", path) } - jsonContent, err := ioutil.ReadFile(path) + jsonContent, err := os.ReadFile(path) if err != nil { return nil, err } diff --git a/config/config_test.go b/config/config_test.go index 93d63be..d38e856 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -2,7 +2,6 @@ package config_test import ( "fmt" - "io/ioutil" "os" "testing" @@ -45,7 +44,7 @@ func TestReadConfig(t *testing.T) { func TestReadConfigByPath(t *testing.T) { getTmpFile := func() string { - tempFile, err := ioutil.TempFile(os.TempDir(), "test_read_path") + tempFile, err := os.CreateTemp(os.TempDir(), "test_read_path") if err != nil { panic(err) } @@ -61,7 +60,7 @@ func TestReadConfigByPath(t *testing.T) { preExec: func() string { tmpFile := getTmpFile() jsonContent := `{"content_enc": "aGVsbG8K", "totp_master_enc": "d29ybGQK"}` - if err := ioutil.WriteFile(tmpFile, []byte(jsonContent), 0600); err != nil { + if err := os.WriteFile(tmpFile, []byte(jsonContent), 0600); err != nil { panic(err) }