Skip to content

Commit

Permalink
Improve build system (#1328)
Browse files Browse the repository at this point in the history
* Add internal task builder

* Add MacOS, Linux and Windows task files

* Update Taskfile.yml with new tasks

* Use new tasks in build workflow

* Update prod build flags and fix VERSION handling in internal build task

* Add a task for generating MS required directories

* Improve MS build in build workflow to build as production only on releases

* Replace `summary` with `desc` and add some missing desc for tasks

* Fix build error due to internal include working dir
  • Loading branch information
thomas-senechal authored Mar 5, 2024
1 parent 22d0d44 commit 531d35e
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 43 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,22 @@ jobs:
run: go install fyne.io/fyne/v2/cmd/fyne@latest
- name: Set environment variables
run: |
echo "GOOS=${{ matrix.target }}" >> $GITHUB_ENV
echo "GOARCH=${{ matrix.arch }}" >> $GITHUB_ENV
echo "CGO_ENABLED=1" >> $GITHUB_ENV
echo "CC=${{ matrix.cc }}" >> $GITHUB_ENV
- name: Build binary for ${{ matrix.target }} on ${{ matrix.arch}}
- name: Build binary for ${{ matrix.target }} on ${{ matrix.arch }}
shell: bash
run: |
go build -ldflags "-X github.com/massalabs/station/int/config.Version=${{env.VERSION}}" -o massastation_${{ matrix.target }}_${{ matrix.arch }}${{ matrix.ext }} ./cmd/massastation/
task ${{ matrix.target }}:build VERSION=${{ env.VERSION }} ARCH=${{ matrix.arch }} PRODUCTION=${{ inputs.tag_name != '' }} BIN_DIR="."
- name: Package binary for ${{ matrix.target }} on ${{ matrix.arch}}
# We don't need to package for windows since fyne package generates a similar .exe as go build.
# We don't need to package for windows since Fyne package generates a similar .exe as go build.
if: matrix.target != 'windows'
shell: bash
run: |
cp massastation_${{ matrix.target }}_${{ matrix.arch }} massastation
fyne package -name MassaStation -icon ./int/systray/embedded/logo.png -appID net.massalabs.massastation -exe massastation
task package
- name: Rename binary for ${{ matrix.target }} on ${{ matrix.arch }}
shell: bash
run: |
mv ./massastation${{ matrix.ext }} massastation_${{ matrix.target }}_${{ matrix.arch }}${{ matrix.ext }}
- name: Upload MassaStation Binary
uses: actions/upload-artifact@v3
with:
Expand Down
93 changes: 57 additions & 36 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@
version: '3'
version: "3"

vars:
APP_NAME: "massastation"
BIN_DIR: "./build/{{.APP_NAME}}"

includes:
darwin: tasks/Taskfile_darwin.yml
linux: tasks/Taskfile_linux.yml
windows: tasks/Taskfile_windows.yml
internal:
taskfile: tasks/Taskfile_internal.yml
internal: true

tasks:
install:
desc: Installs build dependencies
cmds:
- echo "Installing dependencies"
- cmd: go install github.com/go-swagger/go-swagger/cmd/swagger@latest
- cmd: go install golang.org/x/tools/cmd/stringer@latest
- cmd: go install go.uber.org/mock/[email protected]

install-dev:
desc: Installs development dependencies (fmt, lint, etc.)
cmds:
- cmd: go install github.com/golangci/golangci-lint/cmd/[email protected]
- cmd: go install github.com/daixiang0/gci@latest
- cmd: go install mvdan.cc/gofumpt@latest
- task: install-dev-win

install-dev-win:
desc: Installs Windows development dependencies
platforms: [windows]
cmds:
- cmd: mkdir -p build/massastation
- cmd: curl -o build/massastation/mar-tools-win64.zip https://archive.torproject.org/tor-package-archive/torbrowser/12.5.1/mar-tools-win64.zip

generate: go generate ./...
generate:
cmds:
- task: generate-dirs
- cmd: go generate ./...

test:
test:
cmds:
- cmd: go test -v -timeout 60s ./...

test-2e2:
cmds:
- cmd: scripts/test-e2e.sh

test-coverage:
test-coverage:
cmds:
- cmd: go test -timeout 60s ./... -coverprofile=coverage.coverprofile

fmt:
desc: Formats all files
cmds:
- cmd: go mod tidy
- cmd: gofumpt -l -w .
Expand All @@ -44,52 +62,55 @@ tasks:
- cmd: golangci-lint run --fix

fmt-web:
desc: Formats web files
dir: web/massastation
cmds:
- cmd: npm run fmt

build:
cmds:
- task: build-linux
- task: build-macos
- task: build-windows

build-linux:
platforms: [linux]
cmds:
- cmd: mkdir -p build/massastation
- cmd: go build -o build/massastation/massastation cmd/massastation/main.go
- cmd: sudo setcap CAP_NET_BIND_SERVICE=+eip build/massastation/massastation

build-macos:
platforms: [darwin]
cmds:
- cmd: mkdir -p build/massastation
- cmd: go build -o build/massastation/massastation cmd/massastation/main.go

build-windows:
platforms: [windows]
cmds:
- cmd: mkdir -p build/massastation
- cmd: mkdir -p build/massastation/logs
- cmd: mkdir -p build/massastation/certs
- cmd: go build -o build/massastation/massastation.exe cmd/massastation/main.go

run:
desc: Runs MassaStation in DEBUG mode
cmds:
- cmd: "{{.BIN_DIR}}/{{.APP_NAME}}{{.BIN_EXT}}"
vars:
BIN_EXT: '{{if eq .OS "windows"}}.exe{{end}}'
env:
LOG_LEVEL: DEBUG

build:
desc: Builds MassaStation
cmds:
- cmd: ./build/massastation/massastation
platforms: [linux, darwin]
- cmd: ./build/massastation/massastation.exe
platforms: [windows]
- task: linux:int-build
- task: darwin:int-build
- task: windows:int-build

build-run:
desc: Builds and runs MassaStation
cmds:
- task: build
- task: run

package:
desc: Packages MassaStation using fyne
platforms: [linux, darwin]
cmds:
- cmd: fyne package -name MassaStation -icon ./int/systray/embedded/logo.png -appID net.massalabs.massastation -exe massastation

generate-dirs:
desc: Generates required directories for MassaStation
cmds:
- cmd: "{{.SUDO}} mkdir -p {{.CONFIG_DIR}}"
- cmd: "{{.SUDO}} mkdir -p {{.CONFIG_DIR}}/logs"
- cmd: "{{.SUDO}} mkdir -p {{.CONFIG_DIR}}/plugins"
status:
- test -d "{{.CONFIG_DIR}}"
- test -d "{{.CONFIG_DIR}}/logs"
- test -d "{{.CONFIG_DIR}}/plugins"
vars:
CONFIG_DIR: '{{if eq OS "windows"}}{{.BIN_DIR}}{{else}}/usr/local/share/massastation{{end}}'
SUDO: '{{if ne OS "windows"}}sudo{{end}}'

all:
desc: Runs install, generate, build-run
cmds:
- task: install
- task: generate
Expand Down
32 changes: 32 additions & 0 deletions tasks/Taskfile_darwin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3"

includes:
internal:
taskfile: ./Taskfile_internal.yml
internal: true
dir: ..

tasks:
int-build:
desc: Internal build task for macOS
platforms: [darwin]
internal: true
cmds:
- cmd: echo BUILDING FOR macOS $GOARCH
- task: build

build:
desc: Builds MassaStation for macOS
cmds:
- task: internal:build
vars:
OS: darwin
ARCH: '{{.ARCH | default ""}}'

build-prod:
desc: Builds MassaStation for macOS (production)
cmds:
- task: internal:build-prod
vars:
OS: darwin
ARCH: '{{.ARCH | default ""}}'
32 changes: 32 additions & 0 deletions tasks/Taskfile_internal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3"

tasks:
build:
desc: Internal build task
internal: true
cmds:
- cmd: echo Building MassaStation for {{.OS | default OS}}/{{.ARCH | default ARCH}}
- cmd: go build {{.BUILD_FLAGS}} -o {{.BIN_DIR}}/{{.APP_NAME}}{{.BIN_EXT}} ./cmd/massastation/main.go
vars:
# We need this check for nil and empty string because a simple check for empty string doesn't work as expected
VERSION_FLAG: '{{if ne .VERSION nil}}{{if ne .VERSION ""}}-X github.com/massalabs/station/int/config.Version={{.VERSION}}{{end}}{{end}}'
BUILD_FLAGS: '{{if eq .PRODUCTION "true"}}-tags production {{end}}-ldflags="{{.VERSION_FLAG}}{{if eq .PRODUCTION "true"}} -w -s{{end}}"'
BIN_EXT: '{{if eq .OS "windows"}}.exe{{end}}'
env:
GOOS: "{{.OS | default OS}}"
GOARCH: "{{.ARCH | default ARCH}}"
PRODUCTION: '{{.PRODUCTION | default "false"}}'
VERSION: "{{.VERSION | default nil}}"

build-prod:
desc: Builds MassaStation (production)
preconditions:
- sh: test -n "{{.VERSION}}"
msg: "VERSION is required"
cmds:
- task: build
vars:
OS: "{{.OS | default OS}}"
ARCH: "{{.ARCH | default ARCH}}"
PRODUCTION: true
VERSION: '{{.VERSION | default ""}}'
30 changes: 30 additions & 0 deletions tasks/Taskfile_linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3"

includes:
internal:
taskfile: ./Taskfile_internal.yml
internal: true
dir: ..

tasks:
int-build:
desc: Internal build task for Linux
platforms: [linux]
internal: true
cmds:
- task: build

build:
desc: Builds MassaStation for Linux
cmds:
- task: internal:build
vars:
OS: linux
- cmd: sudo setcap CAP_NET_BIND_SERVICE=+eip {{.BIN_DIR}}/{{.APP_NAME}} || true

build-prod:
desc: Builds MassaStation for Linux (production)
cmds:
- task: internal:build-prod
vars:
OS: linux
29 changes: 29 additions & 0 deletions tasks/Taskfile_windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3"

includes:
internal:
taskfile: ./Taskfile_internal.yml
internal: true
dir: ..

tasks:
int-build:
desc: Internal build task for Windows
platforms: [windows]
internal: true
cmds:
- task: build

build:
desc: Builds MassaStation for Windows
cmds:
- task: internal:build
vars:
OS: windows

build-prod:
desc: Builds MassaStation for Windows (production)
cmds:
- task: internal:build-prod
vars:
OS: windows

0 comments on commit 531d35e

Please sign in to comment.