Skip to content

Commit daf67bb

Browse files
authored
Merge pull request #70 from arnested/docs
Improve documentation
2 parents 5a4d98b + b2dba18 commit daf67bb

File tree

4 files changed

+114
-16
lines changed

4 files changed

+114
-16
lines changed

README.md

Lines changed: 111 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,123 @@
11
# Go version action
22

3-
> Provide go versions for use in your workflow
3+
A GitHub action for using the latest released Go version and the
4+
minimal support Go version (from go.mod) and a build matrix of them
5+
and all versions in between.
6+
7+
## Motive
8+
9+
Being consistent is hard.
10+
11+
I used the hard code the Go versions my projects needed to test and
12+
builds against in my GitHub Actions workflow files.
13+
14+
Of course the result was that I used different versions in the
15+
`go.mod` file and my workflow files. And whenever a new version of Go
16+
was released I forgot to add the new version to my build matrix and my
17+
projects weren't tested on the new release(s).
18+
19+
So I build this action.
20+
21+
The action reads the minimal supported Go version from your `go.mod`
22+
file and exposes it as a variable to you workflow.
23+
24+
It also pulls the list of release tags from
25+
https://github.com/golang/go and exposes the latest released Go
26+
version as a variable as well.
27+
28+
From the list of released go versions and the minimal version your
29+
module supports we also build a "matrix" variable to be used as a
30+
build matrix.
31+
32+
While we are at it we also extract the modules path from the `go.mod`
33+
file even though it hasn't really anything to do with versions ;)
434

535
## Inputs
636

37+
If your `go mod` file is located in a non standard location you can
38+
specify the working directory where it is located:
39+
740
```yaml
8-
working-directory:
9-
description: Working direcory where you go.mod file is located
10-
required: false
11-
default: .
41+
working-directory:
42+
description: Working direcory where you go.mod file is located
43+
required: false
44+
default: .
1245
```
1346
1447
## Outputs
1548
1649
```yaml
17-
latest:
18-
description: The latest go version
19-
minimal:
20-
description: The minial go version (as specified by go.mod)
21-
matrix:
22-
description: An array of go versions from the minimum supported version to the latest released version
23-
module:
24-
description: The go module name (as specified by go.mod)
50+
latest:
51+
description: The latest go version
52+
minimal:
53+
description: The minial go version (as specified by go.mod)
54+
matrix:
55+
description: An (stringified) array of go versions from the minimum supported version to the latest released version
56+
module:
57+
description: The go module name (as specified by go.mod)
58+
```
59+
60+
## Examples
61+
62+
Let's say your `go.mod` specifies go 1.13 as the minimal supported
63+
version and you want your workflow to setup go version 1.13 using the
64+
[actions/setup-go](https://github.com/actions/setup-go) action:
65+
66+
```yaml
67+
name: My go workflow
68+
on: pull_request
69+
70+
jobs:
71+
my-go-workflow:
72+
runs-on: ubuntu-latest
73+
steps:
74+
- uses: actions/checkout@v2
75+
- uses: arnested/go-version-action@v1
76+
id: go-version
77+
- name: Install Go ${{ steps.go-version.outputs.minimal }}
78+
uses: actions/setup-go@v2
79+
with:
80+
go-version: ${{ steps.go-version.outputs.minimal }}
81+
```
82+
83+
![Log of running action](docs/action-run.png)
84+
85+
If you want do matrix test of all Go versions from your minimally
86+
supported version up to the latest released version we need to do a
87+
bit more.
88+
89+
We have to run the version lookup as a separate job and let the test
90+
job depend on it:
91+
92+
```yaml
93+
on: push
94+
name: Test
95+
96+
jobs:
97+
go-versions:
98+
name: Lookup go versions
99+
runs-on: ubuntu-latest
100+
outputs:
101+
matrix: ${{ steps.versions.outputs.matrix }}
102+
steps:
103+
- uses: actions/checkout@v2
104+
- uses: arnested/go-version-action@v1
105+
id: versions
106+
test:
107+
name: Test
108+
runs-on: ubuntu-latest
109+
needs: go-versions
110+
strategy:
111+
matrix:
112+
version: ${{ fromJSON(needs.go-versions.outputs.matrix) }}
113+
steps:
114+
- uses: actions/checkout@v2
115+
- name: Install Go
116+
uses: actions/setup-go@v2
117+
with:
118+
go-version: ${{ matrix.version }}
119+
- name: go test
120+
run: go test -v -race -cover -covermode=atomic -coverprofile=coverage.txt ./...
25121
```
122+
123+
![The workflow summary](docs/action-matrix-summary.png)

action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: go-version-action
2-
description: Provide go versions for use in your workflow
1+
name: Go version action
2+
description: A GitHub action for using the latest released Go version and the minimal support Go version (from go.mod) and a build matrix of them and all versions in between.
33
inputs:
44
working-directory:
55
description: Working direcory
@@ -11,7 +11,7 @@ outputs:
1111
minimal:
1212
description: The minial go version (as specified by go.mod)
1313
matrix:
14-
description: An array of go versions from the minimum supported version to the latest released version
14+
description: An (stringified) array of go versions from the minimal supported version to the latest released version
1515
module:
1616
description: The go module (as specified by go.mod)
1717
runs:

docs/action-matrix-summary.png

17.6 KB
Loading

docs/action-run.png

120 KB
Loading

0 commit comments

Comments
 (0)