aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2025-03-28 14:09:38 -0400
committerXe Iaso <me@xeiaso.net>2025-03-28 14:11:24 -0400
commitd035c875a14f5ea10a3f6f95453a0f6b4bac77b6 (patch)
tree3bba84a44639beca0b0a73b283395cf27663af3c /cmd
parent1f8be88ff63a86508402858777277a1f41f932c4 (diff)
downloadx-d035c875a14f5ea10a3f6f95453a0f6b4bac77b6.tar.xz
x-d035c875a14f5ea10a3f6f95453a0f6b4bac77b6.zip
cmd/yeet: add ability to build debian packages
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/yeet/.gitignore1
-rw-r--r--cmd/yeet/internal/mkdeb/mkdeb.go127
-rw-r--r--cmd/yeet/internal/mkrpm/mkrpm.go21
-rw-r--r--cmd/yeet/internal/pkgmeta/package.go19
-rw-r--r--cmd/yeet/main.go14
-rw-r--r--cmd/yeet/yeetfile.js22
6 files changed, 174 insertions, 30 deletions
diff --git a/cmd/yeet/.gitignore b/cmd/yeet/.gitignore
index e7a9c13..db38867 100644
--- a/cmd/yeet/.gitignore
+++ b/cmd/yeet/.gitignore
@@ -1 +1,2 @@
*.rpm
+*.deb \ No newline at end of file
diff --git a/cmd/yeet/internal/mkdeb/mkdeb.go b/cmd/yeet/internal/mkdeb/mkdeb.go
new file mode 100644
index 0000000..2d8d663
--- /dev/null
+++ b/cmd/yeet/internal/mkdeb/mkdeb.go
@@ -0,0 +1,127 @@
+package mkdeb
+
+import (
+ "fmt"
+ "log/slog"
+ "os"
+ "path/filepath"
+ "runtime"
+
+ "github.com/goreleaser/nfpm/v2"
+ _ "github.com/goreleaser/nfpm/v2/deb"
+ "github.com/goreleaser/nfpm/v2/files"
+ "within.website/x/cmd/yeet/internal"
+ "within.website/x/cmd/yeet/internal/pkgmeta"
+)
+
+func Build(p pkgmeta.Package) (foutpath string, err error) {
+ defer func() {
+ if r := recover(); r != nil {
+ switch r.(type) {
+ case error:
+ err = r.(error)
+ slog.Error("mkrpm: error while building", "err", err)
+ default:
+ err = fmt.Errorf("mkrpm: error while building: %v", r)
+ slog.Error("mkrpm: error while building", "err", err)
+ }
+ }
+ }()
+
+ if p.Version == "" {
+ p.Version = internal.GitVersion()
+ }
+
+ dir, err := os.MkdirTemp("", "yeet-mkdeb")
+ if err != nil {
+ return "", fmt.Errorf("mkrpm: can't make temporary directory")
+ }
+ defer os.RemoveAll(dir)
+ os.MkdirAll(dir, 0755)
+
+ defer func() {
+ os.Setenv("GOARCH", runtime.GOARCH)
+ os.Setenv("GOOS", runtime.GOOS)
+ }()
+ os.Setenv("GOARCH", p.Goarch)
+ os.Setenv("GOOS", "linux")
+
+ p.Build(dir)
+
+ var contents files.Contents
+
+ for _, d := range p.EmptyDirs {
+ if d == "" {
+ continue
+ }
+
+ contents = append(contents, &files.Content{Type: files.TypeDir, Destination: d})
+ }
+
+ for repoPath, osPath := range p.ConfigFiles {
+ contents = append(contents, &files.Content{Type: files.TypeConfig, Source: repoPath, Destination: osPath})
+ }
+
+ if err := filepath.Walk(dir, func(path string, stat os.FileInfo, err error) error {
+ if err != nil {
+ return err
+ }
+
+ if stat.IsDir() {
+ return nil
+ }
+
+ contents = append(contents, &files.Content{Type: files.TypeFile, Source: path, Destination: path[len(dir)+1:]})
+
+ return nil
+ }); err != nil {
+ return "", fmt.Errorf("mkdeb: can't walk output directory: %w", err)
+ }
+
+ info := nfpm.WithDefaults(&nfpm.Info{
+ Name: p.Name,
+ Version: p.Version,
+ Arch: p.Goarch,
+ Platform: "linux",
+ Description: p.Description,
+ Maintainer: fmt.Sprintf("%s <%s>", *internal.UserName, *internal.UserEmail),
+ Homepage: p.Homepage,
+ License: p.License,
+ Overridables: nfpm.Overridables{
+ Contents: contents,
+ Depends: p.Depends,
+ Recommends: p.Recommends,
+ Replaces: p.Replaces,
+ Conflicts: p.Replaces,
+ },
+ })
+
+ info.Overridables.RPM.Group = p.Group
+
+ if *internal.GPGKeyID != "" {
+ slog.Debug("using GPG key", "file", *internal.GPGKeyFile, "id", *internal.GPGKeyID)
+ info.Overridables.Deb.Signature.KeyFile = *internal.GPGKeyFile
+ info.Overridables.Deb.Signature.KeyID = internal.GPGKeyID
+ info.Overridables.Deb.Signature.KeyPassphrase = *internal.GPGKeyPassword
+ }
+
+ pkg, err := nfpm.Get("deb")
+ if err != nil {
+ return "", fmt.Errorf("mkdeb: can't get RPM packager: %w", err)
+ }
+
+ foutpath = pkg.ConventionalFileName(info)
+ fout, err := os.Create(foutpath)
+ if err != nil {
+ return "", fmt.Errorf("mkdeb: can't create output file: %w", err)
+ }
+ defer fout.Close()
+
+ if err := pkg.Package(info, fout); err != nil {
+ return "", fmt.Errorf("mkdeb: can't build package: %w", err)
+ }
+
+ slog.Debug("built package", "name", p.Name, "version", p.Version, "path", foutpath)
+
+ return foutpath, err
+}
diff --git a/cmd/yeet/internal/mkrpm/mkrpm.go b/cmd/yeet/internal/mkrpm/mkrpm.go
index a12fcff..b682ad7 100644
--- a/cmd/yeet/internal/mkrpm/mkrpm.go
+++ b/cmd/yeet/internal/mkrpm/mkrpm.go
@@ -11,27 +11,10 @@ import (
"github.com/goreleaser/nfpm/v2/files"
_ "github.com/goreleaser/nfpm/v2/rpm"
"within.website/x/cmd/yeet/internal"
+ "within.website/x/cmd/yeet/internal/pkgmeta"
)
-type Package struct {
- Name string `json:"name"`
- Version string `json:"version"`
- Description string `json:"description"`
- Homepage string `json:"homepage"`
- Group string `json:"group"`
- License string `json:"license"`
- Goarch string `json:"goarch"`
- Replaces []string `json:"replaces"`
- Depends []string `json:"depends"`
- Recommends []string `json:"recommends"`
-
- EmptyDirs []string `json:"emptyDirs"` // rpm destination path
- ConfigFiles map[string]string `json:"configFiles"` // repo-relative source path, rpm destination path
-
- Build func(out string) `json:"build"`
-}
-
-func Build(p Package) (foutpath string, err error) {
+func Build(p pkgmeta.Package) (foutpath string, err error) {
defer func() {
if r := recover(); r != nil {
switch r.(type) {
diff --git a/cmd/yeet/internal/pkgmeta/package.go b/cmd/yeet/internal/pkgmeta/package.go
new file mode 100644
index 0000000..b5d7fcb
--- /dev/null
+++ b/cmd/yeet/internal/pkgmeta/package.go
@@ -0,0 +1,19 @@
+package pkgmeta
+
+type Package struct {
+ Name string `json:"name"`
+ Version string `json:"version"`
+ Description string `json:"description"`
+ Homepage string `json:"homepage"`
+ Group string `json:"group"`
+ License string `json:"license"`
+ Goarch string `json:"goarch"`
+ Replaces []string `json:"replaces"`
+ Depends []string `json:"depends"`
+ Recommends []string `json:"recommends"`
+
+ EmptyDirs []string `json:"emptyDirs"` // rpm destination path
+ ConfigFiles map[string]string `json:"configFiles"` // repo-relative source path, rpm destination path
+
+ Build func(out string) `json:"build"`
+}
diff --git a/cmd/yeet/main.go b/cmd/yeet/main.go
index dd18d33..a97d9a1 100644
--- a/cmd/yeet/main.go
+++ b/cmd/yeet/main.go
@@ -16,7 +16,9 @@ import (
"strings"
"github.com/dop251/goja"
+ "within.website/x/cmd/yeet/internal/mkdeb"
"within.website/x/cmd/yeet/internal/mkrpm"
+ "within.website/x/cmd/yeet/internal/pkgmeta"
"within.website/x/internal"
"within.website/x/internal/appsluggr"
"within.website/x/internal/kahless"
@@ -176,6 +178,16 @@ func main() {
lg := log.New(writer.LineSplitting(writer.PrefixWriter("[yeet] ", os.Stdout)), "", 0)
+ vm.Set("deb", map[string]any{
+ "build": func(p pkgmeta.Package) string {
+ foutpath, err := mkdeb.Build(p)
+ if err != nil {
+ panic(err)
+ }
+ return foutpath
+ },
+ })
+
vm.Set("docker", map[string]any{
"build": dockerbuild,
"load": dockerload,
@@ -260,7 +272,7 @@ func main() {
})
vm.Set("rpm", map[string]any{
- "build": func(p mkrpm.Package) string {
+ "build": func(p pkgmeta.Package) string {
foutpath, err := mkrpm.Build(p)
if err != nil {
panic(err)
diff --git a/cmd/yeet/yeetfile.js b/cmd/yeet/yeetfile.js
index 0dcd8fc..da0f265 100644
--- a/cmd/yeet/yeetfile.js
+++ b/cmd/yeet/yeetfile.js
@@ -1,13 +1,15 @@
go.install();
-["amd64", "arm64"].forEach(goarch => rpm.build({
- name: "yeet",
- description: "Yeet out actions with maximum haste!",
- homepage: "https://within.website",
- license: "CC0",
- goarch,
+["amd64", "arm64"].forEach(goarch => {
+ [deb, rpm].forEach(method => method.build({
+ name: "yeet",
+ description: "Yeet out actions with maximum haste!",
+ homepage: "https://within.website",
+ license: "CC0",
+ goarch,
- build: (out) => {
- go.build("-o", `${out}/usr/bin/yeet`);
- },
-})); \ No newline at end of file
+ build: (out) => {
+ go.build("-o", `${out}/usr/bin/yeet`);
+ },
+ }));
+}); \ No newline at end of file