From fa049db1a28f3d87c6c0baaa1a78f4a4d7bb1931 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 6 Dec 2023 16:44:40 -0700 Subject: [PATCH] Windows executables from CI/CD? --- .gitignore | 3 ++- .gitlab-ci.yml | 11 ++++++++++ build/package/Containerfile | 3 ++- build/package/build.sh | 39 +++++++++++++++++++++++++----------- build/package/moth-devel.bat | 1 + build/package/winbuild.sh | 24 ++++++++++++++++++++++ go.mod | 2 +- 7 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 build/package/moth-devel.bat create mode 100755 build/package/winbuild.sh diff --git a/.gitignore b/.gitignore index 7e15d0d..461204e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ __debug_bin *.tar.gz transpile -mothd \ No newline at end of file +mothd +winmoth.*.zip diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index abfb2c5..16dadbf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,6 @@ stages: - test + - build - push Run unit tests: @@ -37,6 +38,16 @@ Generage coverage XML: coverage_format: cobertura path: coverage.xml +build-win: + stage: build + image: *goimage + needs: ["Run unit tests"] + script: + - ./build/package/winbuild.sh + artifacts: + paths: + - build/package/winmoth.*.zip + push: stage: push needs: ["Run unit tests"] diff --git a/build/package/Containerfile b/build/package/Containerfile index 238db91..cb8ab93 100644 --- a/build/package/Containerfile +++ b/build/package/Containerfile @@ -1,4 +1,5 @@ -FROM golang:1 AS builder +ARG GO_VERSION=1.21-alpine +FROM docker.io/library/golang:${GO_VERSION} AS builder COPY go.* /src/ COPY pkg /src/pkg/ COPY cmd /src/cmd/ diff --git a/build/package/build.sh b/build/package/build.sh index bf87dd4..1021b58 100755 --- a/build/package/build.sh +++ b/build/package/build.sh @@ -2,19 +2,34 @@ set -e -cd $(dirname $0)/../.. +cd $(dirname $0) +base=../.. -PODMAN=$(command -v podman || echo docker) -VERSION=$(cat CHANGELOG.md | awk -F '[][]' '/^## \[/ {print $2; exit}') +VERSION=$(cat $base/CHANGELOG.md | awk -F '[][]' '/^## \[/ {print $2; exit}') +GO_VERSION=$(cat $base/go.mod | sed -n 's/^go //p') -for target in moth; do - tag=dirtbags/$target:$VERSION - echo "==== Building $tag" - $PODMAN build \ - --build-arg http_proxy --build-arg https_proxy --build-arg no_proxy \ - --tag $tag \ - --target $target \ - -f build/package/Containerfile . -done +( + zipfile=winmoth.$VERSION.zip + echo "=== Building $zipfile" + mkdir -p winmoth winmoth/state winmoth/puzzles winmoth/mothballs + echo devel > winmoth/state/teamids.txt + cp moth-devel.bat winmoth + cp -a $base/theme winmoth + ( + cd winmoth + GOOS=windows GOARCH=amd64 go build ../$base/cmd/mothd/... + ) + zip -r $zipfile winmoth + + rm -rf winmoth +) + +tag=dirtbags/moth:$VERSION +echo "==== Building $tag" +docker build \ + --build-arg GO_VERSION=$GO_VERSION \ + --build-arg http_proxy --build-arg https_proxy --build-arg no_proxy \ + --tag $tag \ + -f Containerfile $base exit 0 diff --git a/build/package/moth-devel.bat b/build/package/moth-devel.bat new file mode 100644 index 0000000..6cc02f6 --- /dev/null +++ b/build/package/moth-devel.bat @@ -0,0 +1 @@ +.\mothd.exe -puzzles puzzles diff --git a/build/package/winbuild.sh b/build/package/winbuild.sh new file mode 100755 index 0000000..5e44b8f --- /dev/null +++ b/build/package/winbuild.sh @@ -0,0 +1,24 @@ +#! /bin/sh + +set -e + +cd $(dirname $0) +base=../.. + +VERSION=$(cat $base/CHANGELOG.md | awk -F '[][]' '/^## \[/ {print $2; exit}') + +( + zipfile=winmoth.$VERSION.zip + echo "=== Building $zipfile" + mkdir -p winmoth winmoth/state winmoth/puzzles winmoth/mothballs + echo devel > winmoth/state/teamids.txt + cp moth-devel.bat winmoth + cp -a $base/theme winmoth + ( + cd winmoth + GOOS=windows GOARCH=amd64 go build ../$base/cmd/mothd/... + ) + zip -r $zipfile winmoth + + rm -rf winmoth +) diff --git a/go.mod b/go.mod index e39a379..ad23321 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/dirtbags/moth/v4 -go 1.13 +go 1.21 require ( github.com/kr/text v0.2.0 // indirect