Skip to content

Commit 0f89463

Browse files
committed
CI: Add test workflow (#38)
On every push and pull request that affects relevant files, run the project's Go code tests. * CI: Add test workflow * Disable code-coverage
1 parent 28d5428 commit 0f89463

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

.github/workflows/test-go-task.yml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/test-go-task.md
2+
name: Test Go
3+
4+
env:
5+
# See: https://github.com/actions/setup-go/tree/v2#readme
6+
GO_VERSION: "1.16"
7+
8+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
9+
on:
10+
create:
11+
push:
12+
paths:
13+
- ".github/workflows/test-go-task.ya?ml"
14+
- "codecov.ya?ml"
15+
- "**/go.mod"
16+
- "**/go.sum"
17+
- "Taskfile.ya?ml"
18+
- "**.go"
19+
- "**/testdata/**"
20+
pull_request:
21+
paths:
22+
- ".github/workflows/test-go-task.ya?ml"
23+
- "codecov.ya?ml"
24+
- "**/go.mod"
25+
- "**/go.sum"
26+
- "Taskfile.ya?ml"
27+
- "**.go"
28+
- "**/testdata/**"
29+
workflow_dispatch:
30+
repository_dispatch:
31+
32+
jobs:
33+
run-determination:
34+
runs-on: ubuntu-latest
35+
outputs:
36+
result: ${{ steps.determination.outputs.result }}
37+
steps:
38+
- name: Determine if the rest of the workflow should run
39+
id: determination
40+
run: |
41+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
42+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
43+
if [[ \
44+
"${{ github.event_name }}" != "create" || \
45+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \
46+
]]; then
47+
# Run the other jobs.
48+
RESULT="true"
49+
else
50+
# There is no need to run the other jobs.
51+
RESULT="false"
52+
fi
53+
54+
echo "::set-output name=result::$RESULT"
55+
56+
test:
57+
name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})
58+
needs: run-determination
59+
if: needs.run-determination.outputs.result == 'true'
60+
61+
strategy:
62+
fail-fast: false
63+
64+
matrix:
65+
operating-system:
66+
- ubuntu-latest
67+
- windows-latest
68+
- macos-latest
69+
module:
70+
# TODO: add paths of all Go modules here
71+
- path: ./
72+
codecov-flags: unit
73+
74+
runs-on: ${{ matrix.operating-system }}
75+
76+
steps:
77+
- name: Checkout repository
78+
uses: actions/checkout@v2
79+
80+
- name: Install Go
81+
uses: actions/setup-go@v2
82+
with:
83+
go-version: ${{ env.GO_VERSION }}
84+
85+
- name: Install Task
86+
uses: arduino/setup-task@v1
87+
with:
88+
repo-token: ${{ secrets.GITHUB_TOKEN }}
89+
version: 3.x
90+
91+
- name: Run tests
92+
env:
93+
GO_MODULE_PATH: ${{ matrix.module.path }}
94+
run: task go:test
95+
96+
# - name: Send unit tests coverage to Codecov
97+
# if: runner.os == 'Linux'
98+
# uses: codecov/codecov-action@v2
99+
# with:
100+
# file: ${{ matrix.module.path }}coverage_unit.txt
101+
# flags: ${{ matrix.module.codecov-flags }}
102+
# fail_ci_if_error: ${{ github.repository == 'arduino/arduino-cloud-cli' }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Compilation artifacts
22
arduino-cloud-cli
3+
arduino-cloud-cli.exe
34

45
# Configuration file
56
config.yaml

Taskfile.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# See: https://taskfile.dev/#/usage
2+
version: "3"
3+
4+
vars:
5+
# Path of the project's primary Go module:
6+
DEFAULT_GO_MODULE_PATH: ./
7+
DEFAULT_GO_PACKAGES:
8+
sh: |
9+
echo $(cd {{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}} && go list ./... | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
10+
# `-ldflags` flag to use for `go build` command
11+
# TODO: define flag if required by the project, or leave empty if not needed.
12+
LDFLAGS:
13+
# `-ldflags` flag to use for `go test` command
14+
# TODO: define flag if required by the project, or leave empty if not needed.
15+
TEST_LDFLAGS:
16+
17+
tasks:
18+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml
19+
go:build:
20+
desc: Build the Go code
21+
dir: "{{.DEFAULT_GO_MODULE_PATH}}"
22+
cmds:
23+
- go build -v {{.LDFLAGS}}
24+
25+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml
26+
go:test:
27+
desc: Run unit tests
28+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
29+
cmds:
30+
- |
31+
go test \
32+
-v \
33+
-short \
34+
-run '{{default ".*" .GO_TEST_REGEX}}' \
35+
{{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \
36+
-coverprofile=coverage_unit.txt \
37+
{{.TEST_LDFLAGS}} \
38+
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}

0 commit comments

Comments
 (0)