diff --git a/.gitignore b/.gitignore index 15b5fdc..cacfcf7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .claude *.prg +.version +*-*.metadata.json diff --git a/.woodpecker.yaml b/.woodpecker.yaml new file mode 100644 index 0000000..a51c43f --- /dev/null +++ b/.woodpecker.yaml @@ -0,0 +1,35 @@ +steps: + - name: version + image: alpine + commands: + - 'apk add --no-cache make' + - 'make ci-version' + + - name: build + image: debian:stable-slim + commands: + - 'apt-get update && apt-get install -y --no-install-recommends make acme' + - 'make ci-build' + + - 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-artifact' + + - name: update + image: alpine + environment: + UPDATE_SERVER: https://games.vps.teletype.hu + UPDATE_SECRET: + from_secret: update_secret_key + commands: + - 'apk add --no-cache make curl' + - 'make ci-update' diff --git a/Makefile b/Makefile index 2eb1285..682999b 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,28 @@ +# ----------------------------------------- +# Makefile – C64 project builder (ACME + VICE) +# ----------------------------------------- + +PROJECT = rabbit + ASM = acme EMU = x64sc SRC = main.asm SRCS = $(wildcard *.asm) -TARGET = rabbit.prg +TARGET ?= $(PROJECT).prg + +METADATA = metadata.json UNAME_S := $(shell uname -s) -.PHONY: build run clear rebuild rebuildrun deps +# CI/CD variables +VERSION_FILE = .version +DROPAREA_HOST ?= vps.teletype.hu +DROPAREA_PORT ?= 2223 +DROPAREA_TARGET_PATH ?= /home/drop +DROPAREA_USER ?= drop +UPDATE_SERVER ?= https://games.vps.teletype.hu + +all: build deps: ifeq ($(UNAME_S),Darwin) @@ -27,8 +43,49 @@ run: build $(EMU) $(TARGET) clear: - rm -f $(TARGET) + rm -f $(TARGET) $(PROJECT)-*.prg $(PROJECT)-*.metadata.json $(VERSION_FILE) rebuild: clear build rebuildrun: clear build run + +# ----------------------------------------- +# CI/CD Pipeline targets +# ----------------------------------------- + +ci-version: + @VERSION=$$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' $(METADATA) | head -n 1); \ + if [ -z "$$VERSION" ]; then \ + echo "ERROR: no \"version\" field in $(METADATA)!"; \ + exit 1; \ + fi; \ + BRANCH=$${CI_COMMIT_BRANCH:-$${WOODPECKER_BRANCH}}; \ + BRANCH=$$(echo "$$BRANCH" | tr '/' '-'); \ + if [ "$$BRANCH" != "main" ] && [ "$$BRANCH" != "master" ] && [ -n "$$BRANCH" ]; then \ + VERSION=dev-$$VERSION-$$BRANCH; \ + fi; \ + echo "VERSION is: $$VERSION"; \ + echo $$VERSION > $(VERSION_FILE) + +ci-build: build + @VERSION=$$(cat $(VERSION_FILE)); \ + echo "==> Creating versioned files for $$VERSION"; \ + cp $(TARGET) $(PROJECT)-$$VERSION.prg; \ + cp $(METADATA) $(PROJECT)-$$VERSION.metadata.json; \ + ls -lh $(PROJECT)-$$VERSION.* + +ci-artifact: + @VERSION=$$(cat $(VERSION_FILE)); \ + echo "==> Uploading artifacts for version $$VERSION"; \ + SCP_TARGET="$(DROPAREA_USER)@$(DROPAREA_HOST):$(DROPAREA_TARGET_PATH)/"; \ + sshpass -p "$(DROPAREA_SSH_PASSWORD)" scp -o StrictHostKeyChecking=no -P $(DROPAREA_PORT) \ + $(PROJECT)-$$VERSION.prg \ + $(PROJECT)-$$VERSION.metadata.json \ + $$SCP_TARGET + +ci-update: + @VERSION=$$(cat $(VERSION_FILE)); \ + echo "==> Triggering update for version $$VERSION"; \ + curl "$(UPDATE_SERVER)/update?secret=$(UPDATE_SECRET)&name=$(PROJECT)&platform=c64&version=$$VERSION" + +.PHONY: all deps build run clear rebuild rebuildrun ci-version ci-build ci-artifact ci-update diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..502a548 --- /dev/null +++ b/metadata.json @@ -0,0 +1,8 @@ +{ + "name": "rabbit", + "title": "Rabbit Scooter", + "author": "Teletype Games", + "desc": "A Commodore 64 port of rabbitroller, the Game & Watch style LCD mini game. Rabbits hop toward you on a five-lane road; steer your scooter to dodge them. Includes a two-player mode where player 2 steers the rabbits.", + "site": "https://git.teletype.hu/games/rabbitc64", + "version": "1.0.0" +}