Skip to content

Commit e8fdccc

Browse files
authored
Merge pull request #23 from per1234/test-go
Add template workflow to test Go code
2 parents 4262804 + 90a384a commit e8fdccc

File tree

4 files changed

+226
-0
lines changed

4 files changed

+226
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# See: https://taskfile.dev/#/usage
2+
version: "3"
3+
4+
vars:
5+
DEFAULT_GO_PACKAGES:
6+
sh: echo $(go list ./... | tr '\n' ' ')
7+
8+
tasks:
9+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml
10+
go:test:
11+
desc: Run unit tests
12+
cmds:
13+
- |
14+
go test \
15+
-v \
16+
-short \
17+
-run '{{default ".*" .GO_TEST_REGEX}}' \
18+
{{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \
19+
-coverprofile=coverage_unit.txt \
20+
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/test-go-task.md
2+
name: Test Go
3+
4+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
paths:
8+
- ".github/workflows/test-go-task.ya?ml"
9+
- "go.mod"
10+
- "go.sum"
11+
- "Taskfile.ya?ml"
12+
- "**.go"
13+
- "**/testdata/**"
14+
pull_request:
15+
paths:
16+
- ".github/workflows/test-go-task.ya?ml"
17+
- "go.mod"
18+
- "go.sum"
19+
- "Taskfile.ya?ml"
20+
- "**.go"
21+
- "**/testdata/**"
22+
workflow_dispatch:
23+
repository_dispatch:
24+
25+
jobs:
26+
build:
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v2
32+
33+
- name: Install Go
34+
uses: actions/setup-go@v2
35+
with:
36+
go-version: "1.14"
37+
38+
- name: Install Task
39+
uses: arduino/setup-task@v1
40+
with:
41+
repo-token: ${{ secrets.GITHUB_TOKEN }}
42+
version: 3.x
43+
44+
- name: Build application
45+
run: task go:build
46+
47+
# Allow interested parties to easily try the build
48+
- name: Save binary as workflow artifact
49+
uses: actions/upload-artifact@v2
50+
with:
51+
if-no-files-found: error
52+
# TODO: specify binary name here:
53+
path: BINARY_NAME
54+
name: BINARY_NAME
55+
56+
test:
57+
runs-on: ubuntu-latest
58+
59+
steps:
60+
- name: Checkout repository
61+
uses: actions/checkout@v2
62+
63+
- name: Install Go
64+
uses: actions/setup-go@v2
65+
with:
66+
go-version: "1.14"
67+
68+
- name: Install Task
69+
uses: arduino/setup-task@v1
70+
with:
71+
repo-token: ${{ secrets.GITHUB_TOKEN }}
72+
version: 3.x
73+
74+
- name: Run tests
75+
run: task go:test

workflow-templates/test-go-task.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# "Test Go" workflow (Task)
2+
3+
Workflow file: [test-go-task.yml](test-go-task.yml)
4+
5+
Lint and check formatting of a [Go](https://golang.org/) module.
6+
7+
This is the version of the workflow for projects using the [Task](https://taskfile.dev/#/) task runner tool.
8+
9+
## Assets
10+
11+
- [`Taskfile.yml`](assets/test-go-task/Taskfile.yml]
12+
- Install to: repository root (or add the `go:test` task into the existing `Taskfile.yml`)
13+
14+
## Readme badge
15+
16+
Markdown badge:
17+
18+
```markdown
19+
[![Test Go status](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/test-go-task.yml/badge.svg)](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/test-go-task.yml)
20+
```
21+
22+
Replace the `REPO_OWNER` and `REPO_NAME` placeholders in the URLs with the final repository owner and name ([example](https://raw.githubusercontent.com/arduino-libraries/ArduinoIoTCloud/master/README.md)).
23+
24+
---
25+
26+
Asciidoc badge:
27+
28+
```adoc
29+
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/test-go-task.yml/badge.svg["Test Go status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/test-go-task.yml"]
30+
```
31+
32+
Define the `{repository-owner}` and `{repository-name}` attributes and use them throughout the readme ([example](https://raw.githubusercontent.com/arduino-libraries/WiFiNINA/master/README.adoc)).
33+
34+
## Commit message
35+
36+
```
37+
Add CI workflow to test Go code
38+
39+
On every push and pull request that affects relevant files:
40+
41+
- Build the project.
42+
- Upload the binary as a workflow artifact to allow interested parties to try it out without needing to build it
43+
themselves.
44+
- Run the project's Go code tests.
45+
```
46+
47+
## PR message
48+
49+
```markdown
50+
On every push and pull request that affects relevant files:
51+
52+
- Build the project.
53+
- Upload the binary as a workflow artifact to allow interested parties to try it out without needing to build it
54+
themselves.
55+
- Run the project's [Golang](https://golang.org/) code tests.
56+
```

workflow-templates/test-go-task.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/test-go-task.md
2+
name: Test Go
3+
4+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
paths:
8+
- ".github/workflows/test-go-task.ya?ml"
9+
- "go.mod"
10+
- "go.sum"
11+
- "Taskfile.ya?ml"
12+
- "**.go"
13+
- "**/testdata/**"
14+
pull_request:
15+
paths:
16+
- ".github/workflows/test-go-task.ya?ml"
17+
- "go.mod"
18+
- "go.sum"
19+
- "Taskfile.ya?ml"
20+
- "**.go"
21+
- "**/testdata/**"
22+
workflow_dispatch:
23+
repository_dispatch:
24+
25+
jobs:
26+
build:
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v2
32+
33+
- name: Install Go
34+
uses: actions/setup-go@v2
35+
with:
36+
go-version: "1.14"
37+
38+
- name: Install Task
39+
uses: arduino/setup-task@v1
40+
with:
41+
repo-token: ${{ secrets.GITHUB_TOKEN }}
42+
version: 3.x
43+
44+
- name: Build application
45+
run: task go:build
46+
47+
# Allow interested parties to easily try the build
48+
- name: Save binary as workflow artifact
49+
uses: actions/upload-artifact@v2
50+
with:
51+
if-no-files-found: error
52+
# TODO: specify binary name here:
53+
path: BINARY_NAME
54+
name: BINARY_NAME
55+
56+
test:
57+
runs-on: ubuntu-latest
58+
59+
steps:
60+
- name: Checkout repository
61+
uses: actions/checkout@v2
62+
63+
- name: Install Go
64+
uses: actions/setup-go@v2
65+
with:
66+
go-version: "1.14"
67+
68+
- name: Install Task
69+
uses: arduino/setup-task@v1
70+
with:
71+
repo-token: ${{ secrets.GITHUB_TOKEN }}
72+
version: 3.x
73+
74+
- name: Run tests
75+
run: task go:test

0 commit comments

Comments
 (0)