Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace pkgx with pkgm #9

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Go Build

on:
push:
branches: [ "**" ]
pull_request:
branches: [ "master" ]

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ pkgx install github.com/mycreepy/pakku@latest
* `pakku add brew awscli`
* Install the packages on your system:
* `pakku apply`

## Supported Package Managers

* apt
* brew
* dnf
* pkgm
34 changes: 34 additions & 0 deletions internal/manager/pkgm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package manager

import (
"context"
"fmt"
)

type Pkgm struct {
Packages []string
Sudo bool
}

func (m *Pkgm) InstallPackages(ctx context.Context, verbose bool) error {
for _, pkg := range m.Packages {
fmt.Printf("Installing %s with pkgm...\n", pkg)

err := runCommand(ctx, []string{"pkgm", "install", pkg}, m.Sudo, verbose)
if err != nil {
return fmt.Errorf("failed to install %s: %w", pkg, err)
}
}

return nil
}

func (m *Pkgm) UpdatePackages(ctx context.Context, verbose bool) error {
if len(m.Packages) == 0 {
return nil
}

fmt.Println("Updating packages with pkgm...")

return runCommand(ctx, []string{"pkgm", "update"}, m.Sudo, verbose)
}
34 changes: 0 additions & 34 deletions internal/manager/pkgx.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/pakku/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Config struct {
Apt ConfigPackageManager `yaml:"apt"`
Brew ConfigPackageManager `yaml:"brew"`
Dnf ConfigPackageManager `yaml:"dnf"`
Pkgx ConfigPackageManager `yaml:"pkgx"`
Pkgm ConfigPackageManager `yaml:"pkgm"`
}

func resolveAbsoluteConfigPath() (string, error) {
Expand Down
30 changes: 15 additions & 15 deletions internal/pakku/pakku.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Pakku struct {
AptManager manager.Manager
BrewManager manager.Manager
DnfManager manager.Manager
PkgxManager manager.Manager
PkgmManager manager.Manager
}

func New() (*Pakku, error) {
Expand All @@ -39,7 +39,7 @@ func (p *Pakku) setupManagers() error {
p.AptManager = &manager.Apt{Packages: p.config.Apt.Packages, Sudo: p.config.Apt.Sudo}
p.BrewManager = &manager.Brew{Packages: p.config.Brew.Packages, Sudo: p.config.Brew.Sudo}
p.DnfManager = &manager.Dnf{Packages: p.config.Dnf.Packages, Sudo: p.config.Dnf.Sudo}
p.PkgxManager = &manager.Pkgx{Packages: p.config.Pkgx.Packages, Sudo: p.config.Pkgx.Sudo}
p.PkgmManager = &manager.Pkgm{Packages: p.config.Pkgm.Packages, Sudo: p.config.Pkgm.Sudo}

return nil
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func (p *Pakku) printHelp() error {
fmt.Println(" apt")
fmt.Println(" brew")
fmt.Println(" dnf")
fmt.Println(" pkgx")
fmt.Println(" pkgm")
fmt.Println()

return nil
Expand Down Expand Up @@ -194,14 +194,14 @@ func (p *Pakku) addPackageToConfig(manager, pkg string) error {
p.config.Dnf.Packages = append(p.config.Dnf.Packages, pkg)

slices.Sort(p.config.Dnf.Packages)
case "pkgx":
if slices.Contains(p.config.Pkgx.Packages, pkg) {
case "pkgm":
if slices.Contains(p.config.Pkgm.Packages, pkg) {
return fmt.Errorf("package %s has already been added for %s", pkg, manager)
}

p.config.Pkgx.Packages = append(p.config.Pkgx.Packages, pkg)
p.config.Pkgm.Packages = append(p.config.Pkgm.Packages, pkg)

slices.Sort(p.config.Pkgx.Packages)
slices.Sort(p.config.Pkgm.Packages)
default:
return fmt.Errorf("unsupported package manager: %s", manager)
}
Expand Down Expand Up @@ -235,14 +235,14 @@ func (p *Pakku) removePackageFromConfig(manager, pkg string) error {
idx := slices.Index(p.config.Dnf.Packages, pkg)

p.config.Dnf.Packages = slices.Delete(p.config.Dnf.Packages, idx, idx+1)
case "pkgx":
if !slices.Contains(p.config.Pkgx.Packages, pkg) {
case "pkgm":
if !slices.Contains(p.config.Pkgm.Packages, pkg) {
return fmt.Errorf("package %s has not been added for %s", pkg, manager)
}

idx := slices.Index(p.config.Pkgx.Packages, pkg)
idx := slices.Index(p.config.Pkgm.Packages, pkg)

p.config.Pkgx.Packages = slices.Delete(p.config.Pkgx.Packages, idx, idx+1)
p.config.Pkgm.Packages = slices.Delete(p.config.Pkgm.Packages, idx, idx+1)
default:
return fmt.Errorf("unsupported package manager: %s", manager)
}
Expand Down Expand Up @@ -310,9 +310,9 @@ func (p *Pakku) applyPackages(ctx context.Context) error {
return fmt.Errorf("failed to install packages for dnf: %w", err)
}

err = p.PkgxManager.InstallPackages(ctx, *verbose)
err = p.PkgmManager.InstallPackages(ctx, *verbose)
if err != nil {
return fmt.Errorf("failed to install packages for pkgx: %w", err)
return fmt.Errorf("failed to install packages for pkgm: %w", err)
}

return nil
Expand Down Expand Up @@ -343,9 +343,9 @@ func (p *Pakku) applyUpdate(ctx context.Context) error {
return fmt.Errorf("failed to update packages for dnf: %w", err)
}

err = p.PkgxManager.UpdatePackages(ctx, *verbose)
err = p.PkgmManager.UpdatePackages(ctx, *verbose)
if err != nil {
return fmt.Errorf("failed to update packages for pkgx: %w", err)
return fmt.Errorf("failed to update packages for pkgm: %w", err)
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions internal/pakku/pakku_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ func TestBrew(t *testing.T) {
mustSucceed(t, container, []string{"pakku", "remove", "brew", "curl"})
}

func TestPkgx(t *testing.T) {
func TestPkgm(t *testing.T) {
req := testcontainers.ContainerRequest{
Image: "pkgxdev/pkgx:v1",
Image: "pkgxdev/pkgx:v2",
Entrypoint: []string{"bash", "-c", "echo ready && sleep 300"},
Files: []testcontainers.ContainerFile{pakkuFile},
WaitingFor: wait.ForLog("ready"),
Expand All @@ -121,8 +121,8 @@ func TestPkgx(t *testing.T) {

mustSucceed(t, container, []string{"pakku", "init"})
mustSucceed(t, container, []string{"pakku", "config"})
mustSucceed(t, container, []string{"pakku", "add", "pkgx", "curl.se@8"})
mustSucceed(t, container, []string{"pakku", "add", "pkgm", "curl.se^8"})
mustSucceed(t, container, []string{"pakku", "apply", "-verbose"})
mustSucceed(t, container, []string{"pakku", "update", "-verbose"})
mustSucceed(t, container, []string{"pakku", "remove", "pkgx", "curl.se@8"})
mustSucceed(t, container, []string{"pakku", "remove", "pkgm", "curl.se^8"})
}
6 changes: 3 additions & 3 deletions pkgx.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies:
go.dev: 1.23.2
goreleaser.com: 2.3.2
golangci-lint.run: 1.61.0
go.dev: 1.23.5
goreleaser.com: 2.5.1
golangci-lint.run: 1.63.4
gnu.org/make: 4.3.0
4 changes: 2 additions & 2 deletions testdata/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ version: 1
apt:
packages:
- curl
pkgx:
pkgm:
packages:
- kubectl@1.31.0
- kubectl^1
Loading