From ad39872f3a492a6f5200d36a149fdeedd60d9274 Mon Sep 17 00:00:00 2001
From: Andrew Alderwick <andrew@alderwick.co.uk>
Date: Thu, 23 Sep 2021 21:19:02 +0100
Subject: [PATCH] Added automated builds for Linux and Windows

---
 .build.yml | 41 +++++++++++++++++++++++++++++++++++++++++
 README.md  |  4 ++++
 2 files changed, 45 insertions(+)
 create mode 100644 .build.yml

diff --git a/.build.yml b/.build.yml
new file mode 100644
index 0000000..948cf50
--- /dev/null
+++ b/.build.yml
@@ -0,0 +1,41 @@
+image: debian/oldstable
+packages:
+    - curl
+    - build-essential
+    - libsdl2-dev
+    - rsync
+oauth: pages.sr.ht/PAGES:RW
+environment:
+    SITE: rabbits.srht.site
+    SSH_HOST_KEYS: |
+        [w1.uxn-build.ald.nu]:2222 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP+IYCB4JrKklFjWSMRkPBTqUjBqUuhlDQy6/X3l8xj5
+secrets:
+    - 138ad607-a4ec-4d74-88a1-8f3be2ba2d03
+tasks:
+    - prepare: |
+        rm -f out
+        mkdir -p out
+        umask 077
+        mkdir -p ~/.ssh
+        printf '%s\n' "${SSH_HOST_KEYS}" > ~/.ssh/known_hosts
+        printf 'Host win\nHostName w1.uxn-build.ald.nu\nPort 2222\nUser build\nStrictHostKeyChecking yes\nCheckHostIP no\n' > ~/.ssh/config
+    - build-linux: |
+        cd uxn
+        sed -i -e 's/.*Running.*/exit/' build.sh
+        ./build.sh
+        mv bin uxn
+        tar -czf ../out/uxn-linux-amd64.tar.gz uxn
+        cd ..
+    - build-windows: |
+        ssh win "rm -f uxn-windows-64bit.zip; export PATH=\"\${PATH}:/mingw64/bin\"; set -ex; cd uxn; git fetch; git checkout .; git clean -xfd; git checkout $(cd uxn && git rev-parse HEAD); sed -i -e 's/.*Running.*/exit/' build.sh; MSYSTEM=MSYS ./build.sh; mv bin uxn; zip -qr ../uxn-windows-64bit.zip uxn"
+        rsync win:uxn-windows-64bit.zip out/
+    - upload: |
+        ls -l out
+        tar -czf out.tar.gz -C out uxn-linux-amd64.tar.gz uxn-windows-64bit.zip
+        acurl() {
+            set +x
+            curl -H "Authorization: Bearer ${OAUTH2_TOKEN}" "${@}"
+            set -x
+        }
+        acurl -f "https://pages.sr.ht/publish/${SITE}" -Fcontent=@out.tar.gz
+        acurl -f "https://pages.sr.ht/publish/${SITE}" -Fcontent=@out.tar.gz -Fprotocol=GEMINI
diff --git a/README.md b/README.md
index 2d3a553..790521f 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,10 @@
 
 An assembler and emulator for the [Uxn stack-machine](https://wiki.xxiivv.com/site/uxn.html), written in ANSI C. 
 
+## Download binaries
+
+Binaries are available for 64-bit x86 computers running [Linux](https://rabbits.srht.site/uxn-linux-amd64.tar.gz) and [Windows](https://rabbits.srht.site/uxn-windows-64bit.zip).
+
 ## Build
 
 ### Linux/OS X