From 141bd22d0de8a29fe29f3201245d51b306140c75 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Fri, 5 Dec 2025 00:09:54 +1100 Subject: [PATCH 01/12] add pokeprite repo as submodule --- .gitmodules | 3 +++ build/pokesprite | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 build/pokesprite diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..fd254cc7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "build/pokesprite"] + path = build/pokesprite + url = git@github.com:msikma/pokesprite diff --git a/build/pokesprite b/build/pokesprite new file mode 160000 index 00000000..c5aaa610 --- /dev/null +++ b/build/pokesprite @@ -0,0 +1 @@ +Subproject commit c5aaa610ff2acdf7fd8e2dccd181bca8be9fcb3e From 6cea905d337c44324df8acaf218848279480076e Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Fri, 5 Dec 2025 01:42:08 +1100 Subject: [PATCH 02/12] move cowfile building out of dockerfile - it causes the image to be pretty big - can use the submodule dir instead - alter the makefile task to use the new script --- build/Dockerfile | 27 ++++++--------------------- build/Makefile | 16 +++++++++------- build/scripts/build_cowfiles.sh | 13 +++++++++++++ 3 files changed, 28 insertions(+), 28 deletions(-) create mode 100755 build/scripts/build_cowfiles.sh diff --git a/build/Dockerfile b/build/Dockerfile index 0638caf6..24d8da27 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -15,30 +15,15 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* \ && rm -rf /tmp/* /var/tmp/* + +RUN useradd u -m + WORKDIR /usr/local/src/ -ADD src/ /usr/local/src/src/ ADD go.* /usr/local/src/ +ADD src/ /usr/local/src/src/ RUN go mod tidy \ && go get -v github.com/mitchellh/go-wordwrap \ - && go install gotest.tools/gotestsum@latest - -RUN useradd u -m -USER u - -RUN git clone -q --depth 1 https://github.com/msikma/pokesprite /tmp/original/pokesprite - -ARG DEBUG -ENV DEBUG=$DEBUG -RUN echo "Debug mode is set to: '$DEBUG'" -# Convert all of the pokesprite .pngs -> cowfiles for the terminal -RUN go run /usr/local/src/src/bin/convert/png_convert.go \ - -from /tmp/original/pokesprite/ \ - -to /tmp/cows/ \ - -padding 4 \ - -skip '["resources/", "misc/", "icons/", "items/", "items-outline/"]' \ - && mv -v /tmp/cows/pokemon-gen8 /tmp/cows/gen8 \ - && mv -v /tmp/cows/pokemon-gen7x /tmp/cows/gen7x \ - && cat /tmp/original/pokesprite/data/pokemon.json | jq -c .[] > /tmp/cows/pokemon.json \ - && rm -rf /tmp/original/pokesprite + && go install gotest.tools/gotestsum@latest \ + && chown -R u:u /go ADD . . diff --git a/build/Makefile b/build/Makefile index df9482ca..003f381e 100644 --- a/build/Makefile +++ b/build/Makefile @@ -29,14 +29,16 @@ build/docker: build/cows: @$(echo) -e "\e[48;5;30m> Building cows\e[0m" @rm -rf cows.tar.gz cows/ - @docker rm -f pokebuilder > /dev/null 2>&1 - @docker create \ + @mkdir -p cows/ + docker run --rm \ --platform linux/amd64 \ - --name pokebuilder $(DOCKER_IMAGE) - docker cp pokebuilder:$(DOCKER_OUTPUT_DIR)/ cows/ - @tar czf cows.tar.gz cows/ - @rm -rf cows/ - @docker rm -f pokebuilder > /dev/null 2>&1 + -v $(PWD)/../:/usr/local/src \ + -v $(PWD)/pokesprite:/tmp/original/pokesprite \ + -v $(PWD)/cows:/tmp/cows \ + -u u \ + $(DOCKER_IMAGE) \ + build/scripts/build_cowfiles.sh + @tar -czf cows.tar.gz ./cows @du -sh cows.tar.gz # generate embedded bin files for category/metadata/the actual pokemon diff --git a/build/scripts/build_cowfiles.sh b/build/scripts/build_cowfiles.sh new file mode 100755 index 00000000..735da7ea --- /dev/null +++ b/build/scripts/build_cowfiles.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -euo pipefail + +# Convert all of the pokesprite .pngs -> cowfiles for the terminal +go run /usr/local/src/src/bin/convert/png_convert.go \ + -from /tmp/original/pokesprite/ \ + -to /tmp/cows/ \ + -padding 4 \ + -skip '["resources/", "misc/", "icons/", "items/", "items-outline/"]' \ + && mv -v /tmp/cows/pokemon-gen8 /tmp/cows/gen8 \ + && mv -v /tmp/cows/pokemon-gen7x /tmp/cows/gen7x \ + && cat /tmp/original/pokesprite/data/pokemon.json | jq -c .[] > /tmp/cows/pokemon.json From c889b118f2fc5e059f56e9039881c5ea670329d2 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Fri, 5 Dec 2025 01:43:40 +1100 Subject: [PATCH 03/12] make cowfile generation multithreaded - use 1 worker per core - add better error detection and logging for conversions --- src/bin/convert/png_convert.go | 87 ++++++++++++++++++++++++---------- src/pokedex/convert.go | 83 +++++++++++++++++++++++++------- 2 files changed, 128 insertions(+), 42 deletions(-) diff --git a/src/bin/convert/png_convert.go b/src/bin/convert/png_convert.go index ae4bc846..bd43f5e0 100644 --- a/src/bin/convert/png_convert.go +++ b/src/bin/convert/png_convert.go @@ -6,7 +6,11 @@ import ( "fmt" "os" "path/filepath" + "runtime" "strings" + "sync" + + "github.com/schollz/progressbar/v3" "github.com/tmck-code/pokesay/src/bin" "github.com/tmck-code/pokesay/src/pokedex" @@ -41,44 +45,33 @@ func parseArgs() CowBuildArgs { return args } -func main() { - args := parseArgs() - - fpaths := pokedex.FindFiles(args.FromDir, ".png", args.SkipDirs) - - // Ensure that the destination dir exists - os.MkdirAll(args.ToDir, 0755) - - fmt.Println("Converting PNGs -> cowfiles") - pbar := bin.NewProgressBar(len(fpaths)) - - allData := make([]string, 0, len(fpaths)) - nDuplicates, nFailures := 0, 0 +func worker(args CowBuildArgs, jobs <-chan string, pbar *progressbar.ProgressBar, dataSet map[string]struct{}, nDuplicates *int, nFailures *int, mu *sync.Mutex, wg *sync.WaitGroup) { + defer wg.Done() - for _, f := range fpaths { + for f := range jobs { data, err := pokedex.ConvertPngToCow(args.FromDir, f, args.ToDir, args.Padding) + if err != nil { - nFailures++ + mu.Lock() + *nFailures++ + mu.Unlock() + pbar.Add(1) continue } // check if this cawfile is a duplicate of one that has already been written - found := false - for _, existingData := range allData { - if existingData == data { - found = true - break - } - } - if found { + mu.Lock() + if _, found := dataSet[data]; found { if args.Debug { fmt.Println("Skipping duplicate data for", f) } - nDuplicates++ + *nDuplicates++ + mu.Unlock() pbar.Add(1) continue } - allData = append(allData, data) + dataSet[data] = struct{}{} + mu.Unlock() destDirpath := filepath.Join( args.ToDir, @@ -91,6 +84,50 @@ func main() { pokedex.WriteToCowfile(data, destDirpath, destFpath) pbar.Add(1) } +} + +func main() { + args := parseArgs() + + fpaths := pokedex.FindFiles(args.FromDir, ".png", args.SkipDirs) + + // Ensure that the destination dir exists + os.MkdirAll(args.ToDir, 0755) + + fmt.Println("Converting PNGs -> cowfiles") + pbar := bin.NewProgressBar(len(fpaths)) + + dataSet := make(map[string]struct{}) + nDuplicates, nFailures := 0, 0 + + nWorkers := runtime.NumCPU() + var wg sync.WaitGroup + var mu sync.Mutex + + // Create a channel to distribute work + jobs := make(chan string, len(fpaths)) + + // Send all file paths to the jobs channel + for _, f := range fpaths { + jobs <- f + } + close(jobs) + + // Start worker goroutines + for w := 0; w < nWorkers; w++ { + wg.Add(1) + go worker(args, jobs, &pbar, dataSet, &nDuplicates, &nFailures, &mu, &wg) + } + + // Wait for all workers to finish + wg.Wait() fmt.Println("\nFinished converting", len(fpaths), "pokesprite PNGs -> cowfiles") fmt.Println("(skipped", nDuplicates, "duplicates and", nFailures, "failures)") + + if args.Debug && len(pokedex.Failures) > 0 { + fmt.Println("failures:") + for _, f := range pokedex.Failures { + fmt.Println(" -", f) + } + } } diff --git a/src/pokedex/convert.go b/src/pokedex/convert.go index 6ce84729..5c79cb84 100644 --- a/src/pokedex/convert.go +++ b/src/pokedex/convert.go @@ -2,7 +2,11 @@ package pokedex import ( "bufio" + "crypto/rand" + "encoding/hex" + "errors" "fmt" + "io" "os" "os/exec" "path/filepath" @@ -10,7 +14,7 @@ import ( ) var ( - failures []string + Failures []string COLOUR_RESET string = fmt.Sprintf("%s[%dm\n", "\x1b", 39) ) @@ -33,18 +37,45 @@ func FindFiles(dirpath string, ext string, skip []string) []string { // img2xterm converts an image to a cowfile, returning the result as a byte slice func img2xterm(sourceFpath string) ([]byte, error) { - return exec.Command("bash", "-c", fmt.Sprintf("/usr/local/bin/img2xterm %s", sourceFpath)).Output() + return exec.Command("bash", "-c", fmt.Sprintf("/usr/local/bin/img2xterm %s 2>&1", sourceFpath)).Output() } // autoCrop trims the whitespace from the edges of an image, in place -func autoCrop(sourceFpath string) { - destFpath := fmt.Sprintf("/tmp/%s", filepath.Base(sourceFpath)) - _, err := exec.Command( - "bash", "-c", fmt.Sprintf("/usr/bin/convert %s -trim +repage %s", sourceFpath, destFpath), +func autoCrop(sourceFpath string) error { + // Generate a random suffix to avoid conflicts when running in parallel + randomBytes := make([]byte, 8) + rand.Read(randomBytes) + randomSuffix := hex.EncodeToString(randomBytes) + + destFpath := fmt.Sprintf("/tmp/%s-%s", randomSuffix, filepath.Base(sourceFpath)) + // fmt.Println("Auto-cropping", sourceFpath, "->", destFpath) + output, err := exec.Command( + "bash", "-c", fmt.Sprintf("/usr/bin/convert %s -trim +repage %s 2>&1", sourceFpath, destFpath), ).Output() - Check(err) + if err != nil { + return fmt.Errorf("auto-crop failed for %s: (%v) - %s", sourceFpath, err, strings.Trim(string(output), "\n")) + } + + srcFile, err := os.Open(destFpath) + if err != nil { + return fmt.Errorf("failed to open cropped file %s: (%v)", destFpath, err) + } + defer srcFile.Close() + + destFile, err := os.Create(sourceFpath) + if err != nil { + return fmt.Errorf("failed to open source file %s for writing: (%v)", sourceFpath, err) + } + defer destFile.Close() + + _, err = io.Copy(destFile, srcFile) + if err != nil { + return fmt.Errorf("failed to copy cropped data to %s: (%v)", sourceFpath, err) + } - os.Rename(destFpath, sourceFpath) + // Clean up the temporary file + os.Remove(destFpath) + return nil } func countLineLeftPadding(line string) int { @@ -110,25 +141,43 @@ func padLeft(cowfile []byte, n int) []string { func ConvertPngToCow(sourceDirpath string, sourceFpath string, destDirpath string, extraPadding int) (string, error) { // Trim the whitespace from the edges of the images. This helps with the conversion - autoCrop(sourceFpath) + err := autoCrop(sourceFpath) + if err != nil { + // If autoCrop fails, still try to convert the original image + Failures = append(Failures, string(err.Error())) + return "", err + } + // Some conversions are failing with something about colour channels - // Can't be bothered resolving atm, so just skip past any failed conversions - converted, _ := img2xterm(sourceFpath) + output, err := img2xterm(sourceFpath) + if err != nil { + failureMsg := fmt.Sprintf("failed to convert %s: (%v) - %s", sourceFpath, err, strings.Trim(string(output), "\n")) + Failures = append(Failures, failureMsg) + return "", errors.New(failureMsg) + } - if len(converted) == 0 { - failures = append(failures, sourceFpath) - return "", fmt.Errorf("failed to convert %s", sourceFpath) + if len(output) == 0 { + failureMsg := fmt.Sprintf("failed to convert %s: no output", sourceFpath) + Failures = append(Failures, failureMsg) + return "", errors.New(failureMsg) } - final := stripEmptyLines(padLeft(converted, extraPadding)) + final := stripEmptyLines(padLeft(output, extraPadding)) return strings.Join(final, "\n") + COLOUR_RESET, nil } func WriteToCowfile(data string, destDirpath string, destFpath string) { // Ensure that the destination dir exists - os.MkdirAll(destDirpath, 0755) + err := os.MkdirAll(destDirpath, 0755) + if err != nil { + fmt.Printf("Failed to create directory %s: %v\n", destDirpath, err) + Check(err) + } ostream, err := os.Create(destFpath) - Check(err) + if err != nil { + fmt.Printf("Failed to create file %s: %v\n", destFpath, err) + Check(err) + } defer ostream.Close() writer := bufio.NewWriter(ostream) From 9dc47e35c930a4b0316dbbb46ed606aba980a2c4 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Fri, 5 Dec 2025 02:10:59 +1100 Subject: [PATCH 04/12] don't overwrite original pokesprite files - use a tmp dir for this --- build/scripts/build_cowfiles.sh | 7 ++++-- src/bin/convert/png_convert.go | 14 +++++++----- src/pokedex/convert.go | 38 ++++++++------------------------- 3 files changed, 23 insertions(+), 36 deletions(-) diff --git a/build/scripts/build_cowfiles.sh b/build/scripts/build_cowfiles.sh index 735da7ea..ed47c46b 100755 --- a/build/scripts/build_cowfiles.sh +++ b/build/scripts/build_cowfiles.sh @@ -2,12 +2,15 @@ set -euo pipefail +mkdir -p /tmp/convert/ + # Convert all of the pokesprite .pngs -> cowfiles for the terminal go run /usr/local/src/src/bin/convert/png_convert.go \ -from /tmp/original/pokesprite/ \ + -tmpDir /tmp/convert/ \ -to /tmp/cows/ \ -padding 4 \ -skip '["resources/", "misc/", "icons/", "items/", "items-outline/"]' \ - && mv -v /tmp/cows/pokemon-gen8 /tmp/cows/gen8 \ - && mv -v /tmp/cows/pokemon-gen7x /tmp/cows/gen7x \ + && mv -v /tmp/cows/pokemon-gen8 /tmp/cows/gen8 > /dev/null \ + && mv -v /tmp/cows/pokemon-gen7x /tmp/cows/gen7x > /dev/null \ && cat /tmp/original/pokesprite/data/pokemon.json | jq -c .[] > /tmp/cows/pokemon.json diff --git a/src/bin/convert/png_convert.go b/src/bin/convert/png_convert.go index bd43f5e0..4158cb1a 100644 --- a/src/bin/convert/png_convert.go +++ b/src/bin/convert/png_convert.go @@ -9,6 +9,7 @@ import ( "runtime" "strings" "sync" + "time" "github.com/schollz/progressbar/v3" @@ -22,6 +23,7 @@ var ( type CowBuildArgs struct { FromDir string + TmpDir string ToDir string SkipDirs []string Padding int @@ -30,13 +32,14 @@ type CowBuildArgs struct { func parseArgs() CowBuildArgs { fromDir := flag.String("from", ".", "from dir") + tmpDir := flag.String("tmpDir", "/tmp/convert/", "temporary directory for intermediate files") toDir := flag.String("to", ".", "to dir") skipDirs := flag.String("skip", "'[\"resources\"]'", "JSON array of dir patterns to skip converting") padding := flag.Int("padding", 2, "the number of spaces to pad from the left") flag.Parse() - args := CowBuildArgs{FromDir: *fromDir, ToDir: *toDir, Padding: *padding, Debug: DEBUG} + args := CowBuildArgs{FromDir: *fromDir, TmpDir: *tmpDir, ToDir: *toDir, Padding: *padding, Debug: DEBUG} json.Unmarshal([]byte(*skipDirs), &args.SkipDirs) if args.Debug { @@ -49,13 +52,13 @@ func worker(args CowBuildArgs, jobs <-chan string, pbar *progressbar.ProgressBar defer wg.Done() for f := range jobs { - data, err := pokedex.ConvertPngToCow(args.FromDir, f, args.ToDir, args.Padding) + data, err := pokedex.ConvertPngToCow(args.FromDir, f, args.TmpDir, args.ToDir, args.Padding) + pbar.Add(1) if err != nil { mu.Lock() *nFailures++ mu.Unlock() - pbar.Add(1) continue } @@ -67,7 +70,6 @@ func worker(args CowBuildArgs, jobs <-chan string, pbar *progressbar.ProgressBar } *nDuplicates++ mu.Unlock() - pbar.Add(1) continue } dataSet[data] = struct{}{} @@ -82,7 +84,6 @@ func worker(args CowBuildArgs, jobs <-chan string, pbar *progressbar.ProgressBar destFpath := filepath.Join(destDirpath, strings.ReplaceAll(filepath.Base(f), ".png", ".cow")) pokedex.WriteToCowfile(data, destDirpath, destFpath) - pbar.Add(1) } } @@ -124,6 +125,9 @@ func main() { fmt.Println("\nFinished converting", len(fpaths), "pokesprite PNGs -> cowfiles") fmt.Println("(skipped", nDuplicates, "duplicates and", nFailures, "failures)") + // wait for progress bar to finish + time.Sleep(100 * time.Millisecond) + if args.Debug && len(pokedex.Failures) > 0 { fmt.Println("failures:") for _, f := range pokedex.Failures { diff --git a/src/pokedex/convert.go b/src/pokedex/convert.go index 5c79cb84..9b8a0e68 100644 --- a/src/pokedex/convert.go +++ b/src/pokedex/convert.go @@ -6,7 +6,6 @@ import ( "encoding/hex" "errors" "fmt" - "io" "os" "os/exec" "path/filepath" @@ -41,41 +40,22 @@ func img2xterm(sourceFpath string) ([]byte, error) { } // autoCrop trims the whitespace from the edges of an image, in place -func autoCrop(sourceFpath string) error { +func autoCrop(sourceFpath string, tmpDirpath string) (string, error) { // Generate a random suffix to avoid conflicts when running in parallel randomBytes := make([]byte, 8) rand.Read(randomBytes) randomSuffix := hex.EncodeToString(randomBytes) - destFpath := fmt.Sprintf("/tmp/%s-%s", randomSuffix, filepath.Base(sourceFpath)) + destFpath := fmt.Sprintf("%s/%s-%s", tmpDirpath, randomSuffix, filepath.Base(sourceFpath)) // fmt.Println("Auto-cropping", sourceFpath, "->", destFpath) output, err := exec.Command( "bash", "-c", fmt.Sprintf("/usr/bin/convert %s -trim +repage %s 2>&1", sourceFpath, destFpath), ).Output() if err != nil { - return fmt.Errorf("auto-crop failed for %s: (%v) - %s", sourceFpath, err, strings.Trim(string(output), "\n")) + return "", fmt.Errorf("auto-crop failed for %s: (%v) - %s", sourceFpath, err, strings.Trim(string(output), "\n")) } - srcFile, err := os.Open(destFpath) - if err != nil { - return fmt.Errorf("failed to open cropped file %s: (%v)", destFpath, err) - } - defer srcFile.Close() - - destFile, err := os.Create(sourceFpath) - if err != nil { - return fmt.Errorf("failed to open source file %s for writing: (%v)", sourceFpath, err) - } - defer destFile.Close() - - _, err = io.Copy(destFile, srcFile) - if err != nil { - return fmt.Errorf("failed to copy cropped data to %s: (%v)", sourceFpath, err) - } - - // Clean up the temporary file - os.Remove(destFpath) - return nil + return destFpath, nil } func countLineLeftPadding(line string) int { @@ -138,10 +118,10 @@ func padLeft(cowfile []byte, n int) []string { return converted } -func ConvertPngToCow(sourceDirpath string, sourceFpath string, destDirpath string, extraPadding int) (string, error) { +func ConvertPngToCow(sourceDirpath string, sourceFpath string, tmpDirpath string, destDirpath string, extraPadding int) (string, error) { // Trim the whitespace from the edges of the images. This helps with the conversion - err := autoCrop(sourceFpath) + tmpFpath, err := autoCrop(sourceFpath, tmpDirpath) if err != nil { // If autoCrop fails, still try to convert the original image Failures = append(Failures, string(err.Error())) @@ -149,15 +129,15 @@ func ConvertPngToCow(sourceDirpath string, sourceFpath string, destDirpath strin } // Some conversions are failing with something about colour channels - output, err := img2xterm(sourceFpath) + output, err := img2xterm(tmpFpath) if err != nil { - failureMsg := fmt.Sprintf("failed to convert %s: (%v) - %s", sourceFpath, err, strings.Trim(string(output), "\n")) + failureMsg := fmt.Sprintf("failed to convert %s: (%v) - %s", tmpFpath, err, strings.Trim(string(output), "\n")) Failures = append(Failures, failureMsg) return "", errors.New(failureMsg) } if len(output) == 0 { - failureMsg := fmt.Sprintf("failed to convert %s: no output", sourceFpath) + failureMsg := fmt.Sprintf("failed to convert %s: no output", tmpFpath) Failures = append(Failures, failureMsg) return "", errors.New(failureMsg) } From ce36ca2d3f628146b11837440f571fcdc21d0e3a Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Fri, 5 Dec 2025 02:19:28 +1100 Subject: [PATCH 05/12] update other makefile tasks - use user u instead of root --- build/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/build/Makefile b/build/Makefile index 003f381e..bf59dade 100644 --- a/build/Makefile +++ b/build/Makefile @@ -30,7 +30,7 @@ build/cows: @$(echo) -e "\e[48;5;30m> Building cows\e[0m" @rm -rf cows.tar.gz cows/ @mkdir -p cows/ - docker run --rm \ + @docker run --rm \ --platform linux/amd64 \ -v $(PWD)/../:/usr/local/src \ -v $(PWD)/pokesprite:/tmp/original/pokesprite \ @@ -45,9 +45,13 @@ build/cows: build/assets: @$(echo) -e "\e[48;5;30m> Building assets\e[0m" @mkdir -p $(PWD)/assets + @rm -rf $(PWD)/cows/ + @tar -xzf cows.tar.gz @docker run --rm \ -v $(PWD)/../:/usr/local/src \ + -v $(PWD)/cows:/tmp/cows \ --platform linux/amd64 \ + -u u \ --name pokesay \ $(DOCKER_IMAGE) \ build/scripts/build_assets.sh @@ -61,7 +65,7 @@ build/bin: -e VERSION=$(VERSION) \ -e DEBUG=$(DEBUG) \ --platform linux/amd64 \ - --user root \ + --user u \ --name pokesay \ $(DOCKER_IMAGE) \ /usr/local/src/build/scripts/build_bin.sh From c93d39b73525e614b6cdab06aae543be6b54d6f7 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Fri, 5 Dec 2025 02:33:14 +1100 Subject: [PATCH 06/12] update github workflow - build cows - mount cows when building assets --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e8354a1c..412604d4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,8 +16,10 @@ jobs: run: docker pull ghcr.io/tmck-code/pokesay:latest - name: Make dist directory run: mkdir -p dist/bin/ dist/packages/ dist/tarballs/ + - name: Build cows + run: docker run -v ${PWD}:/usr/local/src -v ${PWD}/build/cows:/tmp/cows -v $(PWD)/build/pokesprite:/tmp/original/pokesprite -u root --platform linux/amd64 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_cows.sh - name: Build go binary assets - run: docker run -v ${PWD}:/usr/local/src -u root --platform linux/amd64 -e VERSION=0.1 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_assets.sh + run: docker run -v ${PWD}:/usr/local/src -v ${PWD}/build/cows:/tmp/cows -u root --platform linux/amd64 -e VERSION=0.1 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_assets.sh - name: Build go binaries run: docker run -v ${PWD}:/usr/local/src -u root --platform linux/amd64 -e VERSION=0.1 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_bin.sh - name: Check build From 0ddcd3a016896730b490450424350685e262692b Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Fri, 5 Dec 2025 02:35:20 +1100 Subject: [PATCH 07/12] typo --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 412604d4..391401b6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: - name: Make dist directory run: mkdir -p dist/bin/ dist/packages/ dist/tarballs/ - name: Build cows - run: docker run -v ${PWD}:/usr/local/src -v ${PWD}/build/cows:/tmp/cows -v $(PWD)/build/pokesprite:/tmp/original/pokesprite -u root --platform linux/amd64 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_cows.sh + run: docker run -v ${PWD}:/usr/local/src -v ${PWD}/build/cows:/tmp/cows -v ${PWD}/build/pokesprite:/tmp/original/pokesprite -u root --platform linux/amd64 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_cows.sh - name: Build go binary assets run: docker run -v ${PWD}:/usr/local/src -v ${PWD}/build/cows:/tmp/cows -u root --platform linux/amd64 -e VERSION=0.1 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_assets.sh - name: Build go binaries From 12a37652d5a4190b8b0896665151b0c52edb6d51 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Fri, 5 Dec 2025 02:36:50 +1100 Subject: [PATCH 08/12] another typo --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 391401b6..7858353e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: - name: Make dist directory run: mkdir -p dist/bin/ dist/packages/ dist/tarballs/ - name: Build cows - run: docker run -v ${PWD}:/usr/local/src -v ${PWD}/build/cows:/tmp/cows -v ${PWD}/build/pokesprite:/tmp/original/pokesprite -u root --platform linux/amd64 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_cows.sh + run: docker run -v ${PWD}:/usr/local/src -v ${PWD}/build/cows:/tmp/cows -v ${PWD}/build/pokesprite:/tmp/original/pokesprite -u root --platform linux/amd64 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_cowfiles.sh - name: Build go binary assets run: docker run -v ${PWD}:/usr/local/src -v ${PWD}/build/cows:/tmp/cows -u root --platform linux/amd64 -e VERSION=0.1 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_assets.sh - name: Build go binaries From 7e7d6e0ca1c6c3a6c8a004b181707b48925903fb Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Fri, 5 Dec 2025 02:39:53 +1100 Subject: [PATCH 09/12] use actions/checkout to pull repo and submodules --- .github/workflows/main.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7858353e..c2224b8e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,10 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull image from ghcr.io - run: docker pull ghcr.io/tmck-code/pokesay:latest + - name: Checkout repository and submodules + uses: actions/checkout@v4 + with: + submodules: recursive - name: Make dist directory run: mkdir -p dist/bin/ dist/packages/ dist/tarballs/ - name: Build cows From 8bd9913734725736cc3a85f22e7971705ff19706 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Fri, 5 Dec 2025 02:41:23 +1100 Subject: [PATCH 10/12] replace existing checkout step --- .github/workflows/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c2224b8e..50760255 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,18 +4,18 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive - name: Log in to the Container registry uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Checkout repository and submodules - uses: actions/checkout@v4 - with: - submodules: recursive + - name: Pull image from ghcr.io + run: docker pull ghcr.io/tmck-code/pokesay:latest - name: Make dist directory run: mkdir -p dist/bin/ dist/packages/ dist/tarballs/ - name: Build cows From f50e7a5080e8f5caf9e026bdb451f3e1660caace Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Fri, 5 Dec 2025 02:42:44 +1100 Subject: [PATCH 11/12] unit test before building binaries --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 50760255..26d5743f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,6 +20,8 @@ jobs: run: mkdir -p dist/bin/ dist/packages/ dist/tarballs/ - name: Build cows run: docker run -v ${PWD}:/usr/local/src -v ${PWD}/build/cows:/tmp/cows -v ${PWD}/build/pokesprite:/tmp/original/pokesprite -u root --platform linux/amd64 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_cowfiles.sh + - name: Run unit tests + run: docker run -v ${PWD}:/usr/local/src -u root ghcr.io/tmck-code/pokesay:latest gotestsum --debug - name: Build go binary assets run: docker run -v ${PWD}:/usr/local/src -v ${PWD}/build/cows:/tmp/cows -u root --platform linux/amd64 -e VERSION=0.1 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_assets.sh - name: Build go binaries @@ -28,8 +30,6 @@ jobs: run: ls -alh dist/bin - name: Test build run: echo w | ./dist/bin/pokesay-0.1-linux-amd64 - - name: Run unit tests - run: docker run -v ${PWD}:/usr/local/src -u root ghcr.io/tmck-code/pokesay:latest gotestsum --debug - name: Build deb package run: docker run -v ${PWD}:/usr/local/src -u root -e VERSION=0.1 -e DEBUG=1 ghcr.io/tmck-code/pokesay:latest bash -c "./build/scripts/build_packages.sh deb" - name: Build arch package From b0492ffb5398e14dee8dc8d4957956f9a0ec04c3 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Fri, 5 Dec 2025 02:44:22 +1100 Subject: [PATCH 12/12] unit test after assets build --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 26d5743f..ae7d1b3f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,10 +20,10 @@ jobs: run: mkdir -p dist/bin/ dist/packages/ dist/tarballs/ - name: Build cows run: docker run -v ${PWD}:/usr/local/src -v ${PWD}/build/cows:/tmp/cows -v ${PWD}/build/pokesprite:/tmp/original/pokesprite -u root --platform linux/amd64 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_cowfiles.sh - - name: Run unit tests - run: docker run -v ${PWD}:/usr/local/src -u root ghcr.io/tmck-code/pokesay:latest gotestsum --debug - name: Build go binary assets run: docker run -v ${PWD}:/usr/local/src -v ${PWD}/build/cows:/tmp/cows -u root --platform linux/amd64 -e VERSION=0.1 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_assets.sh + - name: Run unit tests + run: docker run -v ${PWD}:/usr/local/src -u root ghcr.io/tmck-code/pokesay:latest gotestsum --debug - name: Build go binaries run: docker run -v ${PWD}:/usr/local/src -u root --platform linux/amd64 -e VERSION=0.1 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_bin.sh - name: Check build