Skip to content

Commit

Permalink
Add GitHub actions
Browse files Browse the repository at this point in the history
Take inspiration from the workflows used in gohci and bootstrap but
disable many checks because it's going to take a while to fix them all.

Update go generate to make it work without prerequisites preinstalled.

Remove the corresponding checks from .travis.yml. There are still checks
that haven't been transitioned, this will be done in a follow up.
  • Loading branch information
maruel committed May 25, 2020
1 parent dd85de5 commit 229d90f
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 35 deletions.
234 changes: 234 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
# Copyright 2020 The Periph Authors. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.

# References:
# https://developer.github.com/webhooks/event-payloads/
# https://github.com/actions/cache
# https://github.com/actions/checkout
# https://github.com/actions/setup-go
# https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#using-the-github_token-in-a-workflow
# https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions/
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions

on: [push, pull_request]
name: Run tests
jobs:
test_all:
env:
# TODO(maruel): Unnecessary with v4.
GOPATH: ${{github.workspace}}
continue-on-error: true
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
gover: ['1.14.3']
runs-on: "${{matrix.os}}"
name: "go${{matrix.gover}} on ${{matrix.os}}"
steps:
- uses: actions/setup-go@v2
with:
go-version: "^${{matrix.gover}}"
- name: 'Cache: pkg/mod'
uses: actions/cache@v1
with:
path: "pkg/mod"
# We want a key that helps with keeping the tools.
key: "${{runner.os}}-gopkg-${{hashFiles('pkg/mod/**/go.sum')}}"
restore-keys: "${{runner.os}}-gopkg-"

# Fetch the tools before checking out, so they don't modify go.mod/go.sum.
- name: 'go get necessary tools'
run: >
go get -u
github.com/gordonklaus/ineffassign
golang.org/x/lint/golint
golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
honnef.co/go/tools/cmd/staticcheck
- name: 'go get necessary tools (ubuntu)'
if: always() && matrix.os == 'ubuntu-latest'
# TODO(maruel): Use upstream google/addlicense once upstream is fixed to
# ignore generated files.
run: >
go get -u
github.com/client9/misspell/cmd/misspell
github.com/maruel/addlicense
# Checkout and print debugging information.
- uses: actions/checkout@v2
# TODO(maruel): Unnecessary with v4.
with:
path: src/periph.io/x/periph
- name: "Debug (posix)"
if: always() && matrix.os != 'windows-latest'
run: |
echo GOPATH = $GOPATH
echo GOROOT = $GOROOT
echo HOME = $HOME
echo GITHUB_WORKSPACE = $GITHUB_WORKSPACE
echo PATH = $PATH
echo ""
echo pwd = $(pwd)
echo $ ls -la
ls -la
echo ""
echo $ ls -la $HOME
ls -la $HOME
echo ""
echo $ ls -la $GOPATH
ls -la $GOPATH
echo ""
echo $ ls -la $GOPATH/bin
ls -la $GOPATH/bin
- name: "Debug (windows)"
if: always() && matrix.os == 'windows-latest'
shell: cmd
run: |
echo GOPATH = %GOPATH%
echo GOROOT = %GOROOT%
echo USERPROFILE = %USERPROFILE%
echo GITHUB_WORKSPACE = %GITHUB_WORKSPACE%
echo PATH = %PATH%
echo cd = %CD%
dir /a
dir /a %GOPATH%
dir /a %GOPATH%\bin
# Now run proper checks.
- name: 'Check: go vet (disabled)'
# TODO(maruel): Enable back.
if: false
run: go vet ./...
- name: 'Check: go vet shadow; shadowed variables (posix) (disabled)'
# TODO(maruel): Enable back.
if: false && matrix.os != 'windows-latest'
run: go vet -vettool=$(which shadow) ./...
- name: 'Check: go vet shadow; shadowed variables (windows) (disabled)'
# TODO(maruel): Enable back.
if: false && matrix.os == 'windows-latest'
shell: cmd
run: go vet -vettool=%USERPROFILE%/go/bin/shadow.exe ./...
- name: 'Check: golint (disabled)'
# TODO(maruel): Enable back.
if: false
run: golint -set_exit_status ./...
- name: 'Check: inefficient variable assignment'
if: always()
# TODO(maruel): cd is unnecessary with v4.
run: |
cd src/periph.io/x/periph
ineffassign .
- name: 'Check: staticcheck'
# TODO(maruel): Enable more checks.
# TODO(maruel): cd is unnecessary with v4.
run: |
cd src/periph.io/x/periph
staticcheck -checks all,-U1000,-ST1003,-SA5002,-SA1019 ./...
# The following checks are not dependent on the OS or go build tags. Only
# run them on ubuntu-latest since it's the fastest one.
- name: 'Check: no executable was committed (ubuntu)'
if: always() && matrix.os == 'ubuntu-latest'
# TODO(maruel): cd is unnecessary with v4.
run: |
cd src/periph.io/x/periph
if find . -path ./.git -prune -o -type f -executable -print | grep -e . ; then
echo 'Do not commit executables'
false
fi
- name: 'Check: gofmt; code is well formatted (ubuntu)'
if: always() && matrix.os == 'ubuntu-latest'
# TODO(maruel): cd is unnecessary with v4.
run: |
cd src/periph.io/x/periph
FILES=$(gofmt -s -l .)
if ! test -z "$FILES"; then
echo 'Please run `gofmt -s -w` on the following files:' >> _gofmt.txt
echo "" >> _gofmt.txt
for FILE in ${FILES}; do
echo "- ${FILE}" >> _gofmt.txt
done
cat _gofmt.txt
echo "## ⚠ gofmt Failed" >> _comments.txt
echo "" >> _comments.txt
cat _gofmt.txt >> _comments.txt
echo "" >> _comments.txt
false
fi
- name: 'Check: addlicense; all sources have a license header (ubuntu)'
if: always() && matrix.os == 'ubuntu-latest'
# TODO(maruel): cd is unnecessary with v4.
run: |
cd src/periph.io/x/periph
addlicense -check .
- name: "Check: misspelling; code doesn't contain misspelling (ubuntu)"
if: always() && matrix.os == 'ubuntu-latest'
# TODO(maruel): cd is unnecessary with v4.
run: |
cd src/periph.io/x/periph
ERR=$(misspell .)
if ! test -z "$ERR"; then
echo "$ERR"
echo "## ⚠ misspell Failed" >> _comments.txt
echo "" >> _comments.txt
echo "$ERR" >> _comments.txt
echo "" >> _comments.txt
false
fi
# Run tests last since it's potentially the slowest step.
- name: 'Check: go test -cover (posix)'
if: always() && matrix.os != 'windows-latest'
# TODO(maruel): cd is unnecessary with v4.
run: |
cd src/periph.io/x/periph
go test -covermode=count -coverprofile=coverage.txt ./...
- name: 'Check: go test -cover (windows)'
if: always() && matrix.os == 'windows-latest'
# Powershell messes things up.
shell: cmd
# TODO(maruel): cd is unnecessary with v4.
run: |
cd src\periph.io\x\periph
go test -covermode=count -coverprofile=coverage.txt ./...
# Don't send code coverage if anything failed to reduce spam.
- uses: codecov/codecov-action@v1
- name: 'Cleanup'
run: rm src/periph.io/x/periph/coverage.txt
# Don't run go test -race if anything failed, to speed up the results.
- name: 'Check: go test -race'
# TODO(maruel): cd is unnecessary with v4.
run: |
cd src/periph.io/x/periph
go test -race ./...
- name: "Check: go generate doesn't modify files (posix)"
# TODO(maruel): Find a way to enable this check on Windows.
if: matrix.os != 'windows-latest'
# TODO(maruel): cd is unnecessary with v4.
run: |
cd src/periph.io/x/periph
go generate ./...
TOUCHED=$(git status --porcelain --ignored)
if ! test -z "$TOUCHED"; then
echo "go generate modified these files, please update:"
echo "$TOUCHED"
git diff
false
fi
- name: 'Send comments (posix)'
if: failure() && matrix.os != 'windows-latest' && github.event_name == 'pull_request'
# TODO(maruel): cd is unnecessary with v4.
run: |
cd src/periph.io/x/periph
if [ -f _comments.txt ]; then
URL=$(cat ${GITHUB_EVENT_PATH} | jq -r .pull_request.comments_url)
echo "Sending $(cat _comments.txt|wc -l) lines of comments to ${URL}"
PAYLOAD=$(echo '{}' | jq --arg body "$(cat _comments.txt)" '.body = $body')
curl -sS --request POST \
--header "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" \
--header "Content-Type: application/json" \
--data "${PAYLOAD}" "${URL}" > /dev/null
fi
29 changes: 0 additions & 29 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,14 @@ jobs:
directories:
- $GOPATH/pkg/mod
# Cache tools sources.
#- $GOPATH/src/github\.com/client9
#- $GOPATH/src/github\.com/google/addlicense
#- $GOPATH/src/github\.com/gordonklaus
#- $GOPATH/src/golang\.org
before_script:
- echo $TRAVIS_GO_VERSION
- go get -t -v periph.io/x/periph/...
- >
go get -u -v
github.com/client9/misspell/cmd/misspell
github.com/google/addlicense
github.com/gordonklaus/ineffassign
golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
script:
- >
echo 'Check Code is well formatted';
! gofmt -s -d . | read
- >
echo 'Looking for external dependencies:';
go list -f '{{join .Imports "\n"}}' periph.io/x/periph/... | sort | uniq | grep -v ^periph.io/x/periph | xargs go list -f '{{if not .Standard}}- {{.ImportPath}}{{end}}'
Expand All @@ -46,32 +37,12 @@ jobs:
- >
echo 'Erroring on /conn depending on /host:';
! go list -f '{{.ImportPath}} depends on {{join .Imports ", "}}' periph.io/x/periph/conn/... | sort | uniq | grep periph.io/x/periph/host
- >
echo 'Erroring on misspelling';
! misspell . | grep a
- >
echo 'Erroring on inefficient variable assignment:';
ineffassign .
- >
echo 'Erroring on go vet:';
go vet ./...
- >
echo 'Erroring on shadowed variables:';
! go vet -vettool=$(which shadow) ./... |& grep -v '"err"' | grep -e '^[^#]'
- >
echo 'Running tests with code coverage:';
go test -covermode=count -coverprofile=coverage.txt ./...
- >
echo 'Running tests with race detector:';
go test -race ./...
- >
echo 'Erroring if an executable was committed:';
if find . -path ./.git -prune -o -type f -executable -print | grep -e . ; then echo 'Do not commit executables'; false; fi
- >
echo 'Erroring if a license header is missing:';
! addlicense -check . | grep -v '\(cmd/ssd1306/font7x13.go\|conn/duplex_string.go\|devices/lepton/cci/strings_gen.go\|experimental/cmd/periph-web/static/index.html\|experimental/cmd/periph-web/static_prod.go\)' | read
after_success:
- bash <(curl -s https://codecov.io/bash)
- go: 1.7.6
before_script:
Expand Down
2 changes: 1 addition & 1 deletion cmd/ssd1306/font7x13.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/ssd1306/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"periph.io/x/periph/devices/ssd1306/image1bit"
)

var text = `// generated by go generate; DO NOT EDIT.
var text = `// Code generated by "go run gen.go"; DO NOT EDIT.
package main
Expand Down
1 change: 1 addition & 0 deletions cmd/ssd1306/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

//go:generate go get golang.org/x/image/font golang.org/x/image/font/basicfont golang.org/x/image/math/fixed
//go:generate go run gen.go

// ssd1306 writes to a display driven by a ssd1306 controler.
Expand Down
3 changes: 0 additions & 3 deletions conn/duplex_string.go

This file was deleted.

2 changes: 1 addition & 1 deletion devices/lepton/cci/cci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

// "stringer" can be installed with "go get golang.org/x/tools/cmd/stringer"
//go:generate go get golang.org/x/tools/cmd/stringer
//go:generate stringer -output=strings_gen.go -type=CameraStatus,command,FFCShutterMode,FFCState,ShutterPos,ShutterTempLockoutState

package cci
Expand Down
5 changes: 5 additions & 0 deletions experimental/cmd/periph-web/static/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<!DOCTYPE html>
<!--
Copyright 2020 The Periph Authors. All rights reserved.
Use of this source code is governed under the Apache License, Version 2.0
that can be found in the LICENSE file.
-->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand Down
1 change: 1 addition & 0 deletions experimental/cmd/periph-web/web_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

//go:generate go get github.com/tdewolff/minify/cmd/minify
//go:generate go run internal/static_gen.go -o static_prod.go

package main
Expand Down

0 comments on commit 229d90f

Please sign in to comment.