diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88b90d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin +dist +*.zip +.version diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..cfe2b7d --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,34 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Run", + "type": "shell", + "command": "go run .", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build & Run", + "type": "shell", + "command": "make clean && make build && ./bin/pncdsl-demo", + "problemMatcher": [] + }, + { + "label": "Build WASM", + "type": "shell", + "command": "make wasm", + "problemMatcher": [] + }, + { + "label": "Make build", + "type": "shell", + "command": "make build" + } + ] +} diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..8b03621 --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,47 @@ +steps: + - name: version + image: alpine + commands: + - apk add --no-cache git make jq + - make ci-version + + - name: build + image: golang:1.26.3-alpine + environment: + GOPRIVATE: git.teletypegames.org/* + GIT_SSH_KEY: + from_secret: git_ssh_key + commands: + - apk add --no-cache zip make curl git openssh-client + - mkdir -p ~/.ssh + - echo "$GIT_SSH_KEY" > ~/.ssh/id_ed25519 + - chmod 600 ~/.ssh/id_ed25519 + - ssh-keyscan -p 2222 git.teletypegames.org >> ~/.ssh/known_hosts 2>/dev/null + - git config --global url."ssh://git@git.teletypegames.org:2222/".insteadOf "https://git.teletypegames.org/" + # The go.mod may point at a local ../pncdsl checkout (see README); + # in CI clone the framework next to the workspace so it resolves. + - if grep -q '=> \.\./pncdsl' go.mod; then git clone ssh://git@git.teletypegames.org:2222/games/pncdsl ../pncdsl; fi + - make ci-export + + - name: artifact + image: alpine + environment: + DROPAREA_HOST: vps.teletype.hu + DROPAREA_PORT: 2223 + DROPAREA_TARGET_PATH: /home/drop + DROPAREA_USER: drop + DROPAREA_SSH_PASSWORD: + from_secret: droparea_ssh_password + commands: + - apk add --no-cache make openssh-client sshpass + - make ci-upload + + - name: update + image: alpine + environment: + UPDATE_SERVER: https://teletypegames.org + UPDATE_SECRET: + from_secret: update_secret_key + commands: + - apk add --no-cache make curl + - make ci-update diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c2cc339 --- /dev/null +++ b/Makefile @@ -0,0 +1,76 @@ +# ----------------------------------------- +# Makefile – Ebitengine project builder +# ----------------------------------------- + +PROJECT = pncdsl-demo + +BIN_DIR = bin +DIST_DIR = dist +WASM_NAME = game.wasm +OUTPUT_BIN = $(BIN_DIR)/$(PROJECT) +OUTPUT_WASM = $(DIST_DIR)/$(WASM_NAME) +OUTPUT_JS = $(DIST_DIR)/wasm_exec.js +OUTPUT_ZIP = $(PROJECT)-$(VERSION).html.zip + +VERSION_FILE = .version +INDEX_HTML_URL = https://git.teletype.hu/tools/ebitengine-tools/raw/branch/master/web/index.html + +all: build + +build: + @mkdir -p $(BIN_DIR) + go build -o $(OUTPUT_BIN) . + +wasm: + @mkdir -p $(DIST_DIR) + GOOS=js GOARCH=wasm go build -o $(OUTPUT_WASM) . + cp "$$(go env GOROOT)/lib/wasm/wasm_exec.js" $(OUTPUT_JS) + +export: wasm + @if [ -z "$(VERSION)" ]; then \ + echo "ERROR: VERSION not set!"; exit 1; \ + fi + @echo "==> Downloading index.html" + curl -sSL $(INDEX_HTML_URL) -o $(DIST_DIR)/index.html + @echo "==> Packaging HTML/WASM for $(VERSION)" + zip -r $(OUTPUT_ZIP) -j $(DIST_DIR)/$(WASM_NAME) $(DIST_DIR)/wasm_exec.js $(DIST_DIR)/index.html + @echo "==> Cleaning temporary files" + rm -f $(DIST_DIR)/$(WASM_NAME) $(DIST_DIR)/wasm_exec.js $(DIST_DIR)/index.html + +watch: + fswatch -o . | while read; do make build; done + +clean: + rm -rf $(BIN_DIR) $(DIST_DIR) + +ci-version: + @if [ -f metadata.json ]; then \ + VERSION=$$(jq -r '.version' metadata.json); \ + else \ + VERSION=$$(git rev-parse --short HEAD); \ + fi; \ + BRANCH=$$(git rev-parse --abbrev-ref HEAD); \ + if [ "$$BRANCH" != "main" ] && [ "$$BRANCH" != "master" ]; then \ + VERSION="dev-$$VERSION-$$BRANCH"; \ + fi; \ + echo $$VERSION > $(VERSION_FILE) + +ci-export: + @VERSION=$$(cat $(VERSION_FILE)); \ + $(MAKE) export VERSION=$$VERSION + +ci-upload: + @VERSION=$$(cat $(VERSION_FILE)); \ + FILE="$(PROJECT)-$$VERSION.html.zip"; \ + META_SRC="metadata.json"; \ + META_DST="$(PROJECT)-$$VERSION.metadata.json"; \ + cp $$META_SRC $$META_DST; \ + sshpass -p "$(DROPAREA_SSH_PASSWORD)" scp -o StrictHostKeyChecking=no -P $(DROPAREA_PORT) \ + $$FILE $$META_DST \ + $(DROPAREA_USER)@$(DROPAREA_HOST):$(DROPAREA_TARGET_PATH)/ + +ci-update: + @VERSION=$$(cat $(VERSION_FILE)); \ + curl "$(UPDATE_SERVER)/update?secret=$(UPDATE_SECRET)&name=$(PROJECT)&platform=ebitengine&version=$$VERSION" + +.PHONY: all build wasm export watch clean ci-version ci-export ci-upload ci-update diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..c2c4e33 --- /dev/null +++ b/metadata.json @@ -0,0 +1,9 @@ +{ + "name": "pncdsl-demo", + "title": "Morning Coffee", + "author": "Teletype Games", + "desc": "A short point-and-click adventure built on the pncdsl framework", + "site": "https://git.teletypegames.org/games/pncdsl-demo", + "license": "MIT License", + "version": "1.0.0" +}