diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c1a3c83..de84ca1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,25 +2,25 @@ name: build on: [push] jobs: - build: - name: build - runs-on: ubuntu-latest - steps: - - name: git clone - uses: actions/checkout@v4 + build: + name: build + runs-on: ubuntu-latest + steps: + - name: git clone + uses: actions/checkout@v4 - - name: set up go - uses: actions/setup-go@v5 - with: - go-version: 1.23.4 + - name: set up go + uses: actions/setup-go@v5 + with: + go-version: 1.24.0 - - name: go build - run: go build -v + - name: go build + run: go build -v - - name: go test - run: go test -v -cover -coverpkg=./... -race ./... + - name: go test + run: go test -v -cover -coverpkg=./... -race ./... - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.63.4 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.63.4 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d75212e..7e9f97b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,35 +1,33 @@ name: publish on: - release: - types: [created] + push: + tags: + - "*" + +permissions: + contents: write jobs: - deploy: - runs-on: ubuntu-latest - steps: - - name: git clone - uses: actions/checkout@v4 + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 - - name: set up go - uses: actions/setup-go@v5 - with: - go-version: 1.23.4 + - name: Unshallow repo + run: git fetch --prune --unshallow - - name: compile - run: | - echo "go version:" - go version - echo "go env:" - go env - bash material/scripts/buildall.sh + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: 1.24.x - - name: Upload binaries to release - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - file: build/gotz* - file_glob: true - tag: ${{ github.ref }} - overwrite: true - body: "gotz binaries" + - name: Run goreleaser + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BREW_TOKEN: ${{ secrets.BREW_BUMP_TOKEN }} diff --git a/.gitignore b/.gitignore index a3885d5..683dea9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ gotz gotz.exe build/ +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..10e70c1 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,31 @@ +builds: + - env: + - CGO_ENABLED=0 + goos: + - freebsd + - windows + - darwin + - linux + goarch: + - amd64 + - arm + - arm64 + - "386" + ldflags: + - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} +checksum: + name_template: "checksums.txt" +changelog: + use: github-native + sort: asc +brews: + - name: gotz + homepage: "https://github.com/merschformann/gotz" + description: "A simple CLI timezone conversion assistant, written in Go" + repository: + owner: merschformann + name: gotz-brew + token: "{{ .Env.BREW_TOKEN }}" + commit_author: + name: merschbotmann + email: bot.merschformann@gmail.com diff --git a/.prettierrc.yml b/.prettierrc.yml new file mode 100644 index 0000000..0f4487e --- /dev/null +++ b/.prettierrc.yml @@ -0,0 +1 @@ +tabWidth: 2 diff --git a/main.go b/main.go index 43562f3..181a355 100644 --- a/main.go +++ b/main.go @@ -31,7 +31,7 @@ func main() { } } // Parse flags - config, rt, changed, err := core.ParseFlags(config, Version) + config, rt, changed, err := core.ParseFlags(config, GetReleaseInfo().Version) if err != nil { fmt.Println("error parsing flags:", err) os.Exit(1) diff --git a/tests/testdata/static_default.json b/tests/testdata/static_default.json index bc3ed2a..f3d92f5 100644 --- a/tests/testdata/static_default.json +++ b/tests/testdata/static_default.json @@ -1,48 +1,48 @@ { - "config_version": "1.0", - "timezones": [ - { - "Name": "New York", - "TZ": "America/New_York" - }, - { - "Name": "Berlin", - "TZ": "Europe/Berlin" - }, - { - "Name": "Shanghai", - "TZ": "Asia/Shanghai" - }, - { - "Name": "Sydney", - "TZ": "Australia/Sydney" - } - ], - "style": { - "symbols": "rectangles", - "colorize": false, - "day_segments": { - "morning": 6, - "day": 8, - "evening": 18, - "night": 22 - }, - "coloring": { - "StaticColorMorning": "red", - "StaticColorDay": "yellow", - "StaticColorEvening": "red", - "StaticColorNight": "blue", - "StaticColorForeground": "", - "DynamicColorMorning": "red", - "DynamicColorDay": "yellow", - "DynamicColorEvening": "red", - "DynamicColorNight": "blue", - "DynamicColorForeground": "", - "DynamicColorBackground": "" - } + "config_version": "1.0", + "timezones": [ + { + "Name": "New York", + "TZ": "America/New_York" }, - "tics": false, - "stretch": true, - "hours12": false, - "live": false + { + "Name": "Berlin", + "TZ": "Europe/Berlin" + }, + { + "Name": "Shanghai", + "TZ": "Asia/Shanghai" + }, + { + "Name": "Sydney", + "TZ": "Australia/Sydney" + } + ], + "style": { + "symbols": "rectangles", + "colorize": false, + "day_segments": { + "morning": 6, + "day": 8, + "evening": 18, + "night": 22 + }, + "coloring": { + "StaticColorMorning": "red", + "StaticColorDay": "yellow", + "StaticColorEvening": "red", + "StaticColorNight": "blue", + "StaticColorForeground": "", + "DynamicColorMorning": "red", + "DynamicColorDay": "yellow", + "DynamicColorEvening": "red", + "DynamicColorNight": "blue", + "DynamicColorForeground": "", + "DynamicColorBackground": "" + } + }, + "tics": false, + "stretch": true, + "hours12": false, + "live": false } diff --git a/tests/testdata/static_hours12.json b/tests/testdata/static_hours12.json index 65ddf43..bd4a48d 100644 --- a/tests/testdata/static_hours12.json +++ b/tests/testdata/static_hours12.json @@ -1,48 +1,48 @@ { - "config_version": "1.0", - "timezones": [ - { - "Name": "New York", - "TZ": "America/New_York" - }, - { - "Name": "Berlin", - "TZ": "Europe/Berlin" - }, - { - "Name": "Shanghai", - "TZ": "Asia/Shanghai" - }, - { - "Name": "Sydney", - "TZ": "Australia/Sydney" - } - ], - "style": { - "symbols": "rectangles", - "colorize": false, - "day_segments": { - "morning": 6, - "day": 8, - "evening": 18, - "night": 22 - }, - "coloring": { - "StaticColorMorning": "red", - "StaticColorDay": "yellow", - "StaticColorEvening": "red", - "StaticColorNight": "blue", - "StaticColorForeground": "", - "DynamicColorMorning": "red", - "DynamicColorDay": "yellow", - "DynamicColorEvening": "red", - "DynamicColorNight": "blue", - "DynamicColorForeground": "", - "DynamicColorBackground": "" - } + "config_version": "1.0", + "timezones": [ + { + "Name": "New York", + "TZ": "America/New_York" }, - "tics": false, - "stretch": true, - "hours12": true, - "live": false + { + "Name": "Berlin", + "TZ": "Europe/Berlin" + }, + { + "Name": "Shanghai", + "TZ": "Asia/Shanghai" + }, + { + "Name": "Sydney", + "TZ": "Australia/Sydney" + } + ], + "style": { + "symbols": "rectangles", + "colorize": false, + "day_segments": { + "morning": 6, + "day": 8, + "evening": 18, + "night": 22 + }, + "coloring": { + "StaticColorMorning": "red", + "StaticColorDay": "yellow", + "StaticColorEvening": "red", + "StaticColorNight": "blue", + "StaticColorForeground": "", + "DynamicColorMorning": "red", + "DynamicColorDay": "yellow", + "DynamicColorEvening": "red", + "DynamicColorNight": "blue", + "DynamicColorForeground": "", + "DynamicColorBackground": "" + } + }, + "tics": false, + "stretch": true, + "hours12": true, + "live": false } diff --git a/tests/testdata/static_inline.json b/tests/testdata/static_inline.json index 7ddabab..18d14aa 100644 --- a/tests/testdata/static_inline.json +++ b/tests/testdata/static_inline.json @@ -1,49 +1,49 @@ { - "config_version": "1.0", - "timezones": [ - { - "Name": "New York", - "TZ": "America/New_York" - }, - { - "Name": "Berlin", - "TZ": "Europe/Berlin" - }, - { - "Name": "Shanghai", - "TZ": "Asia/Shanghai" - }, - { - "Name": "Sydney", - "TZ": "Australia/Sydney" - } - ], - "style": { - "symbols": "rectangles", - "colorize": false, - "day_segments": { - "morning": 6, - "day": 8, - "evening": 18, - "night": 22 - }, - "coloring": { - "StaticColorMorning": "red", - "StaticColorDay": "yellow", - "StaticColorEvening": "red", - "StaticColorNight": "blue", - "StaticColorForeground": "", - "DynamicColorMorning": "red", - "DynamicColorDay": "yellow", - "DynamicColorEvening": "red", - "DynamicColorNight": "blue", - "DynamicColorForeground": "", - "DynamicColorBackground": "" - } + "config_version": "1.0", + "timezones": [ + { + "Name": "New York", + "TZ": "America/New_York" }, - "tics": false, - "stretch": true, - "inline": true, - "hours12": false, - "live": false + { + "Name": "Berlin", + "TZ": "Europe/Berlin" + }, + { + "Name": "Shanghai", + "TZ": "Asia/Shanghai" + }, + { + "Name": "Sydney", + "TZ": "Australia/Sydney" + } + ], + "style": { + "symbols": "rectangles", + "colorize": false, + "day_segments": { + "morning": 6, + "day": 8, + "evening": 18, + "night": 22 + }, + "coloring": { + "StaticColorMorning": "red", + "StaticColorDay": "yellow", + "StaticColorEvening": "red", + "StaticColorNight": "blue", + "StaticColorForeground": "", + "DynamicColorMorning": "red", + "DynamicColorDay": "yellow", + "DynamicColorEvening": "red", + "DynamicColorNight": "blue", + "DynamicColorForeground": "", + "DynamicColorBackground": "" + } + }, + "tics": false, + "stretch": true, + "inline": true, + "hours12": false, + "live": false } diff --git a/tests/testdata/static_mono.json b/tests/testdata/static_mono.json index 89dd8b8..abce012 100644 --- a/tests/testdata/static_mono.json +++ b/tests/testdata/static_mono.json @@ -1,48 +1,48 @@ { - "config_version": "1.0", - "timezones": [ - { - "Name": "New York", - "TZ": "America/New_York" - }, - { - "Name": "Berlin", - "TZ": "Europe/Berlin" - }, - { - "Name": "Shanghai", - "TZ": "Asia/Shanghai" - }, - { - "Name": "Sydney", - "TZ": "Australia/Sydney" - } - ], - "style": { - "symbols": "mono", - "colorize": false, - "day_segments": { - "morning": 6, - "day": 8, - "evening": 18, - "night": 22 - }, - "coloring": { - "StaticColorMorning": "red", - "StaticColorDay": "yellow", - "StaticColorEvening": "red", - "StaticColorNight": "blue", - "StaticColorForeground": "", - "DynamicColorMorning": "red", - "DynamicColorDay": "yellow", - "DynamicColorEvening": "red", - "DynamicColorNight": "blue", - "DynamicColorForeground": "", - "DynamicColorBackground": "" - } + "config_version": "1.0", + "timezones": [ + { + "Name": "New York", + "TZ": "America/New_York" }, - "tics": false, - "stretch": true, - "hours12": false, - "live": false + { + "Name": "Berlin", + "TZ": "Europe/Berlin" + }, + { + "Name": "Shanghai", + "TZ": "Asia/Shanghai" + }, + { + "Name": "Sydney", + "TZ": "Australia/Sydney" + } + ], + "style": { + "symbols": "mono", + "colorize": false, + "day_segments": { + "morning": 6, + "day": 8, + "evening": 18, + "night": 22 + }, + "coloring": { + "StaticColorMorning": "red", + "StaticColorDay": "yellow", + "StaticColorEvening": "red", + "StaticColorNight": "blue", + "StaticColorForeground": "", + "DynamicColorMorning": "red", + "DynamicColorDay": "yellow", + "DynamicColorEvening": "red", + "DynamicColorNight": "blue", + "DynamicColorForeground": "", + "DynamicColorBackground": "" + } + }, + "tics": false, + "stretch": true, + "hours12": false, + "live": false } diff --git a/tests/testdata/static_sun-moon.json b/tests/testdata/static_sun-moon.json index a9bd76a..7dc47a7 100644 --- a/tests/testdata/static_sun-moon.json +++ b/tests/testdata/static_sun-moon.json @@ -1,48 +1,48 @@ { - "config_version": "1.0", - "timezones": [ - { - "Name": "New York", - "TZ": "America/New_York" - }, - { - "Name": "Berlin", - "TZ": "Europe/Berlin" - }, - { - "Name": "Shanghai", - "TZ": "Asia/Shanghai" - }, - { - "Name": "Sydney", - "TZ": "Australia/Sydney" - } - ], - "style": { - "symbols": "sun-moon", - "colorize": false, - "day_segments": { - "morning": 6, - "day": 8, - "evening": 18, - "night": 22 - }, - "coloring": { - "StaticColorMorning": "red", - "StaticColorDay": "yellow", - "StaticColorEvening": "red", - "StaticColorNight": "blue", - "StaticColorForeground": "", - "DynamicColorMorning": "red", - "DynamicColorDay": "yellow", - "DynamicColorEvening": "red", - "DynamicColorNight": "blue", - "DynamicColorForeground": "", - "DynamicColorBackground": "" - } + "config_version": "1.0", + "timezones": [ + { + "Name": "New York", + "TZ": "America/New_York" }, - "tics": false, - "stretch": true, - "hours12": false, - "live": false + { + "Name": "Berlin", + "TZ": "Europe/Berlin" + }, + { + "Name": "Shanghai", + "TZ": "Asia/Shanghai" + }, + { + "Name": "Sydney", + "TZ": "Australia/Sydney" + } + ], + "style": { + "symbols": "sun-moon", + "colorize": false, + "day_segments": { + "morning": 6, + "day": 8, + "evening": 18, + "night": 22 + }, + "coloring": { + "StaticColorMorning": "red", + "StaticColorDay": "yellow", + "StaticColorEvening": "red", + "StaticColorNight": "blue", + "StaticColorForeground": "", + "DynamicColorMorning": "red", + "DynamicColorDay": "yellow", + "DynamicColorEvening": "red", + "DynamicColorNight": "blue", + "DynamicColorForeground": "", + "DynamicColorBackground": "" + } + }, + "tics": false, + "stretch": true, + "hours12": false, + "live": false } diff --git a/tests/testdata/static_tics.json b/tests/testdata/static_tics.json index d7da64d..6425ea8 100644 --- a/tests/testdata/static_tics.json +++ b/tests/testdata/static_tics.json @@ -1,48 +1,48 @@ { - "config_version": "1.0", - "timezones": [ - { - "Name": "New York", - "TZ": "America/New_York" - }, - { - "Name": "Berlin", - "TZ": "Europe/Berlin" - }, - { - "Name": "Shanghai", - "TZ": "Asia/Shanghai" - }, - { - "Name": "Sydney", - "TZ": "Australia/Sydney" - } - ], - "style": { - "symbols": "rectangles", - "colorize": false, - "day_segments": { - "morning": 6, - "day": 8, - "evening": 18, - "night": 22 - }, - "coloring": { - "StaticColorMorning": "red", - "StaticColorDay": "yellow", - "StaticColorEvening": "red", - "StaticColorNight": "blue", - "StaticColorForeground": "", - "DynamicColorMorning": "red", - "DynamicColorDay": "yellow", - "DynamicColorEvening": "red", - "DynamicColorNight": "blue", - "DynamicColorForeground": "", - "DynamicColorBackground": "" - } + "config_version": "1.0", + "timezones": [ + { + "Name": "New York", + "TZ": "America/New_York" }, - "tics": true, - "stretch": true, - "hours12": false, - "live": false + { + "Name": "Berlin", + "TZ": "Europe/Berlin" + }, + { + "Name": "Shanghai", + "TZ": "Asia/Shanghai" + }, + { + "Name": "Sydney", + "TZ": "Australia/Sydney" + } + ], + "style": { + "symbols": "rectangles", + "colorize": false, + "day_segments": { + "morning": 6, + "day": 8, + "evening": 18, + "night": 22 + }, + "coloring": { + "StaticColorMorning": "red", + "StaticColorDay": "yellow", + "StaticColorEvening": "red", + "StaticColorNight": "blue", + "StaticColorForeground": "", + "DynamicColorMorning": "red", + "DynamicColorDay": "yellow", + "DynamicColorEvening": "red", + "DynamicColorNight": "blue", + "DynamicColorForeground": "", + "DynamicColorBackground": "" + } + }, + "tics": true, + "stretch": true, + "hours12": false, + "live": false } diff --git a/version.go b/version.go index d8e0d35..c744770 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,23 @@ package main -const Version = "v0.1.10" +// Version, commit, and date are set by the release process. +var ( + version = "v0.0.0" + commit = "none" + date = "1970-01-01T00:00:00Z" +) + +type ReleaseInfo struct { + Version string `json:"version"` + Commit string `json:"commit"` + Date string `json:"date"` +} + +// GetReleaseInfo returns the version information. +func GetReleaseInfo() ReleaseInfo { + return ReleaseInfo{ + Version: version, + Commit: commit, + Date: date, + } +}