forked from vugu/vugu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yaml
156 lines (139 loc) · 7.5 KB
/
Taskfile.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Taskfile for 'vugu'
#
# The Taskfile builds vugu, runs all the tests and lints the source code.
version: '3'
# TODO: Warning this task file and the shell scripts it calls assume a Debian based Linux is the OS.
# The Taskfile will need to reworked to strip the Linux only shell cmds and port the taskfile to non-debian Linux/BSD
# as well as Windows and MacOS
tasks:
# Build everything, run all the tests (using go, tinygo and tinygo in docker) and lint the codebase
all:
preconditions:
- task: check-cmds-exist
cmds:
# Sanity check - display the version of task we are using
- task: print-taskfile-version
# Clean the autogenerated generated files from the wasm-test-suite
- task: clean-auto-generated-files
# build first as this will catch any syntax/Go compiler errors
- task: build
# Pull the lastest golangci-lint docker image
- task: pull-latest-golangci-lint-docker-image
# Lint using the dockerized golangci-lint
- task: lint-via-docker
# Run the vugu test suite using the Go (but not tinygo?)
- task: test
# Pull the latest tinygo docker image
- task: pull-latest-tinygo-docker-image
# Run the wasm test suites against Go, a local tinygo compiler and a dockerized tinygo compiler.
# Warning: the tinygo builds take significantly longer to build and run.
- task: test-wasm
# Check that the (linux) tools we rely on are present.
# We will need to change these to check for he platform specific equivalents.
check-cmds-exist:
preconditions:
- sh: command -v find
msg: "find command not found."
- sh: command -v grep
msg: "grep command not found."
- sh: command -v rm
msg: "rm command not found."
# Print the version of taskfile we are using
# The github action based workflow will always download the latest task command release so we need to know which version that was in case
# a taskfile works locally but not on the Github Action Runner due to a difference in the task version.
print-taskfile-version:
cmds:
- task --version
# Remove all of the auto-generated files from the wasm-test-suite
clean-auto-generated-files:
# both the 'find' and 'rm' commands are prerequisites
preconditions:
- task: check-cmds-exist
cmds:
# remove anything with a "_gen.go" suffix from the We expect these file to be rebuilt as part of the build.
- find ./wasm-test-suite -type f -name "*_gen.go" -exec rm {} \;
# Build the vugu packages and the vugugen and vugufmt commands
# Explicitly run the generate command in the vgform package so that the auto-generated code can be linted
build:
cmds:
# note we now use the full package names
# build and install the vugu package
- go install github.com/vugu/vugu
# build and install the vugugen command
- go install github.com/vugu/vugu/cmd/vugugen
# build and install the vugufmt command
- go install github.com/vugu/vugu/cmd/vugufmt
# we have to run go generate in the vgform package
- go generate github.com/vugu/vugu/vgform # go generate calls vugugen
# Pull/Download the latest golangci-lint docker image. We use this image in the "lint-via-docker" task below
pull-latest-golangci-lint-docker-image:
preconditions:
- task: check-cmds-exist
cmds:
- docker pull golangci/golangci-lint:latest-alpine
# Run the dockerized golangci-lint linter
lint-via-docker:
preconditions:
- task: check-cmds-exist
cmds:
- docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run -v
# Run all of the tests - except the wasm-test-suite. The wasm-test-suite currently takes circa 35 minutes to execute.
# Some of the tests (e.g. in the devutil package) are built using tinygo in a dockerized container.
# The tests will pull the container
# as required at teh latest version.
test:
# it's a precondition is that tinygo is available
preconditions:
- task: check-cmds-exist
cmds:
# Display the packages we are going to tun tests in.
# This can be useful because we don't know the list until th test run completes. This list also gives the order the packages will be tested in.
- echo The tests in the following packages will be run
- go list ./... | grep -v wasm-test-suite
# run all of the tests EXCEPT the wasm-test-suite (we use go list ./... to list all the packages and then ignore wasm-test-suite via the "-v" in the grep)
- go test -v `go list ./... | grep -v wasm-test-suite`
# Download and install the latest version of the tinygo compiler locally.
pull-latest-tinygo-docker-image:
preconditions:
- task: check-cmds-exist
cmds:
# CRITICAL - this MUST be the same docker image as specified by DefaultTinygoDockerImage in devutil/tinygo-compiler.go
# This change makes the pull of the docker container explicit as part of the build process instead of being implicit as part of the test run.
# The 'docker run ...' that runs the container in the wasm-test-suite tests will now find the correct container locally.
# This is s temporary situation pending the wasm-test-suite being refactored.
- docker pull tinygo/tinygo:latest
# Run just the wasm-test-suite tests. This can take up to 35 minutes to complete.
# The wasm-test suite builds all of the tests three times - once using Go, once using a local tinygo and once using tinygo installed in a docker container
# Therefore docker is a prerequisite to run these tests along with tinygo.
# The docker container that is started is named `wasm-test-suite`. It will be stopped once the tests are complete.
# The tests are servered by a small Go http server - the wasm-test-suite-srv executeable. This is build prior to the tests being run. It is installed in the
# 'wasm-test-suite' container
test-wasm:
dir:
# This task must be executed from the local "wasm-test-suite/docker" directory. The contents of the Dockerfile rely on this.
# The 'wasm-test-suite-srv' executable will be put into the "wasm-test-suite/docker" directory.
./wasm-test-suite/docker
# the precondition is docker and tinygo are both available
preconditions:
- sh: command -v docker
msg: "docker not found. Please see https://docs.docker.com/desktop/ for how to install locally"
cmds:
# build the wasm-test-suite-srv. Note we build via the package name.
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./wasm-test-suite-srv github.com/vugu/vugu/wasm-test-suite/docker
# docker build and tag our image
- docker build -t vugu/wasm-test-suite:latest .
# we want to ignore any failures e.g. the wasm-test-suite container wasn't running so we have to use "cmd:" to be explicit which error
# we want to ignore.
- cmd: 'docker stop wasm-test-suite'
ignore_error: true
# ditto, be explit so it's clear we are ignoring any 'docker rm' error
- cmd: 'docker rm wasm-test-suite'
ignore_error: true
# start the container
- docker run -d -t -p 9222:9222 -p 8846:8846 --name wasm-test-suite vugu/wasm-test-suite:latest
# stop the container and cleanup once the task is complete
- defer: docker stop wasm-test-suite
# run the tests
# set the timeout for 35 minutes, as the tests can timeout between 20 and 35 minutes depending on the hardware
# and enable verbose output otherwise it looks like this hangs.
- go test -v -timeout=35m github.com/vugu/vugu/wasm-test-suite