Skip to content
Merged
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
- name: Make dist directory
run: mkdir -p dist/bin/ dist/packages/ dist/tarballs/
- name: Build go binary assets
run: docker run -v ${PWD}:/usr/local/src -e VERSION=0.1 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_assets.sh
run: docker run -v ${PWD}:/usr/local/src --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 -e VERSION=0.1 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_bin.sh
run: docker run -v ${PWD}:/usr/local/src --platform linux/amd64 -e VERSION=0.1 ghcr.io/tmck-code/pokesay:latest ./build/scripts/build_bin.sh
- name: Check build
run: ls -alh dist/bin
- name: Test build
Expand Down
7 changes: 4 additions & 3 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ WORKDIR /usr/local/src
ENV DEBIAN_FRONTEND=noninteractive
ENV BUILD_DEPS="make gcc"
RUN apt-get update \
&& apt-get install -y --no-install-recommends $BUILD_DEPS libmagickwand-dev ncurses-dev jq imagemagick

RUN git clone -q --depth 1 https://github.com/denilsonsa/img2xterm \
&& apt-get install -y --no-install-recommends \
$BUILD_DEPS libmagickwand-dev ncurses-dev jq imagemagick tree \
&& git clone -q --depth 1 https://github.com/denilsonsa/img2xterm \
&& (cd img2xterm && make && make install) \
&& rm -rf img2xterm \
&& apt-get purge -y $BUILD_DEPS \
Expand All @@ -23,6 +23,7 @@ RUN go mod tidy \
&& 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

Expand Down
58 changes: 38 additions & 20 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,96 @@ DOCKER_TAG ?= latest
DOCKER_IMAGE=$(DOCKER_REPO)/pokesay:$(DOCKER_TAG)
DEBUG ?= ""

ifeq (, $(shell which gecho > /dev/null 2>&1))
echo := echo
else
echo := gecho
endif

all: build/docker build/cows build/assets test build/bin build/packages

clean:
@$(echo) -e "\e[48;5;30m> Cleaning up\e[0m"
rm -rf ../dist/ assets/ deb/ arch/ cows/ bin/

build/docker:
echo "Building $(DOCKER_IMAGE)"
docker build --platform linux/amd64 -f Dockerfile -t $(DOCKER_IMAGE) ..
@$(echo) -e "\e[48;5;30m> Building docker image $(DOCKER_IMAGE)\e[0m"
@docker build \
--platform linux/amd64 \
-f Dockerfile \
-t $(DOCKER_IMAGE) \
..

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 --name pokebuilder $(DOCKER_IMAGE)
@docker create \
--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
@docker rm -f pokebuilder > /dev/null 2>&1
@du -sh cows.tar.gz

# generate embedded bin files for category/metadata/the actual pokemon
build/assets:
@docker run \
@$(echo) -e "\e[48;5;30m> Building assets\e[0m"
@mkdir -p $(PWD)/assets
@docker run --rm \
-v $(PWD)/../:/usr/local/src \
--rm --name pokesay \
--platform linux/amd64 \
--name pokesay \
$(DOCKER_IMAGE) \
build/scripts/build_assets.sh
@tree -L 1 $(PWD)/assets/

build/bin:
@echo -e "\n> Building binaries"
@$(echo) -e "\e[48;5;30m> Building binaries\e[0m"
@mkdir -p $(PWD)/../dist/bin/ $(PWD)/../dist/packages/ $(PWD)/../dist/tarballs/
@docker run -it \
@docker run --rm \
-v $(PWD)/../:/usr/local/src \
-e VERSION=$(VERSION) \
-e DEBUG=$(DEBUG) \
--rm --name pokesay \
--platform linux/amd64 \
--user root \
--name pokesay \
$(DOCKER_IMAGE) \
/usr/local/src/build/scripts/build_bin.sh
@tree $(PWD)/../dist/

build/deb:
@echo -e "\n> Building DEB packages"
@docker run \
@$(echo) -e "\e[48;5;30m> Building DEB packages\e[0m"
@docker run --rm \
-v $(PWD)/../:/usr/local/src \
-e VERSION=$(VERSION) \
--rm \
--platform linux/amd64 \
--name pokesay \
$(DOCKER_IMAGE) \
bash -c "/usr/local/src/build/scripts/build_packages.sh deb"

build/arch:
@echo -e "\n> Building Arch packages"
@docker run \
-it \
@$(echo) -e "\e[48;5;30m> Building ARCH packages\e[0m"
@docker run --rm\
-v $(PWD)/../:/usr/local/src \
-e VERSION=$(VERSION) \
--platform linux/amd64 \
--rm \
--name pokesay \
archlinux:base-devel \
bash -c "useradd u -m && VERSION=$(VERSION) /usr/local/src/build/scripts/build_packages.sh arch"

build/packages: build/deb build/arch
@echo -e "\n> Built packages:"
@$(echo) -e "\e[48;5;30m> Built packages:\e[0m"
@tree $(PWD)/../dist/

test:
@echo -e "\n> Running tests"
@docker run \
@$(echo) -e "\e[48;5;30m> Running tests\e[0m"
@docker run --rm \
-v $(PWD)/../:/usr/local/src \
--platform linux/amd64 \
--user root \
--rm --name pokesay-test \
--name pokesay-test \
$(DOCKER_IMAGE) \
gotestsum --format dots

Expand Down
1 change: 0 additions & 1 deletion build/scripts/build_assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ go run ./src/bin/pokedex/pokedex.go \
-toTotalFname total.txt

rm -rf cows
ls -alh build/assets
26 changes: 16 additions & 10 deletions build/scripts/build_bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
[ -z "${VERSION:-}" ] && echo "no VERSION!" && exit 1

test -f "/usr/local/opt/coreutils/libexec/gnubin" && \
export PATH="/usr/local/opt/coreutils/libexec/gnubin:${PATH}"

OUTPUT_DIR="dist/bin"
mkdir -p "$OUTPUT_DIR"

Expand All @@ -12,13 +15,15 @@ cat build/packages/pokesay.1 | \
-e "s/VERSION/$VERSION/g" > pokesay.1

function build() {
echo "- building $1 / $2"
GOOS=$1 GOARCH=$2 go build -o "${OUTPUT_DIR}/pokesay-${VERSION}-${1}-${2}${3:-}" pokesay.go
echo "- built as ${OUTPUT_DIR}/pokesay-${VERSION}-${1}-${2}${3:-}"
echo -e " - building $1 / $2"
GOOS=$1 GOARCH=$2 go build \
-o "${OUTPUT_DIR}/pokesay-${VERSION}-${1}-${2}${3:-}" \
pokesay.go > /dev/null 2>&1
echo -e " \e[1;32m✔ built as ${OUTPUT_DIR}/pokesay-${VERSION}-${1}-${2}${3:-}\e[0m"
}

function tarball() {
echo "- tarballing $1 / $2"
echo " - tarballing $1 / $2"
local binfile="pokesay-${VERSION}-${1}-${2}${3:-}"

cp \
Expand Down Expand Up @@ -55,18 +60,19 @@ function tarball() {
pokesay-completion.zsh \
pokesay-completion.fish \
usr/share/pokesay/
echo -e " \e[1;32m✔ tarballed as dist/tarballs/${binfile}.tar.gz\e[0m"

rm -rf pokesay.1 pokesay-* usr/
}

build darwin amd64 &
build darwin arm64 &
build linux amd64 &
build windows amd64 .exe &
build android arm64 &
build darwin amd64
build darwin arm64
build linux amd64
build windows amd64 .exe
build android arm64
wait

# just create a tarball for the linux/amd64 (used for AUR package)
tarball linux amd64

rm -f pokesay.1
rm -f pokesay.1
14 changes: 8 additions & 6 deletions src/bin/pokedex/pokedex.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,22 @@ func main() {
fmt.Println("- Found", len(cowfileFpaths), "cowfiles")
// Read pokemon names
pokemonNames := pokedex.ReadNames(args.FromMetadataFname)
fmt.Println("- Read", len(pokemonNames), "pokemon names from", args.FromMetadataFname)

nameTokens := pokedex.GatherMapKeys(pokemonNames)
sort.Strings(nameTokens)
fmt.Println("names:", nameTokens)

fmt.Println("- Read", len(pokemonNames), "pokemon names from", args.FromMetadataFname)
if args.Debug {
fmt.Println("names:", nameTokens)
}

// 1. For each pokemon name, write a metadata file, containing the name information, and
// links to all of the matching cowfile indexes
fmt.Println("- Writing metadata to file")
pokemonMetadata := make([]pokedex.PokemonMetadata, 0)
uniqueNames := make(map[string][]int)
nameVariants := make(map[string][]string)
i := 0

pbar := bin.NewProgressBar(len(pokemonNames))
for i, key := range nameTokens {
name := pokemonNames[key]
Expand Down Expand Up @@ -152,12 +155,11 @@ func main() {
categories := pokedex.CreateCategoryStruct(args.FromDir, pokemonMetadata, args.Debug)
pokedex.WriteStructToFile(categories, "build/assets/category_keys.txt")

fmt.Println("- Writing total metadata to file")
fmt.Println("- Writing total metadata to", paths.TotalFpath)
pokedex.WriteIntToFile(len(pokemonMetadata), paths.TotalFpath)

fmt.Println("✓ Complete! Indexed", len(cowfileFpaths), "total cowfiles")
fmt.Println("wrote", i, "names to", "build/assets/names.txt")

fmt.Println("✓ Wrote names to", "build/assets/names.txt")
fmt.Println("✓ Wrote gzipped metadata to", paths.MetadataDirPath)
fmt.Println("✓ Wrote gzipped cowfiles to", paths.EntryDirPath)
fmt.Println("✓ Wrote 'total' metadata to", paths.TotalFpath, len(pokemonMetadata))
Expand Down
Loading