Taskfile.yml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. version: '3'
  2. includes:
  3. common: ../Taskfile.yml
  4. vars:
  5. # Signing configuration - edit these values for your project
  6. # PGP_KEY: "path/to/signing-key.asc"
  7. # SIGN_ROLE: "builder" # Options: origin, maint, archive, builder
  8. #
  9. # Password is stored securely in system keychain. Run: wails3 setup signing
  10. # Docker image for cross-compilation (used when building on non-Linux or no CC available)
  11. CROSS_IMAGE: wails-cross
  12. tasks:
  13. build:
  14. summary: Builds the application for Linux
  15. cmds:
  16. # Linux requires CGO - use Docker when:
  17. # 1. Cross-compiling from non-Linux, OR
  18. # 2. No C compiler is available, OR
  19. # 3. Target architecture differs from host architecture (cross-arch compilation)
  20. - task: '{{if and (eq OS "linux") (eq .HAS_CC "true") (eq .TARGET_ARCH ARCH)}}build:native{{else}}build:docker{{end}}'
  21. vars:
  22. ARCH: '{{.ARCH}}'
  23. DEV: '{{.DEV}}'
  24. OUTPUT: '{{.OUTPUT}}'
  25. EXTRA_TAGS: '{{.EXTRA_TAGS}}'
  26. OBFUSCATED: '{{.OBFUSCATED}}'
  27. GARBLE_ARGS: '{{.GARBLE_ARGS}}'
  28. vars:
  29. DEFAULT_OUTPUT: '{{.BIN_DIR}}/{{.APP_NAME}}'
  30. OUTPUT: '{{ .OUTPUT | default .DEFAULT_OUTPUT }}'
  31. # Determine target architecture (defaults to host ARCH if not specified)
  32. TARGET_ARCH: '{{.ARCH | default ARCH}}'
  33. # Check if a C compiler is available (gcc or clang) — cross-platform via wails3 tool
  34. HAS_CC:
  35. sh: 'wails3 tool has "gcc|clang"'
  36. build:native:
  37. summary: Builds the application natively on Linux
  38. internal: true
  39. deps:
  40. - task: common:go:mod:tidy
  41. - task: common:build:frontend
  42. vars:
  43. BUILD_FLAGS:
  44. ref: .BUILD_FLAGS
  45. OBFUSCATED:
  46. ref: .OBFUSCATED
  47. DEV:
  48. ref: .DEV
  49. - task: common:generate:icons
  50. - task: generate:dotdesktop
  51. preconditions:
  52. - sh: '{{if eq .OBFUSCATED "true"}}command -v garble >/dev/null 2>&1{{else}}true{{end}}'
  53. msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@v0.16.0 (requires Go 1.24+). See https://github.com/burrowers/garble/releases for version/toolchain compatibility."
  54. cmds:
  55. - '{{if eq .OBFUSCATED "true"}}garble {{.GARBLE_ARGS}} build{{else}}go build{{end}} {{.BUILD_FLAGS}} -o {{.OUTPUT}}'
  56. vars:
  57. BUILD_FLAGS: '{{if eq .DEV "true"}}{{if or .EXTRA_TAGS (eq .OBFUSCATED "true")}}-tags {{if eq .OBFUSCATED "true"}}wails_obfuscated{{if .EXTRA_TAGS}},{{end}}{{end}}{{.EXTRA_TAGS}} {{end}}-buildvcs=false -gcflags=all="-l"{{else}}-tags production{{if eq .OBFUSCATED "true"}},wails_obfuscated{{end}}{{if .EXTRA_TAGS}},{{.EXTRA_TAGS}}{{end}} -trimpath -buildvcs=false -ldflags="-w -s"{{end}}'
  58. DEFAULT_OUTPUT: '{{.BIN_DIR}}/{{.APP_NAME}}'
  59. OUTPUT: '{{ .OUTPUT | default .DEFAULT_OUTPUT }}'
  60. env:
  61. GOOS: linux
  62. CGO_ENABLED: 1
  63. GOARCH: '{{.ARCH | default ARCH}}'
  64. build:docker:
  65. summary: Builds for Linux using Docker (for non-Linux hosts or when no C compiler available)
  66. internal: true
  67. deps:
  68. - task: common:build:frontend
  69. vars:
  70. OBFUSCATED:
  71. ref: .OBFUSCATED
  72. - task: common:generate:icons
  73. - task: generate:dotdesktop
  74. preconditions:
  75. - sh: docker info > /dev/null 2>&1
  76. msg: "Docker is required for cross-compilation to Linux. Please install Docker."
  77. - sh: docker image inspect {{.CROSS_IMAGE}} > /dev/null 2>&1
  78. msg: |
  79. Docker image '{{.CROSS_IMAGE}}' not found.
  80. Build it first: wails3 task setup:docker
  81. cmds:
  82. - docker run --rm -v "{{.ROOT_DIR}}:/app" {{.DOCKER_MOUNTS}} -e APP_NAME="{{.APP_NAME}}" {{if .EXTRA_TAGS}}-e EXTRA_TAGS="{{.EXTRA_TAGS}}"{{end}} {{if eq .OBFUSCATED "true"}}-e OBFUSCATED=true{{end}} {{if .GARBLE_ARGS}}-e GARBLE_ARGS="{{.GARBLE_ARGS}}"{{end}} "{{.CROSS_IMAGE}}" linux {{.DOCKER_ARCH}}
  83. - cmd: docker run --rm -v "{{.ROOT_DIR}}:/app" alpine chown -R $(id -u):$(id -g) /app/bin
  84. platforms: [linux, darwin]
  85. - mkdir -p {{.BIN_DIR}}
  86. - mv "bin/{{.APP_NAME}}-linux-{{.DOCKER_ARCH}}" "{{.OUTPUT}}"
  87. vars:
  88. DOCKER_ARCH: '{{.ARCH | default "amd64"}}'
  89. DEFAULT_OUTPUT: '{{.BIN_DIR}}/{{.APP_NAME}}'
  90. OUTPUT: '{{ .OUTPUT | default .DEFAULT_OUTPUT }}'
  91. # Generate Docker volume mounts: Go module cache + go.mod replace directives
  92. # Uses wails3 tool docker-mounts for cross-platform compatibility (Windows/Linux/macOS)
  93. DOCKER_MOUNTS:
  94. sh: 'wails3 tool docker-mounts'
  95. package:
  96. summary: Packages the application for Linux
  97. deps:
  98. - task: build
  99. cmds:
  100. - task: create:appimage
  101. - task: create:deb
  102. - task: create:rpm
  103. - task: create:aur
  104. create:appimage:
  105. summary: Creates an AppImage
  106. dir: build/linux/appimage
  107. deps:
  108. - task: build
  109. - task: generate:dotdesktop
  110. cmds:
  111. - cp "{{.APP_BINARY}}" "{{.APP_NAME}}"
  112. - cp ../../appicon.png "{{.APP_NAME}}.png"
  113. - wails3 generate appimage -binary "{{.APP_NAME}}" -icon {{.ICON}} -desktopfile {{.DESKTOP_FILE}} -outputdir {{.OUTPUT_DIR}} -builddir {{.ROOT_DIR}}/build/linux/appimage/build
  114. vars:
  115. APP_NAME: '{{.APP_NAME}}'
  116. APP_BINARY: '../../../bin/{{.APP_NAME}}'
  117. ICON: '{{.APP_NAME}}.png'
  118. DESKTOP_FILE: '../{{.APP_NAME}}.desktop'
  119. OUTPUT_DIR: '../../../bin'
  120. create:deb:
  121. summary: Creates a deb package
  122. deps:
  123. - task: build
  124. cmds:
  125. - task: generate:dotdesktop
  126. - task: generate:deb
  127. create:rpm:
  128. summary: Creates a rpm package
  129. deps:
  130. - task: build
  131. cmds:
  132. - task: generate:dotdesktop
  133. - task: generate:rpm
  134. create:aur:
  135. summary: Creates a arch linux packager package
  136. deps:
  137. - task: build
  138. cmds:
  139. - task: generate:dotdesktop
  140. - task: generate:aur
  141. generate:deb:
  142. summary: Creates a deb package
  143. cmds:
  144. - wails3 tool package -name "{{.APP_NAME}}" -format deb -config ./build/linux/nfpm/nfpm.yaml -out {{.ROOT_DIR}}/bin
  145. generate:rpm:
  146. summary: Creates a rpm package
  147. cmds:
  148. - wails3 tool package -name "{{.APP_NAME}}" -format rpm -config ./build/linux/nfpm/nfpm.yaml -out {{.ROOT_DIR}}/bin
  149. generate:aur:
  150. summary: Creates a arch linux packager package
  151. cmds:
  152. - wails3 tool package -name "{{.APP_NAME}}" -format archlinux -config ./build/linux/nfpm/nfpm.yaml -out {{.ROOT_DIR}}/bin
  153. generate:dotdesktop:
  154. summary: Generates a `.desktop` file
  155. dir: build
  156. cmds:
  157. - mkdir -p {{.ROOT_DIR}}/build/linux/appimage
  158. - wails3 generate .desktop -name "{{.APP_NAME}}" -exec "{{.EXEC}}" -icon "{{.ICON}}" -outputfile "{{.ROOT_DIR}}/build/linux/{{.APP_NAME}}.desktop" -categories "{{.CATEGORIES}}"
  159. vars:
  160. APP_NAME: '{{.APP_NAME}}'
  161. EXEC: '{{.APP_NAME}}'
  162. ICON: '{{.APP_NAME}}'
  163. CATEGORIES: 'Development;'
  164. OUTPUTFILE: '{{.ROOT_DIR}}/build/linux/{{.APP_NAME}}.desktop'
  165. run:
  166. cmds:
  167. - '{{.BIN_DIR}}/{{.APP_NAME}}'
  168. sign:deb:
  169. summary: Signs the DEB package
  170. desc: |
  171. Signs the .deb package with a PGP key.
  172. Set PGP_KEY in the vars section to override the key configured globally via
  173. `wails3 setup` (~/.config/wails/defaults.yaml).
  174. Password is retrieved from system keychain (run: wails3 setup signing)
  175. deps:
  176. - task: create:deb
  177. cmds:
  178. # PGP_KEY is optional: if unset, `wails3 tool sign` falls back to the key
  179. # configured globally via `wails3 setup`.
  180. - wails3 tool sign --input "{{.BIN_DIR}}/{{.APP_NAME}}*.deb" {{if .PGP_KEY}}--pgp-key "{{.PGP_KEY}}"{{end}} {{if .SIGN_ROLE}}--role "{{.SIGN_ROLE}}"{{end}}
  181. sign:rpm:
  182. summary: Signs the RPM package
  183. desc: |
  184. Signs the .rpm package with a PGP key.
  185. Set PGP_KEY in the vars section to override the key configured globally via
  186. `wails3 setup` (~/.config/wails/defaults.yaml).
  187. Password is retrieved from system keychain (run: wails3 setup signing)
  188. deps:
  189. - task: create:rpm
  190. cmds:
  191. - wails3 tool sign --input "{{.BIN_DIR}}/{{.APP_NAME}}*.rpm" {{if .PGP_KEY}}--pgp-key "{{.PGP_KEY}}"{{end}}
  192. sign:packages:
  193. summary: Signs all Linux packages (DEB and RPM)
  194. desc: |
  195. Signs both .deb and .rpm packages with a PGP key.
  196. Set PGP_KEY in the vars section to override the key configured globally via
  197. `wails3 setup` (~/.config/wails/defaults.yaml).
  198. Password is retrieved from system keychain (run: wails3 setup signing)
  199. cmds:
  200. - task: sign:deb
  201. - task: sign:rpm