From 1c7678c48ee1be22d7b669a6846c1a86ebbc5357 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 11 Jul 2021 13:57:58 -0700 Subject: [PATCH] Improve automated distribution and release --- Building.md | 15 ++++ Makefile | 52 +++++++++----- etc/linux/net.kirsle.ProjectDoodle.desktop | 2 +- scripts/fpm-bundle.sh | 37 +++++++--- scripts/release.sh | 82 ++++++++++++++++++++++ 5 files changed, 161 insertions(+), 27 deletions(-) create mode 100755 scripts/release.sh diff --git a/Building.md b/Building.md index 63d943f..4463546 100644 --- a/Building.md +++ b/Building.md @@ -7,6 +7,21 @@ * [Windows Cross-Compile from Linux](#windows-cross-compile-from-linux) * [Old Docs](#old-docs) +# Automated Release Scripts + +For the quickest ways to fully end-to-end build Sketchy Maze for various +platforms to produce public release artifacts, see the following repos: + +* [doodle-docker](https://git.kirsle.net/doodle-docker) provides a Dockerfile that + fully end-to-end releases the latest version of the game for Linux and Windows: + * Windows: .zip file + * Linux: .tar.gz, .rpm, .deb +* [flatpak](https://code.sketchymaze.com/game/flatpak) is a Flatpak manifest for + Linux distributions. + +The Docker container depends on all the git servers being up, but if you have +the uber blob source code you can read the Dockerfile to see what it does. + # Quickstart with bootstrap.py From any Unix-like system (Fedora, Ubuntu, macOS) the bootstrap.py script diff --git a/Makefile b/Makefile index e33d921..980cb63 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ setup: clean # `make build` to build the binary. .PHONY: build build: - go build $(LDFLAGS) -i -o bin/doodle cmd/doodle/main.go + go build $(LDFLAGS) -i -o bin/sketchymaze cmd/doodle/main.go go build $(LDFLAGS) -i -o bin/doodad cmd/doodad/main.go # `make buildall` to run all build steps including doodads and bindata. @@ -29,14 +29,14 @@ buildall: doodads bindata build .PHONY: build-free build-free: gofmt -w . - go build $(LDFLAGS) -tags="shareware" -i -o bin/doodle cmd/doodle/main.go + go build $(LDFLAGS) -tags="shareware" -i -o bin/sketchymaze cmd/doodle/main.go go build $(LDFLAGS) -tags="shareware" -i -o bin/doodad cmd/doodad/main.go # `make build-debug` to build the binary in developer mode. .PHONY: build-debug build-debug: gofmt -w . - go build $(LDFLAGS) -tags="developer" -i -o bin/doodle cmd/doodle/main.go + go build $(LDFLAGS) -tags="developer" -i -o bin/sketchymaze cmd/doodle/main.go go build $(LDFLAGS) -tags="developer" -i -o bin/doodad cmd/doodad/main.go # `make bindata` generates the embedded binary assets package. @@ -75,21 +75,36 @@ doodads: mingw: doodads bindata env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \ GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \ - go build $(LDFLAGS_W) -i -o bin/doodle.exe cmd/doodle/main.go - env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \ - GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \ - go build $(LDFLAGS) -i -o bin/doodad.exe cmd/doodad/main.go + go build $(LDFLAGS_W) -i -o bin/sketchymaze.exe cmd/doodle/main.go + env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \ + GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \ + go build $(LDFLAGS) -i -o bin/doodad.exe cmd/doodad/main.go # `make mingw-free` for Windows binary in free mode. .PHONY: mingw-free mingw-free: doodads bindata env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \ GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \ - go build $(LDFLAGS_W) -tags="shareware" -i -o bin/doodle.exe cmd/doodle/main.go - env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \ - GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \ - go build $(LDFLAGS) -tags="shareware" -i -o bin/doodad.exe cmd/doodad/main.go + go build $(LDFLAGS_W) -tags="shareware" -i -o bin/sketchymaze.exe cmd/doodle/main.go + env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \ + GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \ + go build $(LDFLAGS) -tags="shareware" -i -o bin/doodad.exe cmd/doodad/main.go +# `make release` runs the release.sh script, must be run +# after `make dist` +.PHONY: release +release: + ./scripts/release.sh + +# `make mingw-release` runs a FULL end-to-end release of Linux and Windows +# binaries of the game, zipped and tagged and ready to go. +.PHONY: mingw-release +mingw-release: doodads bindata build mingw __dist-common release + +# `make osx` to cross-compile a Mac OS binary with osxcross. +# .PHONY: osx +# osx: doodads bindata +# CGO_ENABLED=1 CC=[path-to-osxcross]/target/bin/[arch]-apple-darwin[version]-clang GOOS=darwin GOARCH=[arch] go build -tags static -ldflags "-s -w" -a # `make run` to run it in debug mode. @@ -118,13 +133,14 @@ dist-free: doodads bindata build-free __dist-common # Common logic behind `make dist` .PHONY: __dist-common __dist-common: - mkdir -p dist/doodle-$(VERSION) - cp bin/* dist/doodle-$(VERSION)/ - cp -r README.md Changes.md "Open Source Licenses.md" rtp dist/doodle-$(VERSION)/ - rm -rf dist/doodle-$(VERSION)/rtp/.git - ln -sf doodle-$(VERSION) dist/doodle-latest - cd dist && tar -czvf doodle-$(VERSION).tar.gz doodle-$(VERSION) - cd dist && zip -r doodle-$(VERSION).zip doodle-$(VERSION) + mkdir -p dist/sketchymaze-$(VERSION) + cp bin/* dist/sketchymaze-$(VERSION)/ + cp -r README.md Changes.md "Open Source Licenses.md" rtp dist/sketchymaze-$(VERSION)/ + if [[ -d ./guidebook ]]; then cp -r guidebook dist/sketchymaze-$(VERSION)/; fi + rm -rf dist/sketchymaze-$(VERSION)/rtp/.git + ln -sf sketchymaze-$(VERSION) dist/sketchymaze-latest + cd dist && tar -czvf sketchymaze-$(VERSION).tar.gz sketchymaze-$(VERSION) + cd dist && zip -r sketchymaze-$(VERSION).zip sketchymaze-$(VERSION) # `make docker` to run the Docker builds .PHONY: docker docker.ubuntu docker.debian docker.fedora __docker.dist diff --git a/etc/linux/net.kirsle.ProjectDoodle.desktop b/etc/linux/net.kirsle.ProjectDoodle.desktop index 8167cfc..54ed73f 100755 --- a/etc/linux/net.kirsle.ProjectDoodle.desktop +++ b/etc/linux/net.kirsle.ProjectDoodle.desktop @@ -5,7 +5,7 @@ Name=Sketchy Maze GenericName=Maze Game X-GNOME-FullName=Sketchy Maze - A drawing-based maze game Comment=A drawing-based maze game. -Exec=/opt/sketchy-maze/doodle +Exec=/opt/sketchy-maze/sketchymaze Path=/opt/sketchy-maze Icon=project-doodle StartupNotify=true diff --git a/scripts/fpm-bundle.sh b/scripts/fpm-bundle.sh index e6d3a04..2d68de4 100755 --- a/scripts/fpm-bundle.sh +++ b/scripts/fpm-bundle.sh @@ -6,13 +6,34 @@ # Might need fixing over time. export PATH="$PATH:$HOME/.local/share/gem/ruby/3.0.0/bin" -VERSION=`egrep -e 'Version\s+=' ../../pkg/branding/branding.go | head -n 1 | cut -d '"' -f 2` INSTALL_ROOT="/opt/sketchy-maze" -LAUNCHER_FILE="../../etc/linux/net.kirsle.ProjectDoodle.desktop" +LAUNCHER_FILENAME="etc/linux/net.kirsle.ProjectDoodle.desktop" LAUNCHER_ROOT="/usr/share/applications" # Where the .desktop file goes. ICON_ROOT="/usr/share/icons/hicolor/" -if [[ ! -f "./doodle" ]]; then +# Find out how many levels up we need to go, so this +# script can run from either of these locations: +# ./dist/sketchymaze-$version/ +# ./dist/stage/$version/linux/ +UPLEVELS="." +if [[ -f "../../${LAUNCHER_FILENAME}" ]]; then + # run from a ./dist/x folder. + UPLEVELS="../.." +elif [[ -f "../../../../${LAUNCHER_FILENAME}" ]]; then + # run from a release stage folder + UPLEVELS="../../../.." +else + echo Did not find ${LAUNCHER_FILENAME} relative to your working directory. + echo Good places to run this script include: + echo " * ./dist/sketchymaze-\$version/ (as in 'make dist')" + echo " * ./dist/stage/\$version/linux/ (as in 'make release')" + exit 1 +fi + +VERSION=`egrep -e 'Version\s+=' ${UPLEVELS}/pkg/branding/branding.go | head -n 1 | cut -d '"' -f 2` +LAUNCHER_FILE="${UPLEVELS}/${LAUNCHER_FILENAME}" + +if [[ ! -f "./sketchymaze" ]]; then echo Run this script from the directory containing the Doodle binary. echo This is usually at /dist/doodle-VERSION/ relative to the git root. exit 1 @@ -35,11 +56,11 @@ cp $LAUNCHER_FILE root$LAUNCHER_ROOT/ # Copy icons in. mkdir -p root$ICON_ROOT/{256x256,128x128,64x64,32x32,16x16}/apps -cp ../../etc/icons/256.png "root${ICON_ROOT}256x256/apps/project-doodle.png" -cp ../../etc/icons/128.png "root${ICON_ROOT}128x128/apps/project-doodle.png" -cp ../../etc/icons/64.png "root$ICON_ROOT/64x64/apps/project-doodle.png" -cp ../../etc/icons/32.png "root$ICON_ROOT/32x32/apps/project-doodle.png" -cp ../../etc/icons/16.png "root$ICON_ROOT/16x16/apps/project-doodle.png" +cp ${UPLEVELS}/etc/icons/256.png "root${ICON_ROOT}256x256/apps/project-doodle.png" +cp ${UPLEVELS}/etc/icons/128.png "root${ICON_ROOT}128x128/apps/project-doodle.png" +cp ${UPLEVELS}/etc/icons/64.png "root$ICON_ROOT/64x64/apps/project-doodle.png" +cp ${UPLEVELS}/etc/icons/32.png "root$ICON_ROOT/32x32/apps/project-doodle.png" +cp ${UPLEVELS}/etc/icons/16.png "root$ICON_ROOT/16x16/apps/project-doodle.png" # Copy runtime package and guidebook cp -r guidebook rtp "root$INSTALL_ROOT/" diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..6d20987 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +# release.sh: +# Run this AFTER `make dist` and it will carve up the dist/ +# folder into Linux and Windows versions and zip them up +# for release. +# +# For Mac OS releases, after `make dist` run `release-osx.sh` +# instead. + +# Add the user-level "gem install fpm" to the $PATH. +# Might need fixing over time. +export PATH="$PATH:$HOME/.local/share/gem/ruby/3.0.0/bin" + +VERSION=`egrep -e 'Version\s+=' ./pkg/branding/branding.go | head -n 1 | cut -d '"' -f 2` +DIST_PATH="$(pwd)/dist/sketchymaze-${VERSION}" +RELEASE_PATH="$(pwd)/dist/release/${VERSION}" +STAGE_PATH="$(pwd)/dist/stage/${VERSION}" + +if [[ ! -d $DIST_PATH ]]; then + echo Run this script from the root of the game repository, such that + echo ./dist/sketchymaze-${VERSION} exists. Run 'make mingw' and/or + echo 'make dist' to create this directory before running this script. + exit 1 +fi + +# Clean previous artifacts. +if [[ -d $RELEASE_PATH ]]; then + rm -rf $RELEASE_PATH +fi +if [[ -d $STAGE_PATH ]]; then + rm -rf $STAGE_PATH +fi + +# Release scripts by operating system. +linux() { + # Check for Linux binaries in the dist folder. + if [[ ! -f "${DIST_PATH}/doodad" ]]; then + echo No Linux binaries found, skipping Linux release. + return + fi + + # Prepare the Linux release. + mkdir -p ${STAGE_PATH} "${RELEASE_PATH}/linux" + cp -r $DIST_PATH "${STAGE_PATH}/linux" + cd "$STAGE_PATH/linux" + + # Remove Windows artifacts. + rm *.exe *.dll + + # Tar it. + tar -czvf "${RELEASE_PATH}/linux/sketchymaze-${VERSION}-linux-64bit.tar.gz" . + + # fpm it. + ../../../../scripts/fpm-bundle.sh + cp *.rpm *.deb "${RELEASE_PATH}/linux/" + + # return + cd - +} +windows() { + # Check for Windows binaries in the dist folder. + if [[ ! -f "${DIST_PATH}/doodad.exe" ]]; then + echo No Windows binaries found, skipping Windows release. + return + fi + + # Prepare the Windows release. + mkdir -p ${STAGE_PATH} "${RELEASE_PATH}/windows" + cp -r $DIST_PATH "${STAGE_PATH}/windows" + cd "$STAGE_PATH/windows" + + # Remove Linux artifacts. + rm sketchymaze doodad + + # Zip it. + zip -r "${RELEASE_PATH}/windows/sketchymaze-${VERSION}-windows-64bit.zip" . + cd - +} + +linux +windows \ No newline at end of file