Skip to content

Commit fe1c9ae

Browse files
authored
Q1 2024: deferred updates (#117)
Update GitHub Actions versions as needed, update dependencies, update README. Remove gocover.io badge and address linter warnings & deprecated syntax/deps. Add linting and a basic .golangci.yml config. Add a goreleaser config and rework the build system to use goreleaser to build and ship releases, ensuring consistent builds for intermediate commits and pull requests.
1 parent d7d11e6 commit fe1c9ae

18 files changed

+264
-166
lines changed

.github/workflows/build.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: build
2+
3+
on:
4+
push:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
goreleaser:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
- uses: actions/setup-go@v5
17+
with:
18+
go-version: "1.21"
19+
cache: false
20+
- name: build golines
21+
uses: goreleaser/goreleaser-action@v5
22+
with:
23+
distribution: goreleaser
24+
version: latest
25+
args: build --clean --snapshot
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: lint
2+
on:
3+
push:
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
golangci:
10+
name: golines lint
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-go@v5
15+
with:
16+
go-version: "1.21"
17+
cache: false
18+
- name: run golangci-lint
19+
uses: golangci/golangci-lint-action@v3
20+
with:
21+
version: latest
22+
install-mode: binary
23+
skip-cache: true

.github/workflows/release.yml

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

.github/workflows/go.yml renamed to .github/workflows/test.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
name: golines test
1+
name: test
22
on:
33
push:
4-
branches:
5-
- main
6-
pull_request:
74

85
jobs:
96
test:
10-
runs-on: ${{ matrix.os }}
117
strategy:
128
fail-fast: false
139
matrix:
1410
os:
1511
- ubuntu-latest
1612
- macos-latest
1713
- windows-latest
18-
go: ['1.19']
14+
go:
15+
- "1.21"
16+
- "1.20"
17+
runs-on: ${{ matrix.os }}
1918
name: golines test (using go ${{ matrix.go }} on ${{ matrix.os }})
2019
steps:
21-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4
2221
- name: test golines
23-
uses: actions/setup-go@v3
22+
uses: actions/setup-go@v5
2423
with:
2524
go-version: ${{ matrix.go }}
2625
cache: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.dll
55
*.so
66
*.dylib
7+
/dist
78

89
# Test binary, build with `go test -c`
910
*.test

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
linters:
2+
disable:
3+
- errcheck
4+
5+
run:
6+
timeout: 5m

.goreleaser.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
project_name: golines
2+
before:
3+
hooks:
4+
- go clean -x
5+
6+
builds:
7+
- main: .
8+
ldflags:
9+
- -s -w
10+
flags:
11+
- -trimpath
12+
- -v
13+
goos:
14+
- darwin
15+
- linux
16+
goarch:
17+
- amd64
18+
- arm64
19+
env:
20+
- GOAMD64=v3
21+
22+
universal_binaries:
23+
- replace: true
24+
mod_timestamp: "{{ .CommitTimestamp }}"
25+
26+
archives:
27+
- files:
28+
- README.md
29+
- LICENSE
30+
wrap_in_directory: true
31+
32+
snapshot:
33+
name_template: "{{ incpatch .Version }}-pre+{{ .ShortCommit }}"
34+
35+
changelog:
36+
use: github
37+
filters:
38+
exclude:
39+
- "^docs:"
40+
- "^test:"
41+
42+
announce:
43+
skip: true

Makefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
export GO111MODULE=on
22

33
.PHONY: all
4-
all: install test
5-
6-
.PHONY: install
7-
install:
8-
go install .
4+
all: build test
95

106
.PHONY: build
117
build:
12-
go build .
8+
goreleaser build --clean --snapshot --single-target
139

1410
.PHONY: test
1511
test: vet

README.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
[![Circle CI](https://circleci.com/gh/segmentio/golines.svg?style=svg&circle-token=b1d01d8b035ef0aa71ccd183580586a80cd85271)](https://circleci.com/gh/segmentio/golines)
1+
[![golines test](https://github.com/segmentio/golines/actions/workflows/go.yml/badge.svg)](https://github.com/segmentio/golines/actions/workflows/go.yml)
22
[![Go Report Card](https://goreportcard.com/badge/github.com/segmentio/golines)](https://goreportcard.com/report/github.com/segmentio/golines)
33
[![GoDoc](https://godoc.org/github.com/segmentio/golines?status.svg)](https://godoc.org/github.com/segmentio/golines)
4-
[![Coverage](https://img.shields.io/badge/Go%20Coverage-84%25-brightgreen.svg?longCache=true&style=flat)](https://gocover.io/github.com/segmentio/golines?version=1.13.x)
54

65
# golines
76

8-
Golines is a golang formatter that shortens long lines, in addition to all
7+
Golines is a Go code formatter that shortens long lines, in addition to all
98
of the formatting fixes done by [`gofmt`](https://golang.org/cmd/gofmt/).
109

1110
## Motivation
1211

13-
The standard golang formatting tools (`gofmt`, `goimports`, etc.) are great, but
14-
[deliberately don't shorten long lines](https://github.com/golang/go/issues/11915); instead, this
15-
is an activity left to developers.
12+
The standard Go formatting tools (`gofmt`, `goimports`, etc.) are great, but
13+
[deliberately don't shorten long lines](https://github.com/golang/go/issues/11915);
14+
instead, this is an activity left to developers.
1615

1716
While there are different tastes when it comes to line lengths in go, we've generally found
1817
that very long lines are more difficult to read than their shortened alternatives. As an example:
@@ -33,7 +32,7 @@ myMap := map[string]string{
3332
}
3433
```
3534

36-
We built `golines` to give go developers the option to automatically shorten long lines, like
35+
We built `golines` to give Go developers the option to automatically shorten long lines, like
3736
the one above, according to their preferences.
3837

3938
More background and technical details are available in
@@ -47,27 +46,29 @@ view of a file with very long lines. More example pairs can be found in the
4746

4847
## Version support
4948

50-
The latest version of `golines` requires golang 1.18 or newer due to generics-related dependencies.
51-
If you need to use `golines` with an older version of go, install the tool from the `v0.9.0`
52-
release.
49+
Newer releases of `golines` require at least Go 1.18 due to generics-related dependencies.
50+
However, the [minimum version](https://go.dev/ref/mod#go-mod-file-go) in [`go.mod`](./go.mod)
51+
should be considered the minimum required version of Go for any given version
52+
of `golines.` If you need to use `golines` with an older version of go, install
53+
the tool from the `v0.9.0` release.
5354

5455
## Usage
5556

56-
First, install the tool. If you're using golang 1.18 or newer, run:
57+
First, install the tool. If you're using Go 1.21 or newer, run:
5758

58-
```
59+
```text
5960
go install github.com/segmentio/golines@latest
6061
```
6162

62-
Otherwise, for older golang versions, run:
63+
Otherwise, for older Go versions, run:
6364

64-
```
65+
```text
6566
go install github.com/segmentio/[email protected]
6667
```
6768

6869
Then, run:
6970

70-
```
71+
```text
7172
golines [paths to format]
7273
```
7374

@@ -79,10 +80,10 @@ files in place, use the `-w` flag.
7980

8081
## Options
8182

82-
Some other options are described in the sections below. Run `golines --help` to see
83-
all available flags and settings.
83+
Some other options are described in the sections below. Run `golines --help` to
84+
see all available flags and settings.
8485

85-
#### Line length settings
86+
### Line length settings
8687

8788
By default, the tool tries to shorten lines that are longer than 100 columns
8889
and assumes that 1 tab = 4 columns. The latter can be changed via the
@@ -102,15 +103,15 @@ with the `--shorten-comments` flag.
102103

103104
#### Custom formatters
104105

105-
By default, the tool will use [`goimports`](https://godoc.org/golang.org/x/tools/cmd/goimports) as
106-
the base formatter (if found), otherwise it will revert to `gofmt`. An explicit formatter can be
107-
set via the `--base-formatter` flag; the command provided here should accept its input via
108-
`stdin` and write its output to `stdout`.
106+
By default, the tool will use [`goimports`](https://godoc.org/golang.org/x/tools/cmd/goimports)
107+
as the base formatter (if found), otherwise it will revert to `gofmt`. An explicit
108+
formatter can be set via the `--base-formatter` flag; the command provided here
109+
should accept its input via `stdin` and write its output to `stdout`.
109110

110111
#### Generated files
111112

112-
By default, the tool will not format any files that look like they're generated. If you
113-
want to reformat these too, run with the `--no-ignore-generated` flag.
113+
By default, the tool will not format any files that look like they're generated.
114+
If you want to reformat these too, run with the `--no-ignore-generated` flag.
114115

115116
#### Chained method splitting
116117

@@ -140,8 +141,8 @@ myObj.Method(arg1, arg2, arg3).
140141
AThirdMethod(arg1, arg2)
141142
```
142143

143-
The original behavior can be used by running the tool with the `--no-chain-split-dots`
144-
flag.
144+
The original behavior can be used by running the tool with the
145+
`--no-chain-split-dots` flag.
145146

146147
#### Struct tag reformatting
147148

@@ -167,9 +168,8 @@ let g:go_fmt_options = {
167168
1. Install the [Run on Save](https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave) extension
168169
2. Go into the VSCode settings menu, scroll down to the section for the "Run on Save"
169170
extension, click the "Edit in settings.json" link
170-
3. Set the `emeraldwalk.runonsave` key as follows (adding other flags to the `golines`
171-
command as desired):
172-
171+
3. Set the `emeraldwalk.runonsave` key as follows
172+
(adding other flags to the `golines` command as desired):
173173
```
174174
"emeraldwalk.runonsave": {
175175
"commands": [
@@ -181,18 +181,18 @@ let g:go_fmt_options = {
181181
}
182182
```
183183

184-
4. Save the settings and restart VSCode
184+
1. Save the settings and restart VSCode
185185

186186
### Goland
187187

188188
1. Go into the Goland settings and click "Tools" -> "File Watchers" then click the plus to create a new file watcher
189189
2. Set the following properties and confirm by clicking OK:
190-
- __Name:__ `golines`
191-
- __File type:__ `Go files`
192-
- __Scope:__ `Project Files`
193-
- __Program:__ `golines`
194-
- __Arguments:__ `$FilePath$ -w`
195-
- __Output paths to refresh:__ `$FilePath$`
190+
- __Name:__ `golines`
191+
- __File type:__ `Go files`
192+
- __Scope:__ `Project Files`
193+
- __Program:__ `golines`
194+
- __Arguments:__ `$FilePath$ -w`
195+
- __Output paths to refresh:__ `$FilePath$`
196196
3. Activate your newly created file watcher in the Goland settings under "Tools" -> "Actions on save"
197197

198198
### Others

diff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strings"
88

99
"github.com/pmezard/go-difflib/difflib"
10-
"golang.org/x/crypto/ssh/terminal"
10+
"golang.org/x/term"
1111
)
1212

1313
// PrettyDiff prints colored, git-style diffs to the console.
@@ -36,7 +36,7 @@ func PrettyDiff(path string, contents []byte, results []byte) error {
3636
for _, line := range strings.Split(text, "\n") {
3737
line = strings.TrimRight(line, " ")
3838
switch {
39-
case !terminal.IsTerminal(int(os.Stdout.Fd())) && len(line) > 0:
39+
case !term.IsTerminal(int(os.Stdout.Fd())) && len(line) > 0:
4040
fmt.Printf("%s\n", line)
4141
case strings.HasPrefix(line, "+"):
4242
fmt.Printf("%s%s%s\n", ansiGreen, line, ansiEnd)

0 commit comments

Comments
 (0)