Skip to content

Commit e2a3188

Browse files
committed
Add CI, releases, and version flag
- Add GitHub Actions CI workflow (test, lint, build matrix) - Add GitHub Actions release workflow with GoReleaser - Add .goreleaser.yml for multi-platform binary releases - Add -v/--version flag with build info - Add godoc comments to codes package - Update README with CI badge and release instructions
1 parent 0a3ddd7 commit e2a3188

File tree

6 files changed

+192
-11
lines changed

6 files changed

+192
-11
lines changed

.github/workflows/ci.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: go.mod
19+
20+
- name: Download dependencies
21+
run: go mod download
22+
23+
- name: Run tests
24+
run: go test -v -race -coverprofile=coverage.out ./...
25+
26+
- name: Upload coverage
27+
uses: codecov/codecov-action@v4
28+
with:
29+
files: coverage.out
30+
continue-on-error: true
31+
32+
lint:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Set up Go
38+
uses: actions/setup-go@v5
39+
with:
40+
go-version-file: go.mod
41+
42+
- name: Run golangci-lint
43+
uses: golangci/golangci-lint-action@v6
44+
with:
45+
version: latest
46+
47+
build:
48+
runs-on: ubuntu-latest
49+
strategy:
50+
matrix:
51+
goos: [linux, darwin, windows]
52+
goarch: [amd64, arm64]
53+
steps:
54+
- uses: actions/checkout@v4
55+
56+
- name: Set up Go
57+
uses: actions/setup-go@v5
58+
with:
59+
go-version-file: go.mod
60+
61+
- name: Build
62+
env:
63+
GOOS: ${{ matrix.goos }}
64+
GOARCH: ${{ matrix.goarch }}
65+
run: |
66+
binary_name="t"
67+
if [ "$GOOS" = "windows" ]; then
68+
binary_name="t.exe"
69+
fi
70+
go build -o "${binary_name}" ./cmd/t

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version-file: go.mod
23+
24+
- name: Run GoReleaser
25+
uses: goreleaser/goreleaser-action@v6
26+
with:
27+
version: latest
28+
args: release --clean
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
version: 2
2+
3+
project_name: t
4+
5+
before:
6+
hooks:
7+
- go mod tidy
8+
9+
builds:
10+
- main: ./cmd/t
11+
binary: t
12+
env:
13+
- CGO_ENABLED=0
14+
goos:
15+
- linux
16+
- darwin
17+
- windows
18+
goarch:
19+
- amd64
20+
- arm64
21+
ldflags:
22+
- -s -w
23+
- -X main.version={{.Version}}
24+
- -X main.commit={{.ShortCommit}}
25+
- -X main.date={{.Date}}
26+
27+
archives:
28+
- format: tar.gz
29+
name_template: >-
30+
{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}
31+
format_overrides:
32+
- goos: windows
33+
format: zip
34+
35+
checksum:
36+
name_template: 'checksums.txt'
37+
38+
changelog:
39+
sort: asc
40+
filters:
41+
exclude:
42+
- '^docs:'
43+
- '^test:'
44+
- '^ci:'

README.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
# t
22

3+
[![CI](https://github.com/cv/t/actions/workflows/ci.yml/badge.svg)](https://github.com/cv/t/actions/workflows/ci.yml)
4+
35
A quick and simple world clock for the command-line using IATA airport codes.
46

57
## Installation
68

9+
### From source
10+
711
```bash
812
go install github.com/cv/t/cmd/t@latest
913
```
1014

15+
### From releases
16+
17+
Download the latest binary from the [releases page](https://github.com/cv/t/releases).
18+
1119
## Usage
1220

1321
```bash
@@ -18,6 +26,13 @@ JFK: 🕖 19:06:21 (America/New_York)
1826

1927
Any IATA airport code can be used, and will pick the timezone of that airport.
2028

29+
### Version
30+
31+
```bash
32+
$ t --version
33+
t v1.0.0 (commit: abc1234, built: 2024-01-01T00:00:00Z)
34+
```
35+
2136
### Shell Prompt Mode
2237

2338
If `PS1_FORMAT` is set, the output will be compact with no decorations or newline, suitable for shell prompts:
@@ -43,40 +58,45 @@ go build -o t ./cmd/t
4358

4459
```bash
4560
# Run all tests
46-
go test ./...
61+
make test
4762

4863
# Run with coverage
49-
go test -cover ./...
64+
make test-cover
5065

5166
# Run with race detector
52-
go test -race ./...
53-
54-
# Generate coverage report
55-
go test -coverprofile=coverage.out ./...
56-
go tool cover -html=coverage.out -o coverage.html
67+
make test-race
5768
```
5869

5970
### Linting
6071

6172
```bash
62-
# Install golangci-lint
63-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
73+
make lint
74+
```
6475

65-
# Run linters
66-
golangci-lint run
76+
### Releasing
77+
78+
Releases are automated via GitHub Actions. To create a new release:
79+
80+
```bash
81+
git tag v1.0.0
82+
git push origin v1.0.0
6783
```
6884

6985
## Project Structure
7086

7187
```
7288
t/
89+
├── .github/workflows/ # CI and release automation
90+
│ ├── ci.yml
91+
│ └── release.yml
7392
├── cmd/t/ # Main application entry point
7493
│ └── main.go
7594
├── codes/ # IATA airport code to timezone mapping
7695
│ └── iata.go
7796
├── internal/clock/ # Core clock display logic
7897
│ ├── clock.go
7998
│ └── clock_test.go
99+
├── .goreleaser.yml # Release configuration
80100
├── go.mod
81101
├── go.sum
82102
└── README.md

cmd/t/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Usage:
44
//
55
// t <IATA>...
6+
// t -v | --version
67
//
78
// Examples:
89
//
@@ -22,12 +23,25 @@ import (
2223
"github.com/cv/t/internal/clock"
2324
)
2425

26+
// Version information set by goreleaser ldflags
27+
var (
28+
version = "dev"
29+
commit = "none"
30+
date = "unknown"
31+
)
32+
2533
func main() {
2634
if len(os.Args) < 2 {
2735
fmt.Fprint(os.Stderr, "usage: t <IATA>...\n")
2836
os.Exit(1)
2937
}
3038

39+
// Handle version flag
40+
if os.Args[1] == "-v" || os.Args[1] == "--version" {
41+
fmt.Printf("t %s (commit: %s, built: %s)\n", version, commit, date)
42+
return
43+
}
44+
3145
ps1Format := os.Getenv("PS1_FORMAT") != ""
3246
clock.ShowAll(os.Stdout, os.Args[1:], ps1Format, nil)
3347
}

codes/iata.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
// Package codes provides IATA airport code to timezone mappings.
12
package codes
23

4+
// IATA maps airport codes to their corresponding IANA timezone identifiers.
5+
// For example, "SFO" maps to "America/Los_Angeles".
36
var IATA = map[string]string{
47
"3BB": "America/Detroit",
58
"AAA": "Pacific/Tahiti",

0 commit comments

Comments
 (0)