Skip to content

CI: add test workflow #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: test

on:
pull_request:

jobs:
test-matrix:
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]

runs-on: ${{ matrix.operating-system }}

steps:
- name: Disable EOL conversions
run: git config --global core.autocrlf false

- name: Checkout
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "1.14"

- name: Install Dependencies (Linux)
# run: sudo apt-get install ninja-build
run: sudo apt update && sudo apt install -y --no-install-recommends build-essential libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev
if: matrix.operating-system == 'ubuntu-latest'

- name: Install Go deps
# Since 10/23/2019 pwsh is the default shell
# on Windows, but pwsh fails to install protoc-gen-go so
# we force bash as default shell for all OSes in this task
run: |
go get github.com/golangci/govet
go get golang.org/x/lint/golint
shell: bash

- name: Install Taskfile
uses: Arduino/actions/setup-taskfile@master
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check the code is good
run: task check

- name: Build the Agent
run: task build

- name: Run unit tests
run: task test-unit

# - name: Send unit tests coverage to Codecov
# if: >
# matrix.operating-system == 'ubuntu-latest' &&
# github.event_name == 'push'
# uses: codecov/codecov-action@v1
# with:
# file: ./coverage_unit.txt
# flags: unit

# - name: Send legacy tests coverage to Codecov
# if: >
# matrix.operating-system == 'ubuntu-latest' &&
# github.event_name == 'push'
# uses: codecov/codecov-action@v1
# with:
# file: ./coverage_legacy.txt
# flags: unit

# - name: Send integration tests coverage to Codecov
# if: >
# matrix.operating-system == 'ubuntu-latest' &&
# github.event_name == 'push'
# uses: codecov/codecov-action@v1
# with:
# file: ./coverage_integ.txt
# flags: integ
61 changes: 61 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
version: "2"

tasks:

build:
desc: Build the project
cmds:
- go build -v -i {{.LDFLAGS}}

test:
desc: Run the full testsuite, `legacy` will be skipped
cmds:
- task: test-unit

test-unit:
desc: Run unit tests only
cmds:
- go test -short -run '{{ default ".*" .TEST_REGEX }}' {{ default "-v" .GOFLAGS }} -coverprofile=coverage_unit.txt {{ default .DEFAULT_TARGETS .TARGETS }} {{.TEST_LDFLAGS}}

check:
desc: Check fmt and lint
cmds:
- go version
- go fmt {{ default .DEFAULT_TARGETS .TARGETS }}
- test -z $(go fmt {{ default .DEFAULT_TARGETS .TARGETS }})
- echo 'test ok'
- go vet {{ default .DEFAULT_TARGETS .TARGETS }}
- echo 'vet ok'
# FIXME: too many suggestions are failing the check, I'll fix these one in
# another PR.
# - "'{{.GOLINTBIN}}' {{.GOLINTFLAGS}} {{ default .DEFAULT_TARGETS .TARGETS }}"
# - task: i18n:check
# - task: python:check
# - task: docs:check
# - task: config:check

vars:
# all modules of this project except for "gen/..." module
DEFAULT_TARGETS:
sh: echo `go list ./... | grep -v 'arduino-create-agent/gen/' | tr '\n' ' '`
# build vars
COMMIT:
sh: echo ${TRAVIS_COMMIT:-`git log -n 1 --format=%h`}
LDFLAGS: >
-ldflags '-X github.com/arduino/arduino-create-agent/version.commit={{.COMMIT}}'
# test vars
GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic"
TEST_VERSIONSTRING: "0.0.0-test.preview"
TEST_COMMIT: "deadbeef"
TEST_LDFLAGS: >
-ldflags '-X github.com/arduino/arduino-create-agent/version.versionString={{.TEST_VERSIONSTRING}}
-X github.com/arduino/arduino-create-agent/version.commit={{.TEST_COMMIT}}'
# check-lint vars
GOLINTBIN:
sh: go list -f {{"{{"}}".Target{{"}}"}}" golang.org/x/lint/golint
GOLINTFLAGS: "-min_confidence 0.8 -set_exit_status"
# # docs versioning
# DOCS_VERSION: dev
# DOCS_ALIAS: ""
# DOCS_REMOTE: "origin"
PRETTIER: [email protected]
Loading