Skip to content

Commit fed057b

Browse files
committed
Adding additional tests to increase coverage. Cleanup of tasks in taskfile.yml
1 parent 8a39829 commit fed057b

File tree

11 files changed

+1047
-175
lines changed

11 files changed

+1047
-175
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ issues:
3131
linters:
3232
- gosec
3333
- errcheck
34+
- path: _test\.go
35+
text: "fieldalignment:"
3436
max-issues-per-linter: 0
3537
max-same-issues: 0
3638

RELEASE.md

Lines changed: 30 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,50 @@
11
# Release Process
22

3-
This document outlines the process for creating new releases of the Glean CLI.
3+
## Setup
44

5-
## Versioning
5+
After cloning the repository, run the following command to install required dependencies:
66

7-
We follow [Semantic Versioning](https://semver.org/) (SemVer):
8-
- MAJOR version (X.0.0) - incompatible API changes
9-
- MINOR version (0.X.0) - add functionality in a backward compatible manner
10-
- PATCH version (0.0.X) - backward compatible bug fixes
11-
12-
## Prerequisites
13-
14-
Install the required tools:
157
```bash
16-
# Install svu for automated versioning
17-
go install github.com/caarlos0/svu@latest
8+
task setup
189
```
1910

20-
## Release Steps
21-
22-
You can create a new release using either the automated task or the manual steps below.
23-
24-
### Automated Release
25-
26-
```bash
27-
# This will run all checks, create and push the tag
28-
task release
29-
```
30-
31-
### Manual Steps
32-
33-
If you need more control over the release process, you can follow these steps manually:
11+
This will install:
12+
- `svu` - for semantic versioning and tag management
13+
- `gotestsum` - for improved test output and summaries
14+
- `golangci-lint` - for code linting
3415

35-
1. **Ensure Main Branch is Ready**
36-
```bash
37-
git checkout main
38-
git pull origin main
39-
```
16+
## Creating a Release
4017

41-
2. **Run Tests and Checks**
42-
```bash
43-
task test
44-
task lint
45-
```
18+
To create a new release:
4619

47-
3. **Create Release**
20+
1. Ensure your working directory is clean and you're on the `main` branch
21+
2. Run the release task:
4822
```bash
49-
# Preview the next version based on conventional commits
50-
svu next
51-
52-
# Create and push the tag with the next version
53-
git tag -a $(svu next) -m "Release $(svu next)"
54-
git push origin $(svu next)
23+
task release
5524
```
5625

57-
Note: `svu` automatically determines the next version based on your commit messages:
58-
- `feat:` -> MINOR version bump
59-
- `fix:` -> PATCH version bump
60-
- `BREAKING CHANGE:` in commit body -> MAJOR version bump
61-
62-
4. **Monitor Release Process**
63-
- The GitHub Action will automatically:
64-
- Create a GitHub release
65-
- Build binaries for all supported platforms
66-
- Generate release notes from commits
67-
- Upload artifacts to the release
68-
- Update the Homebrew formula
69-
70-
5. **Verify Release**
71-
- Check the [GitHub releases page](https://github.com/scalvert/glean-cli/releases)
72-
- Verify Homebrew formula was updated
73-
- Test installation methods:
74-
```bash
75-
# Homebrew
76-
brew update
77-
brew install scalvert/tap/glean-cli
78-
79-
# Go Install
80-
go install github.com/scalvert/glean-cli@latest
81-
82-
# Shell Script
83-
curl -fsSL https://raw.githubusercontent.com/scalvert/glean-cli/main/install.sh | sh
84-
```
26+
This will:
27+
- Run all checks (lint, test, build)
28+
- Show the current version and commits since last release
29+
- Calculate and propose the next version
30+
- Create and push a git tag
31+
- Trigger the release workflow
8532

86-
## Release Artifacts
33+
### Optional Parameters
8734

88-
Each release includes:
89-
- Binary distributions for:
90-
- macOS (x86_64, arm64)
91-
- Linux (x86_64, arm64)
92-
- Windows (x86_64, arm64)
93-
- Source code (zip, tar.gz)
94-
- Checksums file
95-
- Changelog
96-
97-
## Commit Convention
98-
99-
To make the most of automated versioning, follow these commit message conventions:
100-
101-
```
102-
<type>: <description>
103-
104-
[optional body]
105-
106-
[optional footer(s)]
107-
```
108-
109-
Types:
110-
- `feat:` - New feature (MINOR version bump)
111-
- `fix:` - Bug fix (PATCH version bump)
112-
- `docs:` - Documentation only changes
113-
- `style:` - Changes that do not affect the meaning of the code
114-
- `refactor:` - Code change that neither fixes a bug nor adds a feature
115-
- `perf:` - Code change that improves performance
116-
- `test:` - Adding missing tests or correcting existing tests
117-
- `chore:` - Changes to the build process or auxiliary tools
118-
119-
Breaking Changes:
120-
- Add `BREAKING CHANGE:` to the commit body to trigger a MAJOR version bump
121-
- Example:
35+
- Specify a version:
36+
```bash
37+
task release VERSION=v1.2.3
12238
```
123-
feat: change API endpoint structure
12439

125-
BREAKING CHANGE: The API endpoint structure has changed from /v1/* to /api/v1/*
40+
- Force update an existing tag:
41+
```bash
42+
task release VERSION=v1.2.3 FORCE=true
12643
```
12744

128-
## Troubleshooting
129-
130-
1. **GitHub Action Failed**
131-
- Check the Action logs for errors
132-
- Ensure GITHUB_TOKEN has required permissions
133-
- Verify the tag follows the format `v*` (e.g., v1.0.0)
134-
135-
2. **Homebrew Update Failed**
136-
- Check if homebrew-tap repository exists
137-
- Verify repository permissions
138-
- Check the "Update Homebrew tap" step in the Action logs
139-
140-
3. **Bad Release**
141-
If a release has issues:
142-
```bash
143-
# Get current version
144-
current_version=$(svu current)
145-
146-
# Delete tag locally
147-
git tag -d $current_version
148-
149-
# Delete tag remotely
150-
git push --delete origin $current_version
151-
```
152-
Then fix the issues and retry the release process.
153-
154-
## Notes
45+
## Monitoring
15546

156-
- Release notes are automatically generated from commit messages
157-
- Commits starting with `docs:`, `test:`, `ci:` are excluded from release notes
158-
- The release process is automated via GitHub Actions
159-
- Binary distributions are built using GoReleaser
160-
- All releases are automatically published to GitHub Releases
47+
After creating a release:
48+
1. The GitHub Actions workflow will be triggered automatically
49+
2. Monitor the release at: https://github.com/scalvert/glean-cli/actions
50+
3. Once complete, the release will be available at: https://github.com/scalvert/glean-cli/releases

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ go 1.20
44

55
require (
66
github.com/MakeNowJust/heredoc v1.0.0
7+
github.com/alecthomas/chroma v0.10.0
78
github.com/briandowns/spinner v1.23.2
9+
github.com/mattn/go-tty v0.0.7
810
github.com/spf13/cobra v1.8.1
911
github.com/stretchr/testify v1.10.0
1012
github.com/zalando/go-keyring v0.2.3
1113
golang.org/x/term v0.28.0
12-
gopkg.in/validator.v2 v2.0.1
1314
)
1415

1516
require (
16-
github.com/alecthomas/chroma v0.10.0 // indirect
1717
github.com/alessio/shellescape v1.4.1 // indirect
1818
github.com/danieljoos/wincred v1.2.0 // indirect
1919
github.com/davecgh/go-spew v1.1.1 // indirect
2020
github.com/dlclark/regexp2 v1.4.0 // indirect
21-
github.com/fatih/color v1.7.0 // indirect
21+
github.com/fatih/color v1.16.0 // indirect
2222
github.com/godbus/dbus/v5 v5.1.0 // indirect
2323
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2424
github.com/mattn/go-colorable v0.1.13 // indirect
2525
github.com/mattn/go-isatty v0.0.20 // indirect
26-
github.com/mattn/go-tty v0.0.7 // indirect
2726
github.com/pmezard/go-difflib v1.0.0 // indirect
2827
github.com/spf13/pflag v1.0.5 // indirect
2928
golang.org/x/sys v0.29.0 // indirect
29+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
3030
gopkg.in/yaml.v3 v3.0.1 // indirect
3131
)

go.sum

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,19 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
1414
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1515
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
1616
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
17-
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
18-
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
17+
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
18+
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
1919
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
2020
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
2121
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
2222
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
2323
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
24+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
25+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
2426
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
25-
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
26-
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
27+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
2728
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
2829
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
29-
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
30-
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
3130
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
3231
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
3332
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
@@ -47,7 +46,6 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
4746
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
4847
github.com/zalando/go-keyring v0.2.3 h1:v9CUu9phlABObO4LPWycf+zwMG7nlbb3t/B5wa97yms=
4948
github.com/zalando/go-keyring v0.2.3/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk=
50-
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
5149
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5250
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5351
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
@@ -56,8 +54,7 @@ golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
5654
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
5755
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5856
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
59-
gopkg.in/validator.v2 v2.0.1 h1:xF0KWyGWXm/LM2G1TrEjqOu4pa6coO9AlWSf3msVfDY=
60-
gopkg.in/validator.v2 v2.0.1/go.mod h1:lIUZBlB3Im4s/eYp39Ry/wkR02yOPhZ9IwIRBjuPuG8=
57+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
6158
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6259
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
6360
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/config/config.go

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@ import (
99
"github.com/zalando/go-keyring"
1010
)
1111

12+
// keyringProvider defines the interface for keyring operations
13+
type keyringProvider interface {
14+
Get(service, key string) (string, error)
15+
Set(service, key, value string) error
16+
Delete(service, key string) error
17+
}
18+
19+
// systemKeyring implements keyringProvider using the system keyring
20+
type systemKeyring struct{}
21+
22+
func (s *systemKeyring) Get(service, key string) (string, error) {
23+
return keyring.Get(service, key)
24+
}
25+
26+
func (s *systemKeyring) Set(service, key, value string) error {
27+
return keyring.Set(service, key, value)
28+
}
29+
30+
func (s *systemKeyring) Delete(service, key string) error {
31+
return keyring.Delete(service, key)
32+
}
33+
34+
// keyringImpl is the current keyring implementation, can be swapped for testing
35+
var keyringImpl keyringProvider = &systemKeyring{}
36+
1237
const (
1338
serviceName = "glean-cli"
1439
hostKey = "host"
@@ -51,15 +76,15 @@ func ValidateAndTransformHost(host string) (string, error) {
5176
func LoadConfig() (*Config, error) {
5277
cfg := &Config{}
5378

54-
if host, err := keyring.Get(serviceName, hostKey); err == nil {
79+
if host, err := keyringImpl.Get(serviceName, hostKey); err == nil {
5580
cfg.GleanHost = host
5681
}
5782

58-
if token, err := keyring.Get(serviceName, tokenKey); err == nil {
83+
if token, err := keyringImpl.Get(serviceName, tokenKey); err == nil {
5984
cfg.GleanToken = token
6085
}
6186

62-
if email, err := keyring.Get(serviceName, emailKey); err == nil {
87+
if email, err := keyringImpl.Get(serviceName, emailKey); err == nil {
6388
cfg.GleanEmail = email
6489
}
6590

@@ -72,19 +97,19 @@ func SaveConfig(host, token, email string) error {
7297
if err != nil {
7398
return err
7499
}
75-
if err := keyring.Set(serviceName, hostKey, validHost); err != nil {
100+
if err := keyringImpl.Set(serviceName, hostKey, validHost); err != nil {
76101
return err
77102
}
78103
}
79104

80105
if token != "" {
81-
if err := keyring.Set(serviceName, tokenKey, token); err != nil {
106+
if err := keyringImpl.Set(serviceName, tokenKey, token); err != nil {
82107
return err
83108
}
84109
}
85110

86111
if email != "" {
87-
if err := keyring.Set(serviceName, emailKey, email); err != nil {
112+
if err := keyringImpl.Set(serviceName, emailKey, email); err != nil {
88113
return err
89114
}
90115
}
@@ -93,13 +118,13 @@ func SaveConfig(host, token, email string) error {
93118
}
94119

95120
func ClearConfig() error {
96-
if err := keyring.Delete(serviceName, hostKey); err != nil && err != keyring.ErrNotFound {
121+
if err := keyringImpl.Delete(serviceName, hostKey); err != nil && err != keyring.ErrNotFound {
97122
return err
98123
}
99-
if err := keyring.Delete(serviceName, tokenKey); err != nil && err != keyring.ErrNotFound {
124+
if err := keyringImpl.Delete(serviceName, tokenKey); err != nil && err != keyring.ErrNotFound {
100125
return err
101126
}
102-
if err := keyring.Delete(serviceName, emailKey); err != nil && err != keyring.ErrNotFound {
127+
if err := keyringImpl.Delete(serviceName, emailKey); err != nil && err != keyring.ErrNotFound {
103128
return err
104129
}
105130
return nil

0 commit comments

Comments
 (0)