Skip to content

Commit

Permalink
Support for linux deb,rpm,arch linux packager packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
atterpac committed Nov 23, 2024
1 parent abcc37f commit 5b5aa4a
Show file tree
Hide file tree
Showing 17 changed files with 193 additions and 19 deletions.
45 changes: 45 additions & 0 deletions v3/internal/commands/build_assets/Taskfile.linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ tasks:
PRODUCTION: "true"
cmds:
- task: create:appimage
- task: create:deb
- task: create:rpm
- task: create:aur

create:appimage:
summary: Creates an AppImage
Expand All @@ -48,6 +51,48 @@ tasks:
DESKTOP_FILE: '{{.APP_NAME}}.desktop'
OUTPUT_DIR: '../../bin'

create:deb:
summary: Creates a deb package
deps:
- task: build
vars:
PRODUCTION: "true"
cmds:
- task: generate:deb

create:rpm:
summary: Creates a rpm package
deps:
- task: build
vars:
PRODUCTION: "true"
cmds:
- task: generate:rpm

create:aur:
summary: Creates a arch linux packager package
deps:
- task: build
vars:
PRODUCTION: "true"
cmds:
- task: generate:aur

generate:deb:
summary: Creates a deb package
cmds:
- nfpm pkg -f ./build/nfpm/nfpm.yaml -p deb -t ./bin/{{.APP_NAME}}.deb

generate:rpm:
summary: Creates a rpm package
cmds:
- nfpm pkg -f ./build/nfpm/nfpm.yaml -p rpm -t ./bin/{{.APP_NAME}}.rpm

generate:aur:
summary: Creates a arch linux packager package
cmds:
- nfpm pkg -f ./build/nfpm/nfpm.yaml -p arch -t ./bin/{{.APP_NAME}}.pkg.tar.zst

generate:dotdesktop:
summary: Generates a `.desktop` file
dir: build
Expand Down
20 changes: 20 additions & 0 deletions v3/internal/commands/updatable_build_assets/nfpm.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "{{.BinaryName}}"
arch: "amd64"
platform: "linux"
version: "{{.ProductVersion}}"
section: "default"
priority: "extra"
maintainer: "{{.ProductCompany}}"
description: "{{.ProductDescription}}"
vendor: "{{.ProductCompany}}"
homepage: "https://wails.io"
license: "MIT"
release: "1"

contents:
- src: "../../bin/{{.BinaryName}}"
dst: "/usr/bin/{{.BinaryName}}"
- src: "../appicon.png"
dst: "/usr/share/icons/hicolor/128x128/apps/{{.BinaryName}}.png"
- src: "{{.BinaryName}}.desktop"
dst: "/usr/share/applications/{{.BinaryName}}.desktop"
44 changes: 44 additions & 0 deletions v3/internal/commands/updatable_build_assets/nfpm/nfpm.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Feel free to remove those if you don't want/need to use them.
# Make sure to check the documentation at https://nfpm.goreleaser.com
#
# The lines below are called `modelines`. See `:help modeline`

name: "{{.BinaryName}}"
arch: ${GOARCH}
platform: "linux"
version: "{{.ProductVersion}}"
section: "default"
priority: "extra"
maintainer: ${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}>
description: "{{.ProductDescription}}"
vendor: "{{.ProductCompany}}"
homepage: "https://wails.io"
license: "MIT"
release: "1"

contents:
- src: "./bin/{{.BinaryName}}"
dst: "/usr/local/bin/{{.BinaryName}}"
- src: "./build/appicon.png"
dst: "/usr/share/icons/hicolor/128x128/apps/{{.BinaryName}}.png"

# replaces:
# - foobar
# provides:
# - bar
# depends:
# - foo
# - bar
# recommends:
# - whatever
# suggests:
# - something-else
# conflicts:
# - not-foo
# - not-bar
# changelog: "changelog.yaml"
# scripts:
# preinstall: ./build/nfpm/scripts/preinstall.sh
# postinstall: ./build/nfpm/scripts/postinstall.sh
# preremove: ./build/nfpm/scripts/preremove.sh
# postremove: ./build/nfpm/scripts/postremove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/bash
3 changes: 2 additions & 1 deletion v3/internal/doctor/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package doctor

import (
"fmt"
"github.com/wailsapp/wails/v3/internal/buildinfo"
"path/filepath"
"runtime"
"runtime/debug"
"slices"
"strconv"
"strings"

"github.com/wailsapp/wails/v3/internal/buildinfo"

"github.com/go-git/go-git/v5"
"github.com/jaypipes/ghw"
"github.com/pterm/pterm"
Expand Down
16 changes: 11 additions & 5 deletions v3/internal/doctor/packagemanager/apt.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (a *Apt) Packages() Packagemap {
"npm": []*Package{
{Name: "npm", SystemPackage: true},
},
"nfpm": []*Package{
{Name: "nfpm", SystemPackage: false, InstallCheck: isNfpmInstalled, InstallCommand: "go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest", Optional: true},
},
}
}

Expand All @@ -54,7 +57,10 @@ func (a *Apt) listPackage(name string) (string, error) {

// PackageInstalled tests if the given package name is installed
func (a *Apt) PackageInstalled(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
if !pkg.SystemPackage {
if pkg.InstallCheck != nil {
return pkg.InstallCheck(), nil
}
return false, nil
}
output, err := a.listPackage(pkg.Name)
Expand All @@ -64,8 +70,8 @@ func (a *Apt) PackageInstalled(pkg *Package) (bool, error) {

// PackageAvailable tests if the given package is available for installation
func (a *Apt) PackageAvailable(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
if !pkg.SystemPackage {
return true, nil
}
output, err := a.listPackage(pkg.Name)
// We add a space to ensure we get a full match, not partial match
Expand All @@ -78,8 +84,8 @@ func (a *Apt) PackageAvailable(pkg *Package) (bool, error) {

// InstallCommand returns the package manager specific command to install a package
func (a *Apt) InstallCommand(pkg *Package) string {
if pkg.SystemPackage == false {
return pkg.InstallCommand[a.osid]
if !pkg.SystemPackage {
return pkg.InstallCommand
}
return "sudo apt install " + pkg.Name
}
Expand Down
10 changes: 8 additions & 2 deletions v3/internal/doctor/packagemanager/dnf.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func (y *Dnf) Packages() Packagemap {
{Name: "npm", SystemPackage: true},
{Name: "nodejs-npm", SystemPackage: true},
},
"nfpm*": []*Package{
{Name: "nfpm", SystemPackage: false, InstallCheck: isNfpmInstalled, InstallCommand: "go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest", Optional: true},
},
}
}

Expand All @@ -53,7 +56,10 @@ func (y *Dnf) Name() string {

// PackageInstalled tests if the given package name is installed
func (y *Dnf) PackageInstalled(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
if !pkg.SystemPackage {
if pkg.InstallCheck != nil {
return pkg.InstallCheck(), nil
}
return false, nil
}
stdout, err := execCmd("dnf", "info", "installed", pkg.Name)
Expand Down Expand Up @@ -103,7 +109,7 @@ func (y *Dnf) PackageAvailable(pkg *Package) (bool, error) {
// InstallCommand returns the package manager specific command to install a package
func (y *Dnf) InstallCommand(pkg *Package) string {
if pkg.SystemPackage == false {
return pkg.InstallCommand[y.osid]
return pkg.InstallCommand
}
return "sudo dnf install " + pkg.Name
}
Expand Down
5 changes: 4 additions & 1 deletion v3/internal/doctor/packagemanager/emerge.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (e *Emerge) Packages() Packagemap {
"npm": []*Package{
{Name: "net-libs/nodejs", SystemPackage: true},
},
"nfpm": []*Package{
{Name: "nfpm", SystemPackage: false, InstallCheck: isNfpmInstalled, InstallCommand: "go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest", Optional: true},
},
}
}

Expand Down Expand Up @@ -106,7 +109,7 @@ func (e *Emerge) PackageAvailable(pkg *Package) (bool, error) {
// InstallCommand returns the package manager specific command to install a package
func (e *Emerge) InstallCommand(pkg *Package) string {
if pkg.SystemPackage == false {
return pkg.InstallCommand[e.osid]
return pkg.InstallCommand
}
return "sudo emerge " + pkg.Name
}
11 changes: 8 additions & 3 deletions v3/internal/doctor/packagemanager/eopkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
)

// Eopkg represents the Eopkg manager
type Eopkg struct {
name string
osid string
Expand Down Expand Up @@ -42,6 +41,9 @@ func (e *Eopkg) Packages() Packagemap {
"npm": []*Package{
{Name: "nodejs", SystemPackage: true},
},
"nfpm": []*Package{
{Name: "nfpm", SystemPackage: false, InstallCheck: isNfpmInstalled, InstallCommand: "go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest", Optional: true},
},
}
}

Expand All @@ -52,7 +54,10 @@ func (e *Eopkg) Name() string {

// PackageInstalled tests if the given package is installed
func (e *Eopkg) PackageInstalled(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
if !pkg.SystemPackage {
if pkg.InstallCheck != nil {
return pkg.InstallCheck(), nil
}
return false, nil
}
stdout, err := execCmd("eopkg", "info", pkg.Name)
Expand All @@ -75,7 +80,7 @@ func (e *Eopkg) PackageAvailable(pkg *Package) (bool, error) {
// InstallCommand returns the package manager specific command to install a package
func (e *Eopkg) InstallCommand(pkg *Package) string {
if pkg.SystemPackage == false {
return pkg.InstallCommand[e.osid]
return pkg.InstallCommand
}
return "sudo eopkg it " + pkg.Name
}
Expand Down
10 changes: 8 additions & 2 deletions v3/internal/doctor/packagemanager/nixpkgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func (n *Nixpkgs) Packages() Packagemap {
"npm": []*Package{
{Name: channel + ".nodejs", SystemPackage: true},
},
"nfpm": []*Package{
{Name: channel + ".nfpm", SystemPackage: false, InstallCheck: isNfpmInstalled, InstallCommand: "go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest", Optional: true},
},
}
}

Expand All @@ -65,7 +68,10 @@ func (n *Nixpkgs) Name() string {

// PackageInstalled tests if the given package name is installed
func (n *Nixpkgs) PackageInstalled(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
if !pkg.SystemPackage {
if pkg.InstallCheck != nil {
return pkg.InstallCheck(), nil
}
return false, nil
}

Expand Down Expand Up @@ -142,7 +148,7 @@ func (n *Nixpkgs) PackageAvailable(pkg *Package) (bool, error) {
// InstallCommand returns the package manager specific command to install a package
func (n *Nixpkgs) InstallCommand(pkg *Package) string {
if pkg.SystemPackage == false {
return pkg.InstallCommand[n.osid]
return pkg.InstallCommand
}
return "nix-env -iA " + pkg.Name
}
21 changes: 21 additions & 0 deletions v3/internal/doctor/packagemanager/packagemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func AppVersion(name string) string {
return npmVersion()
}

if name == "nfpm" {
return nfpmVersion()
}

return ""

}
Expand Down Expand Up @@ -167,3 +171,20 @@ func npmVersion() string {
version, _ := execCmd("npm", "--version")
return strings.TrimSpace(version)
}

func nfpmVersion() string {
output, _ := execCmd("nfpm", "--version")
lines := strings.Split(output, "\n")
for _, line := range lines {
if strings.HasPrefix(line, "GitVersion:") {
version := strings.TrimSpace(strings.TrimPrefix(line, "GitVersion:"))
return version
}
}
return "unknown"
}

func isNfpmInstalled() bool {
_, err := exec.LookPath("nfpm")
return err == nil
}
10 changes: 8 additions & 2 deletions v3/internal/doctor/packagemanager/pacman.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (p *Pacman) Packages() Packagemap {
"npm": []*Package{
{Name: "npm", SystemPackage: true},
},
"nfpm": []*Package{
{Name: "nfpm", SystemPackage: false, InstallCheck: isNfpmInstalled, InstallCommand: "go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest", Optional: true},
},
}
}

Expand All @@ -51,7 +54,10 @@ func (p *Pacman) Name() string {

// PackageInstalled tests if the given package name is installed
func (p *Pacman) PackageInstalled(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
if !pkg.SystemPackage {
if pkg.InstallCheck != nil {
return pkg.InstallCheck(), nil
}
return false, nil
}
stdout, err := execCmd("pacman", "-Q", pkg.Name)
Expand Down Expand Up @@ -103,7 +109,7 @@ func (p *Pacman) PackageAvailable(pkg *Package) (bool, error) {
// InstallCommand returns the package manager specific command to install a package
func (p *Pacman) InstallCommand(pkg *Package) string {
if pkg.SystemPackage == false {
return pkg.InstallCommand[p.osid]
return pkg.InstallCommand
}
return "sudo pacman -S " + pkg.Name
}
3 changes: 2 additions & 1 deletion v3/internal/doctor/packagemanager/pm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package packagemanager
type Package struct {
Name string
Version string
InstallCommand map[string]string
InstallCommand string
InstallCheck func() bool
SystemPackage bool
Library bool
Optional bool
Expand Down
Loading

0 comments on commit 5b5aa4a

Please sign in to comment.