Skip to content

Commit 069598d

Browse files
committed
refactor and optimize Taskfile (✨) change also workflows accordingly
1 parent 4a9b413 commit 069598d

File tree

3 files changed

+34
-92
lines changed

3 files changed

+34
-92
lines changed

.github/workflows/release.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
operating-system: [ubuntu-18.04, windows-2019, macos-10.15]
1414

1515
runs-on: ${{ matrix.operating-system }}
16+
env:
17+
TAG_VERSION: ${GITHUB_REF##*/} # will be available to all steps and will be used by task build
1618

1719
steps:
1820
- name: Disable EOL conversions
@@ -53,37 +55,24 @@ jobs:
5355
run: task test-unit
5456

5557
- name: Build the Agent for linux
56-
run: task build
58+
run: task build
5759
if: matrix.operating-system == 'ubuntu-18.04'
5860

5961
# build the agent without GUI support (no tray icon)
6062
- name: Build the Agent-cli
6163
run: task build-cli
6264
if: matrix.operating-system == 'ubuntu-18.04'
6365

64-
# the manifest is required by windows GUI apps, otherwise the binary will crash with: "Unable to create main window: TTM_ADDTOOL failed" (for reference https://github.com/lxn/walk/issues/28)
65-
# rsrc will produce a *.syso file that should get automatically recognized by go build command and linked into an executable.
66-
- name: Download tool to embed manifest in win binary
67-
run: |
68-
go get github.com/akavel/rsrc
69-
if: matrix.operating-system == 'windows-2019'
70-
7166
# building the agent for win requires a different task because of an extra flag
7267
- name: Build the Agent for win32
7368
env:
7469
GOARCH: 386 # 32bit architecture (for support)
7570
GO386: 387 # support old instruction sets without MMX (used in the Pentium 4) (will be deprecated in GO > 1.15 https://golang.org/doc/go1.15)
76-
run: |
77-
rsrc -arch 386 -manifest manifest.xml
78-
task build-win
79-
rm *.syso
71+
run: task build-win
8072
if: matrix.operating-system == 'windows-2019'
8173

8274
- name: Build the Agent for win64
83-
run: |
84-
rsrc -arch amd64 -manifest manifest.xml
85-
task build-win
86-
rm *.syso
75+
run: task build-win # GOARCH=amd64 by default on the runners
8776
if: matrix.operating-system == 'windows-2019'
8877

8978
- name: Build the Agent for macos

.github/workflows/test.yml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,45 +50,32 @@ jobs:
5050
run: task test-unit
5151

5252
- name: Build the Agent for linux
53-
run: task test:build
53+
run: task build
5454
if: matrix.operating-system == 'ubuntu-18.04'
5555

5656
# build the agent without GUI support (no tray icon)
5757
- name: Build the Agent-cli
58-
run: task test:build-cli
58+
run: task build-cli
5959
if: matrix.operating-system == 'ubuntu-18.04'
6060

61-
# the manifest is required by windows GUI apps, otherwise the binary will crash with: "Unable to create main window: TTM_ADDTOOL failed" (for reference https://github.com/lxn/walk/issues/28)
62-
# rsrc will produce a *.syso file that should get automatically recognized by go build command and linked into an executable.
63-
- name: Download tool to embed manifest in win binary
64-
run: |
65-
go get github.com/akavel/rsrc
66-
if: matrix.operating-system == 'windows-2019'
67-
6861
# building the agent for win requires a different task because of an extra flag
6962
- name: Build the Agent for win32
7063
env:
7164
GOARCH: 386 # 32bit architecture (for support)
7265
GO386: 387 # support old instruction sets without MMX (used in the Pentium 4) (will be deprecated in GO > 1.15 https://golang.org/doc/go1.15)
73-
run: |
74-
rsrc -arch 386 -manifest manifest.xml
75-
task test:build-win
76-
rm *.syso
66+
run: task build-win
7767
if: matrix.operating-system == 'windows-2019'
7868

7969
- name: Build the Agent for win64
80-
run: |
81-
rsrc -arch amd64 -manifest manifest.xml
82-
task test:build-win
83-
rm *.syso
70+
run: task build-win # GOARCH=amd64 by default on the runners
8471
if: matrix.operating-system == 'windows-2019'
8572

8673
- name: Build the Agent for macos
8774
env:
8875
MACOSX_DEPLOYMENT_TARGET: 10.11 # minimum supported version for mac
8976
CGO_CFLAGS: -mmacosx-version-min=10.11
9077
CGO_LDFLAGS: -mmacosx-version-min=10.11
91-
run: task test:build
78+
run: task build
9279
if: matrix.operating-system == 'macos-10.15'
9380

9481
# config.ini is required by the executable when it's run

Taskfile.yml

Lines changed: 24 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,35 @@
1-
version: "2"
1+
version: '3'
22

33
tasks:
44

55
build:
6-
desc: Build the project
6+
desc: Build the project, to use a specific version use `task build TAG_VERSION=x.x.x`
77
cmds:
8-
- go build -v -i -o {{.APP_NAME}} {{.LDFLAGS}}
8+
- go build -v -i {{default "" .ADDITIONAL_FLAGS}} -o {{default "arduino-create-agent" .APP_NAME}} -ldflags '-X main.version={{default .TAG_TEST .TAG_VERSION}} -X main.git_revision={{.COMMIT}} {{default "" .WIN_FLAGS}}'
9+
vars:
10+
COMMIT:
11+
sh: git log -n 1 --format=%h
912

1013
build-cli:
1114
desc: Build the project without tray support
1215
cmds:
13-
- go build -v -i -tags cli -o {{.APP_NAME}}_cli {{.LDFLAGS}}
16+
- task: build
17+
vars:
18+
APP_NAME: arduino-create-agent_cli
19+
ADDITIONAL_FLAGS: -tags cli
1420

1521
build-win:
16-
desc: Build the project for win
22+
desc: Build the project for win, to build 32bit `export GOARCH=386` and for 64 bit `export GOARCH=amd64` before `task build-win`
1723
cmds:
18-
- go build -v -i -o {{.APP_NAME}}_{{.GOARCH}} {{.WIN_LDFLAGS}}
19-
20-
test:build:
21-
desc: Build the project for test.yml
22-
env:
23-
cmds:
24-
- go build -v -i -o {{.APP_NAME}} {{.TEST_LDFLAGS}}
25-
26-
test:build-cli:
27-
desc: Build the project without tray support for test.yml
28-
cmds:
29-
- go build -v -i -tags cli -o {{.APP_NAME}}_cli {{.TEST_LDFLAGS}}
30-
31-
test:build-win:
32-
desc: Build the project for win for test.yml
33-
cmds:
34-
- go build -v -i -o {{.APP_NAME}}_{{.GOARCH}} {{.TEST_WIN_LDFLAGS}}
35-
36-
test:
37-
desc: Run the full testsuite, `legacy` will be skipped
38-
cmds:
39-
- task: test-unit
24+
# the manifest is required by windows GUI apps, otherwise the binary will crash with: "Unable to create main window: TTM_ADDTOOL failed" (for reference https://github.com/lxn/walk/issues/28)
25+
- go get github.com/akavel/rsrc
26+
# rsrc will produce a *.syso file that should get automatically recognized by go build command and linked into an executable.
27+
- rsrc -arch {{.GOARCH}} -manifest manifest.xml # GOARCH shoud be either amd64 or 386
28+
- task: build
29+
vars:
30+
APP_NAME: arduino-create-agent_{{.GOARCH}}
31+
WIN_FLAGS: -H=windowsgui
32+
- rm *.syso # rm file to avoid compilation problems on other platforms
4033

4134
test-unit:
4235
desc: Run unit tests only
@@ -59,43 +52,16 @@ tasks:
5952
# - task: python:check
6053
# - task: docs:check
6154
# - task: config:check
62-
55+
6356
vars:
57+
TAG_TEST: "0.0.0-dev"
58+
GOARCH:
59+
sh: go env GOARCH
6460
# all modules of this project except for "gen/..." module
6561
DEFAULT_TARGETS:
6662
sh: echo `go list ./... | grep -v 'arduino-create-agent/gen/' | tr '\n' ' '`
67-
# build vars
68-
APP_NAME: arduino-create-agent
69-
GOARCH:
70-
sh: go env GOARCH
71-
WIN_FLAGS: -H=windowsgui
72-
COMMIT:
73-
sh: echo ${TRAVIS_COMMIT:-`git log -n 1 --format=%h`}
74-
TAG:
75-
sh: echo `git describe --tags --abbrev=0`
76-
TEST_TAG: "0.0.0-dev"
77-
LDFLAGS: >
78-
-ldflags '-X main.version={{.TAG}}
79-
-X main.git_revision={{.COMMIT}}'
80-
WIN_LDFLAGS: >
81-
-ldflags '-X main.version={{.TAG}}
82-
-X main.git_revision={{.COMMIT}}
83-
{{.WIN_FLAGS}}'
84-
TEST_LDFLAGS: >
85-
-ldflags '-X main.version={{.TEST_TAG}}
86-
-X main.git_revision={{.COMMIT}}'
87-
TEST_WIN_LDFLAGS: >
88-
-ldflags '-X main.version={{.TEST_TAG}}
89-
-X main.git_revision={{.COMMIT}}
90-
{{.WIN_FLAGS}}'
91-
9263
GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic"
9364
# check-lint vars
9465
GOLINTBIN:
9566
sh: go list -f {{"{{"}}".Target{{"}}"}}" golang.org/x/lint/golint
9667
GOLINTFLAGS: "-min_confidence 0.8 -set_exit_status"
97-
# # docs versioning
98-
# DOCS_VERSION: dev
99-
# DOCS_ALIAS: ""
100-
# DOCS_REMOTE: "origin"
101-
PRETTIER: prettier@2.0.5

0 commit comments

Comments
 (0)