From 8c234a3e74cc96a29b87a7ac76f44ea658901777 Mon Sep 17 00:00:00 2001
From: Louis Capitanchik <contact@louiscap.co>
Date: Mon, 1 Aug 2022 02:31:05 +0100
Subject: [PATCH] Update build scripts

---
 .gitlab-ci.yml       | 75 ++++++++++++++++++++++++++++++++++----------
 Makefile             |  6 ++++
 game_core/Trunk.toml |  2 ++
 3 files changed, 67 insertions(+), 16 deletions(-)
 create mode 100644 game_core/Trunk.toml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7e72533..f253e0a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -3,59 +3,97 @@ image: "r.lcr.gr/microhacks/bevy-builder:latest"
 variables:
   BINARY_NAME: game
 
-.cache_directive: &cache_directive
+stages:
+  - build
+  - package
+
+build-windows:
+  stage: build
   before_script:
     - export CARGO_HOME="${CI_PROJECT_DIR}/.cargo"
     - export PATH="${CI_PROJECT_DIR}/.cargo/bin:$PATH"
   cache:
-    key: build-cache-key
+    key: build-cache-windows
     paths:
       - .cargo/registry/cache
       - .cargo/registry/index
       - .cargo/git/db
       - .cargo/bin/
       - target/
-
-stages:
-  - build
-  - package
-
-build-windows:
-  stage: build
-  <<: *cache_directive
   script:
     - cargo build --release -p game_core --target x86_64-pc-windows-gnu
+  artifacts:
+    expire_in: 1 day
+    paths:
+      - target/x86_64-pc-windows-gnu/release/game_core.exe
   only:
     - trunk
 
 build-linux:
   stage: build
-  <<: *cache_directive
+  before_script:
+    - export CARGO_HOME="${CI_PROJECT_DIR}/.cargo"
+    - export PATH="${CI_PROJECT_DIR}/.cargo/bin:$PATH"
+  cache:
+    key: build-cache-linux
+    paths:
+      - .cargo/registry/cache
+      - .cargo/registry/index
+      - .cargo/git/db
+      - .cargo/bin/
+      - target/
   script:
     - cargo build --release -p game_core --target x86_64-unknown-linux-gnu
+  artifacts:
+    expire_in: 1 day
+    paths:
+      - target/x86_64-unknown-linux-gnu/release/game_core
   only:
     - trunk
 
 build-web:
   stage: build
-  <<: *cache_directive
+  before_script:
+    - export CARGO_HOME="${CI_PROJECT_DIR}/.cargo"
+    - export PATH="${CI_PROJECT_DIR}/.cargo/bin:$PATH"
+  cache:
+    key: build-cache-web
+    paths:
+      - .cargo/registry/cache
+      - .cargo/registry/index
+      - .cargo/git/db
+      - .cargo/bin/
+      - target/
   script:
+    - make assets
     - cd "${CI_PROJECT_DIR}/game_core" && trunk build --release
+    - cd "${CI_PROJECT_DIR}"
+  artifacts:
+    expire_in: 1 day
+    paths:
+      - game_core/dist/
   only:
     - trunk
 
 package-all:
   stage: package
-  <<: *cache_directive
   script:
     - mkdir -p dist/
+    - make assets
     - cp -r assets dist/assets
     - cp target/x86_64-unknown-linux-gnu/release/game_core "dist/$BINARY_NAME"
     - cp target/x86_64-pc-windows-gnu/release/game_core.exe "dist/$BINARY_NAME.exe"
-    - cd "${CI_PROJECT_DIR}/dist && zip -r "windows.zip" "./${BINARY_NAME}.exe" ./assets
-    - cd "${CI_PROJECT_DIR}/dist && zip -r "linux.zip" "./${BINARY_NAME}" ./assets
-    - cd "${CI_PROJECT_DIR}/game_core/dist && zip -r "../../dist/web.zip" "./*"
+    - cd "${CI_PROJECT_DIR}/dist" && zip -r "windows.zip" "./${BINARY_NAME}.exe" ./assets
+    - cd "${CI_PROJECT_DIR}/dist" && zip -r "linux.zip" "./${BINARY_NAME}" ./assets
+    - ls "${CI_PROJECT_DIR}/game_core/dist"
+    - cd "${CI_PROJECT_DIR}/game_core/dist" && zip -r "web.zip" ./*
+    - cd "${CI_PROJECT_DIR}" && mv "${CI_PROJECT_DIR}/game_core/dist/web.zip" "${CI_PROJECT_DIR}/dist/web.zip"
+  dependencies:
+    - build-windows
+    - build-linux
+    - build-web
   artifacts:
+    expire_in: 7 days
     paths:
       - dist/web.zip
       - dist/windows.zip
@@ -66,10 +104,15 @@ package-all:
 pages:
   stage: package
   script:
+    - ls game_core/
+    - ls game_core/dist/
     - mkdir -p public/
     - cp -r game_core/dist/* public/
   artifacts:
+    expire_in: 7 days
     paths:
       - public
+  dependencies:
+    - build-web
   only:
     - trunk
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 885f735..2dc4e11 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,12 @@ cargo-deps:
 setup-x11: linux-deps cargo-deps
 setup-wayland: linux-deps wayland-deps cargo-deps
 
+# Update this command to build assets; commonly using Crunch to generate asset files
+# If you remove this command, be sure to update .gitlab-ci.yml to remove the steps that
+# call "make assets"
+assets:
+	@echo "Beep Boop, No assets needed to be built"
+
 run:
 	RUSTFLAGS="-Awarnings" \
 	cargo run --release --features "bevy/dynamic" -p game_core
diff --git a/game_core/Trunk.toml b/game_core/Trunk.toml
new file mode 100644
index 0000000..017deba
--- /dev/null
+++ b/game_core/Trunk.toml
@@ -0,0 +1,2 @@
+[build]
+public_url = "./"
\ No newline at end of file
-- 
GitLab