Skip to content

Commit d6a27bc

Browse files
authored
Add coverall CI pipeline, add doc about testing approach, replace md file formatter (#54)
* Use prettier instead of mdox, re-format docs, respect 2 space indents
1 parent 81dd88a commit d6a27bc

File tree

23 files changed

+323
-174
lines changed

23 files changed

+323
-174
lines changed

.github/release.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
changelog:
2+
exclude:
3+
labels:
4+
- ignore-for-release
5+
categories:
6+
- title: Breaking Changes 🛠
7+
labels:
8+
- Semver-Major
9+
- breaking-change
10+
- title: Enhancements 🚀
11+
labels:
12+
- Semver-Minor
13+
- enhancement
14+
- title: Fixed Bugs 🐛
15+
labels:
16+
- bug
17+
- title: Other Changes ✨
18+
labels:
19+
- "*"

.github/workflows/coverall.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Coverall
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
8+
9+
jobs:
10+
test:
11+
name: Test with Coverage
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: "Set git to use LF"
15+
run: |
16+
git config --global core.autocrlf false
17+
git config --global core.eol lf
18+
- name: "Checkout code"
19+
uses: actions/checkout@v3
20+
- name: "Set up Go"
21+
uses: actions/setup-go@v3
22+
with:
23+
go-version: '1.19.1' # must be hardcoded as it's expected in tests
24+
cache: true
25+
- uses: szenius/set-timezone@a5c1676bd4e141779a42a699cc086f3c5ddd1a6c
26+
with:
27+
timezoneLinux: "Europe/Warsaw"
28+
timezoneMacos: "Europe/Warsaw"
29+
timezoneWindows: "Central European Standard Time"
30+
- name: "Unit tests"
31+
uses: magefile/mage-action@5f7a9a23cfef763949ca41834b868167adbd1b59 # v2.0.0
32+
with:
33+
version: latest
34+
args: test:unit
35+
36+
- name: "Install goveralls"
37+
run: go install github.com/mattn/goveralls@latest
38+
- name: "Send coverage"
39+
env:
40+
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
run: goveralls -coverprofile=coverage.out -service=github

docs/community/testing.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Package testing
2+
3+
The `version` package is tested both via unit and e2e tests.
4+
5+
## Unit tests
6+
7+
Unit tests focus more on the corner cases that are hard to reproduce using e2e testing. Unit tests are executed on CI via [**Testing**](https://github.com/mszostok/version/actions/workflows/testing.yml) workflow.
8+
9+
- All tests are executed with the latest Go version on all platforms, using GitHub Action job strategy:
10+
```yaml
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, macos-latest, windows-latest]
14+
```
15+
- All tests are run both on pull-requests and the `main` branch
16+
- The tests' coverage is uploaded to [coveralls.io/github/mszostok/version](https://coveralls.io/github/mszostok/version)
17+
18+
## E2E tests
19+
20+
The e2e tests build a Go binary, run it, and compare with [golden files](https://github.com/mszostok/version/tree/main/tests/e2e/testdata). E2E tests are executed on CI via [**Testing**](https://github.com/mszostok/version/actions/workflows/testing.yml) workflow.
21+
22+
As a result, e2e test focus on:
23+
24+
- Building Go binaries
25+
- Overriding version information via `ldflags`
26+
- Running binary on operating system
27+
- Testing if color output for non-tty output streams is disabled automatically
28+
- Ensuring that all [examples](https://github.com/mszostok/version/tree/main/examples) are runnable
29+
- Executing a real call against GitHub API
30+
- Executing binaries on all platforms, using GitHub Action job strategy:
31+
```yaml
32+
strategy:
33+
matrix:
34+
os: [ubuntu-latest, macos-latest, windows-latest]
35+
```
36+
37+
Each time a new functionality is implemented, a dedicated [test case](https://github.com/mszostok/version/blob/main/tests/e2e/e2e_test.go#L31) is added.
38+
39+
!!! note
40+
41+
Currently, there is no easy way to calculate the coverage based on the e2e tests (built and executed binaries). However, this will be enabled once the [golang#51430](https://github.com/golang/go/issues/51430) issue will be implemented.

docs/customization/extra-fields.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
The `version` package supports most popular version fields natively.
44

55
??? example "Native fields"
6+
67
| Key | Description |
78
|---------------|-----------------------------------------------------------------------------------------------------------------|
89
| `.Version` | Binary version value set via `-ldflags`, otherwise taken from `go install url/tool@version`. |
@@ -28,7 +29,7 @@ Steps:
2829

2930
1. Assign your custom struct to `Info.ExtraFields`.
3031

31-
Go struct with nested fields are not properly supported in Pretty mode.
32+
Go struct with nested fields are not properly supported in Pretty mode.
3233

3334
2. Use `json`, `yaml` and `pretty` field tags to define the field name for a given output format.
3435
3. In the Pretty mode, fields are printed in the same order as defined in struct.

docs/customization/omit-unset.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66

77
- Explicitly exclude a given set of version fields:
88

9-
```go
10-
// excludedFields defines preset for fields that should be excluded in output.
11-
const excludedFields = printer.FieldCompiler | printer.FieldPlatform
9+
```go
10+
// excludedFields defines preset for fields that should be excluded in output.
11+
const excludedFields = printer.FieldCompiler | printer.FieldPlatform
1212

13-
p := printer.New(printer.WithExcludedFields(excludedFields))
14-
if err := p.Print(os.Stdout); err != nil {
15-
log.Fatal(err)
16-
}
17-
```
13+
p := printer.New(printer.WithExcludedFields(excludedFields))
14+
if err := p.Print(os.Stdout); err != nil {
15+
log.Fatal(err)
16+
}
17+
```
1818

1919
- Don't display empty(`""`) and unset(`N/A`) version fields:
2020

21-
```go
22-
p := printer.New(printer.WithOmitUnset(excludedFields))
23-
if err := p.Print(os.Stdout); err != nil {
24-
log.Fatal(err)
25-
}
26-
```
21+
```go
22+
p := printer.New(printer.WithOmitUnset(excludedFields))
23+
if err := p.Print(os.Stdout); err != nil {
24+
log.Fatal(err)
25+
}
26+
```

docs/customization/pretty/format.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Format
22

33
!!! note ""
4+
45
Formatting focuses on the style of your displayed pretty version data.
56

67
Format lets you define your own theme and adjust the output to your branding colors. In general, you can add underscores, bold and italic formatting, text, and background colors.

docs/customization/pretty/layout.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# Layout
22

33
!!! note ""
4+
45
Layout focuses on structured arrangement of pretty version data.
56

67
To define the layout, use [Go templating](https://pkg.go.dev/html/template). You can also use the [`version` package's built-in functions](https://github.com/mszostok/version/blob/main/style/go-tpl-funcs.go) that respect the [formatting settings](./format.md). All helper functions defined by the [Sprig template library](https://masterminds.github.io/sprig/) are also available.
78

89
These are the fields that you can access in your Go template definition:
910

1011
| Key | Description |
11-
|---------------|-----------------------------------------------------------------------------------------------------------------|
12+
| ------------- | --------------------------------------------------------------------------------------------------------------- |
1213
| `.Version` | Binary version value set via `-ldflags`, otherwise taken from `go install url/tool@version`. |
1314
| `.GitCommit` | Git commit value set via `-ldfags`, otherwise taken from `debug.ReadBuildInfo()` - the `vcs.revision` tag. |
1415
| `.BuildDate` | Build date value set via `-ldflags`, otherwise empty. |
@@ -18,7 +19,6 @@ These are the fields that you can access in your Go template definition:
1819
| `.Compiler` | Go compiler taken from `runtime.Compiler`. |
1920
| `.Platform` | Build platform, passed in the following format: `runtime.GOOS/runtime.GOARCH`. |
2021

21-
2222
## Go
2323

2424
!!! tip
@@ -50,7 +50,6 @@ func main() {
5050
}
5151
```
5252

53-
5453
## Config file
5554

5655
!!! coming-soon "Coming soon"
@@ -70,7 +69,7 @@ To load the config file, you can:
7069
goTemplate: |
7170
{{ AdjustKeyWidth .ExtraFields }}
7271
{{ Header .Meta.CLIName }}
73-
72+
7473
{{ Key "Version" }} {{ .Version | Val }}
7574
{{ Key "Git Commit" }} {{ .GitCommit | Commit | Val }}
7675
{{ Key "Build Date" }} {{ .BuildDate | FmtDate | Val }}
@@ -100,4 +99,3 @@ To load the config file, you can:
10099
}
101100
```
102101
<!-- JSONLayout end -->
103-

docs/customization/upgrade-notice/custom-renderer.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ func NewRoot() *cobra.Command {
2323
// 1. Register the 'version' command
2424
extension.NewVersionCobraCmd(
2525
// 2. Explicitly enable the upgrade notice
26-
extension.WithUpgradeNotice("mszostok", "codeowners-validator", opts...)),
26+
extension.WithUpgradeNotice("mszostok", "codeowners-validator", opts...),
27+
),
2728
)
2829

2930
return cmd

0 commit comments

Comments
 (0)