aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2023-08-11 04:02:40 -0700
committerXe Iaso <me@xeiaso.net>2023-08-11 04:02:56 -0700
commitab469b10678483b8ad41bd994668eab2825ba514 (patch)
tree18c089a42f5da3884145b6c73301703e59cd2835 /cmd
parent16f60b165a114d4c41581257b513665ea16e06f7 (diff)
downloadx-ab469b10678483b8ad41bd994668eab2825ba514.tar.xz
x-ab469b10678483b8ad41bd994668eab2825ba514.zip
cmd: add yeet for build automation
Diffstat (limited to 'cmd')
-rw-r--r--cmd/johaus/build.go5
-rw-r--r--cmd/whoisfront/yeetfile.js6
-rw-r--r--cmd/within.website/config.ts37
-rw-r--r--cmd/within.website/yeetfile.js8
-rw-r--r--cmd/xedn/yeetfile.js4
-rw-r--r--cmd/yeet/main.go172
-rw-r--r--cmd/yeet/yeetfile.js5
7 files changed, 198 insertions, 39 deletions
diff --git a/cmd/johaus/build.go b/cmd/johaus/build.go
index 9e2b5ae..8f7caea 100644
--- a/cmd/johaus/build.go
+++ b/cmd/johaus/build.go
@@ -1,4 +1,5 @@
-//+build ignore
+//go:build ignore
+// +build ignore
// Builds and deploys the application to minipaas.
package main
@@ -30,7 +31,7 @@ func main() {
defer fin.Close()
fname := "johaus-" + yeet.DateTag + ".tar.gz"
- pubURL, err := kahless.CopyFile(fname, fin)
+ pubURL, err := kahless.CopySlug(fname, fin)
if err != nil {
log.Fatal(err)
}
diff --git a/cmd/whoisfront/yeetfile.js b/cmd/whoisfront/yeetfile.js
new file mode 100644
index 0000000..ef4750a
--- /dev/null
+++ b/cmd/whoisfront/yeetfile.js
@@ -0,0 +1,6 @@
+yeet.setenv("GOOS", "linux");
+yeet.setenv("GOARCH", "amd64");
+
+go.build();
+slug.build("whoisfront");
+log.info(nix.hashURL(slug.push("whoisfront"))); \ No newline at end of file
diff --git a/cmd/within.website/config.ts b/cmd/within.website/config.ts
index e79434d..e69de29 100644
--- a/cmd/within.website/config.ts
+++ b/cmd/within.website/config.ts
@@ -1,37 +0,0 @@
-export interface Repo {
- kind: "gitea" | "github";
- domain: string;
- user: string;
- repo: string;
- description: string;
-}
-
-const githubRepo = (name: string, description: string): Repo => {
- return {
- kind: "github",
- domain: "github.com",
- user: "Xe",
- repo: name,
- description,
- };
-};
-
-const giteaRepo = (name: string, description: string): Repo => {
- return {
- kind: "gitea",
- domain: "tulpa.dev",
- user: "cadey",
- repo: name,
- description,
- };
-};
-
-const repos: Repo[] = [
- githubRepo("derpigo", "A Derpibooru/Furbooru API client in Go. This is used to monitor Derpibooru/Furbooru for images by artists I care about and archive them."),
- githubRepo("eclier", "A command router for Go programs that implements every command in Lua. This was an experiment for making extensible command-line applications with Lua for extending them."),
- giteaRepo("gopher", "A Gopher (RFC 1436) client/server stack for Go applications. This allows users to write custom Gopher clients and servers."),
- githubRepo("ln", "The natural log function for Go: an easy package for structured logging. This is the logging stack that I use for most of my personal projects."),
- githubRepo("x", "Various experimental things. /x/ is my monorepo of side projects, hobby programming, and other explorations of how programming in Go can be."),
-];
-
-export default repos;
diff --git a/cmd/within.website/yeetfile.js b/cmd/within.website/yeetfile.js
new file mode 100644
index 0000000..394ded8
--- /dev/null
+++ b/cmd/within.website/yeetfile.js
@@ -0,0 +1,8 @@
+yeet.setenv("GOOS", "linux");
+yeet.setenv("GOARCH", "amd64");
+
+go.build();
+slug.build("within.website", {
+ "config.ts": "config.ts"
+});
+log.info(slug.push("within.website")); \ No newline at end of file
diff --git a/cmd/xedn/yeetfile.js b/cmd/xedn/yeetfile.js
new file mode 100644
index 0000000..efafff7
--- /dev/null
+++ b/cmd/xedn/yeetfile.js
@@ -0,0 +1,4 @@
+nix.build(".#docker.xedn")
+docker.load("./result")
+docker.push("registry.fly.io/xedn:latest")
+fly.deploy() \ No newline at end of file
diff --git a/cmd/yeet/main.go b/cmd/yeet/main.go
new file mode 100644
index 0000000..3889261
--- /dev/null
+++ b/cmd/yeet/main.go
@@ -0,0 +1,172 @@
+package main
+
+import (
+ "context"
+ "flag"
+ "fmt"
+ "log"
+ "os"
+ "path/filepath"
+ "runtime"
+
+ "github.com/dop251/goja"
+ "golang.org/x/exp/slog"
+ "within.website/x/internal"
+ "within.website/x/internal/appsluggr"
+ "within.website/x/internal/kahless"
+ "within.website/x/internal/yeet"
+ "within.website/x/writer"
+)
+
+var (
+ fname = flag.String("fname", "yeetfile.js", "filename for the yeetfile")
+ flyctl = flag.String("flyctl-path", flyctlPath(), "path to flyctl binary")
+)
+
+func flyctlPath() string {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return "flyctl"
+ }
+
+ homedirPath := filepath.Join(home, ".fly", "bin", "fly")
+
+ if _, err := os.Stat(homedirPath); err != nil {
+ return "flyctl"
+ }
+
+ return homedirPath
+}
+
+func runcmd(cmdName string, args ...string) string {
+ ctx := context.Background()
+
+ result, err := yeet.Output(ctx, cmdName, args...)
+ if err != nil {
+ panic(err)
+ }
+
+ return result
+}
+
+func gittag() string {
+ ctx := context.Background()
+
+ tag, err := yeet.GitTag(ctx)
+ if err != nil {
+ panic(err)
+ }
+
+ return tag
+}
+
+func dockerload(fname string) {
+ yeet.DockerLoadResult(context.Background(), fname)
+}
+
+func dockertag(org, repo, image string) string {
+ return yeet.DockerTag(context.Background(), org, repo, image)
+}
+
+func dockerbuild(tag string, args ...string) {
+ yeet.DockerBuild(context.Background(), yeet.WD, tag, args...)
+}
+
+func dockerpush(image string) {
+ yeet.DockerPush(context.Background(), image)
+}
+
+func flydeploy() {
+ runcmd(*flyctl, "deploy", "--now")
+}
+
+func nixbuild(target string) {
+ runcmd("nix", "build", target)
+}
+
+func slugbuild(bin string, extraFiles map[string]string) {
+ appsluggr.Must(bin, fmt.Sprintf("%s-%s.tar.gz", bin, yeet.DateTag), extraFiles)
+ os.Remove(bin)
+}
+
+func slugpush(bin string) string {
+ fname := fmt.Sprintf("%s-%s.tar.gz", bin, yeet.DateTag)
+ fin, err := os.Open(fname)
+ if err != nil {
+ panic(err)
+ }
+ defer fin.Close()
+ pubURL, err := kahless.CopySlug(fname, fin)
+ if err != nil {
+ panic(err)
+ }
+
+ os.Remove(fname)
+
+ return pubURL
+}
+
+func main() {
+ internal.HandleStartup()
+
+ vm := goja.New()
+
+ defer func() {
+ if r := recover(); r != nil {
+ slog.Error("error in JS", "err", r)
+ }
+ }()
+
+ data, err := os.ReadFile(*fname)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ lg := log.New(writer.LineSplitting(writer.PrefixWriter("[yeet] ", os.Stdout)), "", 0)
+
+ vm.Set("docker", map[string]any{
+ "build": dockerbuild,
+ "load": dockerload,
+ "push": dockerpush,
+ "tag": dockertag,
+ })
+
+ vm.Set("fly", map[string]any{
+ "deploy": flydeploy,
+ })
+
+ vm.Set("go", map[string]any{
+ "build": func() { runcmd("go", "build") },
+ })
+
+ vm.Set("git", map[string]any{
+ "tag": gittag,
+ })
+
+ vm.Set("log", map[string]any{
+ "info": lg.Println,
+ })
+
+ vm.Set("nix", map[string]any{
+ "build": nixbuild,
+ "hashURL": func(fileURL string) string { return runcmd("nix-prefetch-url", fileURL) },
+ })
+
+ vm.Set("slug", map[string]any{
+ "build": slugbuild,
+ "push": slugpush,
+ })
+
+ vm.Set("yeet", map[string]any{
+ "cwd": yeet.WD,
+ "datetag": yeet.DateTag,
+ "runcmd": runcmd,
+ "setenv": os.Setenv,
+ "goos": runtime.GOOS,
+ "goarch": runtime.GOARCH,
+ })
+
+ if _, err := vm.RunScript(*fname, string(data)); err != nil {
+ log.Fatal(err)
+ }
+}
diff --git a/cmd/yeet/yeetfile.js b/cmd/yeet/yeetfile.js
new file mode 100644
index 0000000..744d6c1
--- /dev/null
+++ b/cmd/yeet/yeetfile.js
@@ -0,0 +1,5 @@
+log.info("cwd", yeet.cwd);
+
+log.info(yeet.runcmd("ls"))
+
+log.info(yeet.goos, yeet.goarch) \ No newline at end of file