Skip to content

Commit cba46f8

Browse files
authoredNov 23, 2021
Merge pull request #87 from arduino/gh-workflows
Added gh-action workflows and build tasks
2 parents 68ebb5d + 0d660a6 commit cba46f8

File tree

3 files changed

+701
-0
lines changed

3 files changed

+701
-0
lines changed
 

‎.github/workflows/release-go-task.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/release-go-task.md
2+
name: Release
3+
4+
env:
5+
# As defined by the Taskfile's PROJECT_NAME variable
6+
PROJECT_NAME: arduino-language-server
7+
# As defined by the Taskfile's DIST_DIR variable
8+
DIST_DIR: dist
9+
# The project's folder on Arduino's download server for uploading builds
10+
AWS_PLUGIN_TARGET: /arduino-language-server/
11+
ARTIFACT_NAME: dist
12+
13+
on:
14+
push:
15+
tags:
16+
- "[0-9]+.[0-9]+.[0-9]+*"
17+
18+
jobs:
19+
create-release-artifacts:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v2
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Create changelog
29+
uses: arduino/create-changelog@v1
30+
with:
31+
tag-regex: '^[0-9]+\.[0-9]+\.[0-9]+.*$'
32+
filter-regex: '^\[(skip|changelog)[ ,-](skip|changelog)\].*'
33+
case-insensitive-regex: true
34+
changelog-file-path: "${{ env.DIST_DIR }}/CHANGELOG.md"
35+
36+
- name: Install Task
37+
uses: arduino/setup-task@v1
38+
with:
39+
repo-token: ${{ secrets.GITHUB_TOKEN }}
40+
version: 3.x
41+
42+
- name: Build
43+
run: task dist:all
44+
45+
- name: Upload artifacts
46+
uses: actions/upload-artifact@v2
47+
with:
48+
if-no-files-found: error
49+
name: ${{ env.ARTIFACT_NAME }}
50+
path: ${{ env.DIST_DIR }}
51+
52+
create-release:
53+
runs-on: ubuntu-latest
54+
55+
steps:
56+
- name: Download artifact
57+
uses: actions/download-artifact@v2
58+
with:
59+
name: ${{ env.ARTIFACT_NAME }}
60+
path: ${{ env.DIST_DIR }}
61+
62+
- name: Identify Prerelease
63+
# This is a workaround while waiting for create-release action
64+
# to implement auto pre-release based on tag
65+
id: prerelease
66+
run: |
67+
wget -q -P /tmp https://github.com/fsaintjacques/semver-tool/archive/3.0.0.zip
68+
unzip -p /tmp/3.0.0.zip semver-tool-3.0.0/src/semver >/tmp/semver && chmod +x /tmp/semver
69+
if [[ "$(/tmp/semver get prerel "${GITHUB_REF/refs\/tags\//}")" ]]; then echo "::set-output name=IS_PRE::true"; fi
70+
71+
- name: Create Github Release and upload artifacts
72+
uses: ncipollo/release-action@v1
73+
with:
74+
token: ${{ secrets.GITHUB_TOKEN }}
75+
bodyFile: ${{ env.DIST_DIR }}/CHANGELOG.md
76+
draft: false
77+
prerelease: ${{ steps.prerelease.outputs.IS_PRE }}
78+
# NOTE: "Artifact is a directory" warnings are expected and don't indicate a problem
79+
# (all the files we need are in the DIST_DIR root)
80+
artifacts: ${{ env.DIST_DIR }}/*
81+
82+
- name: Upload release files on Arduino downloads servers
83+
uses: docker://plugins/s3
84+
env:
85+
PLUGIN_SOURCE: "${{ env.DIST_DIR }}/*"
86+
PLUGIN_TARGET: ${{ env.AWS_PLUGIN_TARGET }}
87+
PLUGIN_STRIP_PREFIX: "${{ env.DIST_DIR }}/"
88+
PLUGIN_BUCKET: ${{ secrets.DOWNLOADS_BUCKET }}
89+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
90+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

‎DistTasks.yml

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/release-go-task/DistTasks.yml
2+
version: "3"
3+
4+
# This taskfile is ideally meant to be project agnostic and could be dropped in
5+
# on other Go projects with minimal or no changes.
6+
#
7+
# To use it simply add the following lines to your main taskfile:
8+
# includes:
9+
# dist: ./DistTasks.yml
10+
#
11+
# The following variables must be declared in the including taskfile for the
12+
# build process to work correctly:
13+
# * DIST_DIR: the folder that will contain the final binaries and packages
14+
# * PROJECT_NAME: the name of the project, used in package name
15+
# * VERSION: the version of the project, used in package name and checksum file
16+
# * LD_FLAGS: flags used at build time
17+
#
18+
# The project MUST contain a LICENSE.txt file in the root folder or packaging will fail.
19+
20+
vars:
21+
CONTAINER: "docker.elastic.co/beats-dev/golang-crossbuild"
22+
GO_VERSION: "1.16.4"
23+
CHECKSUM_FILE: "{{.VERSION}}-checksums.txt"
24+
25+
tasks:
26+
all:
27+
desc: Build for distribution for all platforms
28+
cmds:
29+
- task: Windows_32bit
30+
- task: Windows_64bit
31+
- task: Linux_32bit
32+
- task: Linux_64bit
33+
- task: Linux_ARMv6
34+
- task: Linux_ARMv7
35+
- task: Linux_ARM64
36+
- task: macOS_64bit
37+
38+
Windows_32bit:
39+
desc: Builds Windows 32 bit binaries
40+
dir: "{{.DIST_DIR}}"
41+
cmds:
42+
- |
43+
docker run -v `pwd`/..:/home/build -w /home/build \
44+
-e CGO_ENABLED=1 \
45+
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
46+
--build-cmd "{{.BUILD_COMMAND}}" \
47+
-p "{{.BUILD_PLATFORM}}"
48+
49+
zip {{.PACKAGE_NAME}} {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe ../LICENSE.txt -j
50+
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
51+
52+
vars:
53+
PLATFORM_DIR: "{{.PROJECT_NAME}}_windows_386"
54+
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe {{.LDFLAGS}}"
55+
BUILD_PLATFORM: "windows/386"
56+
CONTAINER_TAG: "{{.GO_VERSION}}-main"
57+
PACKAGE_PLATFORM: "Windows_32bit"
58+
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.zip"
59+
60+
Windows_64bit:
61+
desc: Builds Windows 64 bit binaries
62+
dir: "{{.DIST_DIR}}"
63+
cmds:
64+
- |
65+
docker run -v `pwd`/..:/home/build -w /home/build \
66+
-e CGO_ENABLED=1 \
67+
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
68+
--build-cmd "{{.BUILD_COMMAND}}" \
69+
-p "{{.BUILD_PLATFORM}}"
70+
71+
zip {{.PACKAGE_NAME}} {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe ../LICENSE.txt -j
72+
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
73+
74+
vars:
75+
PLATFORM_DIR: "{{.PROJECT_NAME}}_windows_amd64"
76+
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe {{.LDFLAGS}}"
77+
BUILD_PLATFORM: "windows/amd64"
78+
CONTAINER_TAG: "{{.GO_VERSION}}-main"
79+
PACKAGE_PLATFORM: "Windows_64bit"
80+
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.zip"
81+
82+
Linux_32bit:
83+
desc: Builds Linux 32 bit binaries
84+
dir: "{{.DIST_DIR}}"
85+
cmds:
86+
- |
87+
docker run -v `pwd`/..:/home/build -w /home/build \
88+
-e CGO_ENABLED=1 \
89+
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
90+
--build-cmd "{{.BUILD_COMMAND}}" \
91+
-p "{{.BUILD_PLATFORM}}"
92+
93+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
94+
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
95+
96+
vars:
97+
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_amd32"
98+
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}"
99+
BUILD_PLATFORM: "linux/386"
100+
CONTAINER_TAG: "{{.GO_VERSION}}-main"
101+
PACKAGE_PLATFORM: "Linux_32bit"
102+
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
103+
104+
Linux_64bit:
105+
desc: Builds Linux 64 bit binaries
106+
dir: "{{.DIST_DIR}}"
107+
cmds:
108+
- |
109+
docker run -v `pwd`/..:/home/build -w /home/build \
110+
-e CGO_ENABLED=1 \
111+
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
112+
--build-cmd "{{.BUILD_COMMAND}}" \
113+
-p "{{.BUILD_PLATFORM}}"
114+
115+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
116+
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
117+
118+
vars:
119+
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_amd64"
120+
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}"
121+
BUILD_PLATFORM: "linux/amd64"
122+
CONTAINER_TAG: "{{.GO_VERSION}}-main"
123+
PACKAGE_PLATFORM: "Linux_64bit"
124+
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
125+
126+
Linux_ARMv7:
127+
desc: Builds Linux ARMv7 binaries
128+
dir: "{{.DIST_DIR}}"
129+
cmds:
130+
- |
131+
docker run -v `pwd`/..:/home/build -w /home/build \
132+
-e CGO_ENABLED=1 \
133+
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
134+
--build-cmd "{{.BUILD_COMMAND}}" \
135+
-p "{{.BUILD_PLATFORM}}"
136+
137+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
138+
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
139+
140+
vars:
141+
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_arm_7"
142+
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}"
143+
BUILD_PLATFORM: "linux/armv7"
144+
CONTAINER_TAG: "{{.GO_VERSION}}-armhf"
145+
PACKAGE_PLATFORM: "Linux_ARMv7"
146+
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
147+
148+
Linux_ARMv6:
149+
desc: Builds Linux ARMv6 binaries
150+
dir: "{{.DIST_DIR}}"
151+
cmds:
152+
- |
153+
docker run -v `pwd`/..:/home/build -w /home/build \
154+
-e CGO_ENABLED=1 \
155+
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
156+
--build-cmd "{{.BUILD_COMMAND}}" \
157+
-p "{{.BUILD_PLATFORM}}"
158+
159+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
160+
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
161+
162+
vars:
163+
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_arm_6"
164+
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}"
165+
BUILD_PLATFORM: "linux/armv6"
166+
# We are experiencing the following error with ARMv6 build:
167+
#
168+
# # github.com/arduino/arduino-cli
169+
# net(.text): unexpected relocation type 296 (R_ARM_V4BX)
170+
# panic: runtime error: invalid memory address or nil pointer dereference
171+
# [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x51ae53]
172+
#
173+
# goroutine 1 [running]:
174+
# cmd/link/internal/loader.(*Loader).SymName(0xc000095c00, 0x0, 0xc0000958d8, 0x5a0ac)
175+
# /usr/local/go/src/cmd/link/internal/loader/loader.go:684 +0x53
176+
# cmd/link/internal/ld.dynrelocsym2(0xc000095880, 0x5a0ac)
177+
# /usr/local/go/src/cmd/link/internal/ld/data.go:777 +0x295
178+
# cmd/link/internal/ld.(*dodataState).dynreloc2(0xc007df9800, 0xc000095880)
179+
# /usr/local/go/src/cmd/link/internal/ld/data.go:794 +0x89
180+
# cmd/link/internal/ld.(*Link).dodata2(0xc000095880, 0xc007d00000, 0x60518, 0x60518)
181+
# /usr/local/go/src/cmd/link/internal/ld/data.go:1434 +0x4d4
182+
# cmd/link/internal/ld.Main(0x8729a0, 0x4, 0x8, 0x1, 0xd, 0xe, 0x0, 0x0, 0x6d7737, 0x12, ...)
183+
# /usr/local/go/src/cmd/link/internal/ld/main.go:302 +0x123a
184+
# main.main()
185+
# /usr/local/go/src/cmd/link/main.go:68 +0x1dc
186+
# Error: failed building for linux/armv6: exit status 2
187+
#
188+
# This seems to be a problem in the go builder 1.16.x that removed support for the R_ARM_V4BX instruction:
189+
# https://github.com/golang/go/pull/44998
190+
# https://groups.google.com/g/golang-codereviews/c/yzN80xxwu2E
191+
#
192+
# Until there is a fix released we must use a recent gcc for Linux_ARMv6 build, so for this
193+
# build we select the debian10 based container.
194+
CONTAINER_TAG: "{{.GO_VERSION}}-armel-debian10"
195+
PACKAGE_PLATFORM: "Linux_ARMv6"
196+
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
197+
198+
Linux_ARM64:
199+
desc: Builds Linux ARM64 binaries
200+
dir: "{{.DIST_DIR}}"
201+
cmds:
202+
- |
203+
docker run -v `pwd`/..:/home/build -w /home/build \
204+
-e CGO_ENABLED=1 \
205+
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
206+
--build-cmd "{{.BUILD_COMMAND}}" \
207+
-p "{{.BUILD_PLATFORM}}"
208+
209+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
210+
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
211+
212+
vars:
213+
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_arm_6"
214+
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}"
215+
BUILD_PLATFORM: "linux/arm64"
216+
CONTAINER_TAG: "{{.GO_VERSION}}-arm"
217+
PACKAGE_PLATFORM: "Linux_ARM64"
218+
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
219+
220+
macOS_64bit:
221+
desc: Builds Mac OS X 64 bit binaries
222+
dir: "{{.DIST_DIR}}"
223+
cmds:
224+
- |
225+
docker run -v `pwd`/..:/home/build -w /home/build \
226+
-e CGO_ENABLED=1 \
227+
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
228+
--build-cmd "{{.BUILD_COMMAND}}" \
229+
-p "{{.BUILD_PLATFORM}}"
230+
231+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
232+
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
233+
234+
vars:
235+
PLATFORM_DIR: "{{.PROJECT_NAME}}_osx_darwin_amd64"
236+
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}"
237+
BUILD_PLATFORM: "darwin/amd64"
238+
# We are experiencing the following error with macOS_64bit build:
239+
#
240+
# Undefined symbols for architecture x86_64:
241+
# "_clock_gettime", referenced from:
242+
# _runtime.walltime_trampoline in go.o
243+
# ld: symbol(s) not found for architecture x86_64
244+
# clang: error: linker command failed with exit code 1 (use -v to see invocation)
245+
#
246+
# The reason seems that go 1.16.x use a macos API which is available since 10.12
247+
# https://github.com/techknowlogick/xgo/issues/100#issuecomment-780894190
248+
#
249+
# To compile it we need an SDK >=10.12 so we use the debian10 based container that
250+
# has the SDK 10.14 installed.
251+
CONTAINER_TAG: "{{.GO_VERSION}}-darwin-debian10"
252+
PACKAGE_PLATFORM: "macOS_64bit"
253+
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"

‎Taskfile.yml

Lines changed: 358 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,358 @@
1+
version: "3"
2+
3+
includes:
4+
dist: ./DistTasks.yml
5+
6+
tasks:
7+
docs:generate:
8+
desc: Create all generated documentation content
9+
deps:
10+
- task: go:cli-docs
11+
- task: protoc:docs
12+
cmds:
13+
- task: general:format-prettier
14+
15+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies-task/Taskfile.yml
16+
general:cache-dep-licenses:
17+
desc: Cache dependency license metadata
18+
cmds:
19+
- |
20+
if ! which licensed &>/dev/null; then
21+
if [[ {{OS}} == "windows" ]]; then
22+
echo "Licensed does not have Windows support."
23+
echo "Please use Linux/macOS or download the dependencies cache from the GitHub Actions workflow artifact."
24+
else
25+
echo "licensed not found or not in PATH. Please install: https://github.com/github/licensed#as-an-executable"
26+
fi
27+
exit 1
28+
fi
29+
- licensed cache
30+
31+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies-task/Taskfile.yml
32+
general:check-dep-licenses:
33+
desc: Check for unapproved dependency licenses
34+
deps:
35+
- task: general:cache-dep-licenses
36+
cmds:
37+
- licensed status
38+
39+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml
40+
general:format-prettier:
41+
desc: Format all supported files with Prettier
42+
cmds:
43+
- npx prettier --write .
44+
45+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml
46+
go:build:
47+
desc: Build the Go code
48+
dir: '{{default "./" .GO_MODULE_PATH}}'
49+
cmds:
50+
- go build -v {{.LDFLAGS}}
51+
52+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/deploy-cobra-mkdocs-versioned-poetry/Taskfile.yml
53+
go:cli-docs:
54+
desc: Generate command line interface reference documentation
55+
dir: ./docsgen
56+
cmds:
57+
# Command examples use os.Args[0] so the docs generation binary must have the same filename as the project
58+
- go build -o {{.PROJECT_NAME}}{{exeExt}}
59+
# The binary is invoked like this instead of `./{{.PROJECT_NAME}}` to remove the `./` chars from the examples
60+
- PATH=. {{.PROJECT_NAME}} ../docs/commands
61+
62+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
63+
go:fix:
64+
desc: Modernize usages of outdated APIs
65+
dir: '{{default "./" .GO_MODULE_PATH}}'
66+
cmds:
67+
- go fix {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
68+
69+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
70+
go:format:
71+
desc: Format Go code
72+
dir: '{{default "./" .GO_MODULE_PATH}}'
73+
cmds:
74+
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
75+
76+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
77+
go:lint:
78+
desc: Lint Go code
79+
dir: '{{default "./" .GO_MODULE_PATH}}'
80+
cmds:
81+
- |
82+
if ! which golint &>/dev/null; then
83+
echo "golint not installed or not in PATH. Please install: https://github.com/golang/lint#installation"
84+
exit 1
85+
fi
86+
- |
87+
golint \
88+
{{default "-min_confidence 0.8 -set_exit_status" .GO_LINT_FLAGS}} \
89+
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
90+
91+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml
92+
go:test:
93+
desc: Run unit tests
94+
dir: '{{default "./" .GO_MODULE_PATH}}'
95+
cmds:
96+
- |
97+
go test \
98+
-v \
99+
-short \
100+
-run '{{default ".*" .GO_TEST_REGEX}}' \
101+
{{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \
102+
-coverprofile=coverage_unit.txt \
103+
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} \
104+
{{.TEST_LDFLAGS}}
105+
106+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-integration-task/Taskfile.yml
107+
go:test-integration:
108+
desc: Run integration tests
109+
deps:
110+
- task: go:build
111+
- task: poetry:install-deps
112+
cmds:
113+
- poetry run pytest test
114+
115+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
116+
go:vet:
117+
desc: Check for errors in Go code
118+
dir: '{{default "./" .GO_MODULE_PATH}}'
119+
cmds:
120+
- go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
121+
122+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
123+
markdown:check-links:
124+
desc: Check for broken links
125+
deps:
126+
- task: docs:generate
127+
cmds:
128+
- |
129+
if [[ "{{.OS}}" == "Windows_NT" ]]; then
130+
# npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
131+
# so the Windows user is required to have markdown-link-check installed and in PATH.
132+
if ! which markdown-link-check &>/dev/null; then
133+
echo "markdown-link-check not found or not in PATH. Please install: https://github.com/tcort/markdown-link-check#readme"
134+
exit 1
135+
fi
136+
# Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
137+
# exit status, but it's better to check all links before exiting.
138+
set +o errexit
139+
STATUS=0
140+
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
141+
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
142+
# \ characters special treatment on Windows in an attempt to support them as path separators.
143+
for file in $(find . -regex ".*[.]md"); do
144+
markdown-link-check \
145+
--quiet \
146+
--config "./.markdown-link-check.json" \
147+
"$file"
148+
STATUS=$(( $STATUS + $? ))
149+
done
150+
exit $STATUS
151+
else
152+
npx --package=markdown-link-check --call='
153+
STATUS=0
154+
for file in $(find . -regex ".*[.]md"); do
155+
markdown-link-check \
156+
--quiet \
157+
--config "./.markdown-link-check.json" \
158+
"$file"
159+
STATUS=$(( $STATUS + $? ))
160+
done
161+
exit $STATUS
162+
'
163+
fi
164+
165+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
166+
markdown:fix:
167+
desc: Automatically correct linting violations in Markdown files where possible
168+
cmds:
169+
- npx markdownlint-cli --fix "**/*.md"
170+
171+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
172+
markdown:lint:
173+
desc: Check for problems in Markdown files
174+
cmds:
175+
- npx markdownlint-cli "**/*.md"
176+
177+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
178+
poetry:install-deps:
179+
desc: Install dependencies managed by Poetry
180+
cmds:
181+
- poetry install --no-root
182+
183+
protoc:
184+
desc: Lint, format and compile protobuf definitions
185+
deps:
186+
- protoc:check
187+
- protoc:format
188+
- protoc:compile
189+
190+
protoc:compile:
191+
desc: Compile protobuf definitions
192+
cmds:
193+
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=./rpc --go_opt=paths=source_relative --go-grpc_out=./rpc --go-grpc_opt=paths=source_relative ./rpc/cc/arduino/cli/commands/v1/*.proto'
194+
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=./rpc --go_opt=paths=source_relative --go-grpc_out=./rpc --go-grpc_opt=paths=source_relative ./rpc/cc/arduino/cli/monitor/v1/*.proto'
195+
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=./rpc --go_opt=paths=source_relative --go-grpc_out=./rpc --go-grpc_opt=paths=source_relative ./rpc/cc/arduino/cli/settings/v1/*.proto'
196+
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=./rpc --go_opt=paths=source_relative --go-grpc_out=./rpc --go-grpc_opt=paths=source_relative ./rpc/cc/arduino/cli/debug/v1/*.proto'
197+
198+
protoc:docs:
199+
desc: Generate docs for protobuf definitions
200+
cmds:
201+
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,commands.md --proto_path=rpc ./rpc/cc/arduino/cli/commands/v1/*.proto'
202+
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,monitor.md --proto_path=rpc ./rpc/cc/arduino/cli/monitor/v1/*.proto'
203+
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,settings.md --proto_path=rpc ./rpc/cc/arduino/cli/settings/v1/*.proto'
204+
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,debug.md --proto_path=rpc ./rpc/cc/arduino/cli/debug/v1/*.proto'
205+
206+
protoc:check:
207+
desc: Perform linting of the protobuf definitions
208+
cmds:
209+
- buf lint rpc
210+
211+
protoc:format:
212+
desc: Perform formatting of the protobuf definitions
213+
cmds:
214+
- clang-format -i rpc/cc/arduino/cli/*/*/*.proto
215+
216+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
217+
python:format:
218+
desc: Format Python files
219+
deps:
220+
- task: poetry:install-deps
221+
cmds:
222+
- poetry run black .
223+
224+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
225+
python:lint:
226+
desc: Lint Python code
227+
deps:
228+
- task: poetry:install-deps
229+
cmds:
230+
- poetry run flake8 --show-source
231+
232+
build:
233+
desc: Build the project
234+
deps:
235+
- task: go:build
236+
237+
test:
238+
desc: Run the full testsuite, `legacy` will be skipped
239+
cmds:
240+
- task: go:test
241+
- task: go:test-integration
242+
243+
test-legacy:
244+
desc: Run tests for the `legacy` package
245+
cmds:
246+
- |
247+
go test \
248+
{{ default "-v -failfast" .GOFLAGS }} \
249+
-coverprofile=coverage_legacy.txt \
250+
./legacy/... \
251+
{{.TEST_LDFLAGS}}
252+
253+
test-unit-race:
254+
desc: Run unit tests only with race condition detection
255+
cmds:
256+
- |
257+
go test \
258+
-short \
259+
-race {{ default "-v" .GOFLAGS }} \
260+
-coverprofile=coverage_race_unit.txt \
261+
{{ default .DEFAULT_GO_PACKAGES .TARGETS }} \
262+
{{.TEST_LDFLAGS}}
263+
264+
check:
265+
desc: Check fmt and lint, `legacy` will be skipped
266+
cmds:
267+
- task: go:vet
268+
- task: go:lint
269+
- task: i18n:check
270+
- task: python:lint
271+
- task: protoc:check
272+
273+
check-legacy:
274+
desc: Check fmt and lint for the `legacy` package
275+
cmds:
276+
- test -z $(go fmt ./legacy/...)
277+
- go vet ./legacy/...
278+
279+
rpc-client:
280+
desc: Run the rpc client test routine (server must be already started)
281+
cmds:
282+
- go test -run TestWithClientE2E ./commands/daemon
283+
284+
i18n:update:
285+
desc: Updates i18n files
286+
cmds:
287+
- go run ./i18n/cmd/main.go catalog generate . > ./i18n/data/en.po
288+
289+
i18n:pull:
290+
desc: Pull i18n files from transifex
291+
cmds:
292+
- go run ./i18n/cmd/main.go transifex pull ./i18n/data
293+
294+
i18n:push:
295+
desc: Push i18n files to transifex
296+
cmds:
297+
- go run ./i18n/cmd/main.go transifex push ./i18n/data
298+
299+
i18n:check:
300+
desc: Check if the i18n message catalog was updated
301+
cmds:
302+
- task: i18n:update
303+
- git add -N ./i18n/data
304+
- git diff --exit-code ./i18n/data
305+
306+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-mkdocs-task/Taskfile.yml
307+
website:check:
308+
desc: Check whether the MkDocs-based website will build
309+
deps:
310+
- task: docs:generate
311+
- task: poetry:install-deps
312+
cmds:
313+
- poetry run mkdocs build --strict
314+
315+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-mkdocs-task/Taskfile.yml
316+
website:serve:
317+
desc: Run website locally
318+
deps:
319+
- task: docs:generate
320+
- task: poetry:install-deps
321+
cmds:
322+
- poetry run mkdocs serve
323+
324+
vars:
325+
PROJECT_NAME: "arduino-language-server"
326+
DIST_DIR: "dist"
327+
DEFAULT_GO_PACKAGES:
328+
sh: |
329+
echo $(cd {{default "./" .GO_MODULE_PATH}} && go list ./... | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
330+
# build vars
331+
COMMIT:
332+
sh: echo "$(git log --no-show-signature -n 1 --format=%h)"
333+
TIMESTAMP:
334+
sh: echo "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
335+
TIMESTAMP_SHORT:
336+
sh: echo "{{now | date "20060102"}}"
337+
TAG:
338+
sh: echo "$(git tag --points-at=HEAD 2> /dev/null | head -n1)"
339+
VERSION: "{{if .NIGHTLY}}nightly-{{.TIMESTAMP_SHORT}}{{else if .TAG}}{{.TAG}}{{else}}{{.PACKAGE_NAME_PREFIX}}git-snapshot{{end}}"
340+
CONFIGURATION_PACKAGE: "github.com/arduino/arduino-language-server/version"
341+
LDFLAGS: >-
342+
-ldflags
343+
'
344+
-X {{.CONFIGURATION_PACKAGE}}.versionString={{.VERSION}}
345+
-X {{.CONFIGURATION_PACKAGE}}.commit={{.COMMIT}}
346+
-X {{.CONFIGURATION_PACKAGE}}.date={{.TIMESTAMP}}
347+
'
348+
# test vars
349+
GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic"
350+
TEST_VERSION: "0.0.0-test.preview"
351+
TEST_COMMIT: "deadbeef"
352+
TEST_LDFLAGS: >-
353+
-ldflags
354+
'
355+
-X {{.CONFIGURATION_PACKAGE}}.versionString={{.TEST_VERSION}}
356+
-X {{.CONFIGURATION_PACKAGE}}.commit={{.TEST_COMMIT}}
357+
-X {{.CONFIGURATION_PACKAGE}}.date={{.TIMESTAMP}}
358+
'

0 commit comments

Comments
 (0)
Please sign in to comment.