BlueGit

timfa raytracer

Files

raytracer / blue-ci-cd.yml

blue-ci-cd.yml

blue-ci-cd.yml 4.0 KiB Download Raw
1# BlueGit CI for raytracer: tests, build game/editor bundle, FTP deploy of build/.
2# Secrets (repo): timftphost, timftpuser, timftppassword, timftproot (protected),
3# projectftp (expand; typically ${timftproot}raycaster).
4# GEEN mirror --delete (tuinslang-incident): live files mogen niet verdwijnen.
5# Deployt map build/ (NIET web/, NIET repo-root).
6stages: [test, build, deploy]
7
8workflow:
9 rules:
10 - if: $CI_COMMIT_TAG != ""
11 when: never
12 - if: $CI_PIPELINE_SOURCE == "merge_request_event"
13 - if: $CI_COMMIT_BRANCH == "master"
14 - if: $CI_COMMIT_BRANCH =~ /^feature\//
15
16unit_tests:
17 stage: test
18 image: node:20-bookworm
19 script:
20 - node --test test/*.test.js
21
22build_game:
23 stage: build
24 image: debian:bookworm-slim
25 needs: [unit_tests]
26 script:
27 - apt-get update -qq && apt-get install -y -qq bash ca-certificates >/dev/null
28 - chmod +x src/build.sh
29 - ./src/build.sh
30 - test -f build/game.js
31 - test -f build/editor.js
32 - test -f build/framework.js
33 - test -f build/index.html
34 - test -f build/editor.html
35 - test -f build/levels.json
36 - test -d build/images
37 - test -d build/paperdolls
38 artifacts:
39 paths:
40 - build/game.js
41 - build/editor.js
42 - build/index.html
43 - build/editor.html
44 - build/framework.js
45 - build/levels.json
46 expire_in: 7d
47
48ftp_upload:
49 stage: deploy
50 image: debian:bookworm-slim
51 needs: [build_game]
52 resource_group: production
53 rules:
54 # Alleen master push (protected secrets). Geen feature/MR-deploys.
55 - if: $CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE != "merge_request_event"
56 script:
57 - apt-get update -qy
58 - apt-get install -y --no-install-recommends lftp python3 ca-certificates
59 # BlueGit expandeert $timftproot in secrets niet altijd; doe het zelf.
60 - |
61 export projectftp="$(python3 - <<'PY'
62 import os
63 root = os.environ.get("timftproot", "") or ""
64 raw = os.environ["projectftp"]
65 # Expand placeholder; ensure a slash between root and suffix when glued.
66 if "${timftproot}" in raw or "$timftproot" in raw:
67 suf = raw.replace("${timftproot}", "").replace("$timftproot", "")
68 if root and suf and not root.endswith("/") and not suf.startswith("/"):
69 out = root + "/" + suf
70 else:
71 out = root + suf
72 else:
73 out = raw
74 print(out)
75 PY
76 )"
77 - test -n "$projectftp"
78 - |
79 python3 - <<'PY'
80 import os, sys
81 p = os.environ["projectftp"].rstrip("/")
82 root = os.environ.get("timftproot", "").rstrip("/")
83 if not p or p == root or p == "/" or p == ".":
84 print("REFUSING: projectftp is FTP-root or empty:", repr(p))
85 sys.exit(3)
86 # Pad moet op dit project eindigen (voorkomt verkeerde secret).
87 # Require "raytracer" as a path segment (secret leaf may include host dirs).
88 segs = [s for s in p.split("/") if s]
89 leaf = segs[-1] if segs else ""
90 allowed = {"raytracer", "raycaster"} # Tim's FTP leaf is raycaster
91 if not allowed.intersection(s.lower() for s in segs):
92 print("REFUSING: projectftp leaf not raytracer/raycaster; leaf=%r nsegs=%d" % (leaf, len(segs)))
93 sys.exit(3)
94 print("deploy target ok (length=%d leaf=%s nsegs=%d)" % (len(p), leaf, len(segs)))
95 PY
96 - test -f build/index.html
97 - test -f build/editor.html
98 - test -f build/game.js
99 - test -d build/images
100 # Upload alleen build/. GEEN --delete. Excludes: CI/shot-helpers/bron.
101 - |
102 printf '%s\n' \
103 'set ssl:verify-certificate no' \
104 'set sftp:auto-confirm yes' \
105 'set xfer:use-temp-file yes' \
106 'set cmd:fail-exit yes' \
107 "mkdir -p -f $projectftp" \
108 "cd $projectftp" \
109 'mirror -R --exclude-glob .git/** --exclude-glob shot-*.html --exclude-glob shot-*.js --exclude-glob shot-*.png --exclude-glob blue-ci-cd.yml --exclude-glob README.md --exclude-glob .gitignore build/ .' \
110 'bye' \
111 | lftp -u "$timftpuser","$timftppassword" "$timftphost"