# BlueGit CI for raytracer: tests, build game/editor bundle, FTP deploy of build/. # Secrets (repo): timftphost, timftpuser, timftppassword, timftproot (protected), # projectftp (expand; typically ${timftproot}raytracer). # GEEN mirror --delete (tuinslang-incident): live files mogen niet verdwijnen. # Deployt map build/ (NIET web/, NIET repo-root). stages: [test, build, deploy] workflow: rules: - if: $CI_COMMIT_TAG != "" when: never - if: $CI_PIPELINE_SOURCE == "merge_request_event" - if: $CI_COMMIT_BRANCH == "master" - if: $CI_COMMIT_BRANCH =~ /^feature\// unit_tests: stage: test image: node:20-bookworm script: - node --test test/*.test.js build_game: stage: build image: debian:bookworm-slim needs: [unit_tests] script: - apt-get update -qq && apt-get install -y -qq bash ca-certificates >/dev/null - chmod +x src/build.sh - ./src/build.sh - test -f build/game.js - test -f build/editor.js - test -f build/framework.js - test -f build/index.html - test -f build/editor.html - test -f build/levels.json - test -d build/images - test -d build/paperdolls artifacts: paths: - build/game.js - build/editor.js - build/index.html - build/editor.html - build/framework.js - build/levels.json expire_in: 7d ftp_upload: stage: deploy image: debian:bookworm-slim needs: [build_game] resource_group: production rules: # Alleen master push (protected secrets). Geen feature/MR-deploys. - if: $CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE != "merge_request_event" script: - apt-get update -qy - apt-get install -y --no-install-recommends lftp python3 ca-certificates # BlueGit expandeert $timftproot in secrets niet altijd; doe het zelf. - | export projectftp="$(python3 - <<'PY' import os root = os.environ.get("timftproot", "") or "" raw = os.environ["projectftp"] # Expand placeholder; ensure a slash between root and suffix when glued. if "${timftproot}" in raw or "$timftproot" in raw: suf = raw.replace("${timftproot}", "").replace("$timftproot", "") if root and suf and not root.endswith("/") and not suf.startswith("/"): out = root + "/" + suf else: out = root + suf else: out = raw print(out) PY )" - test -n "$projectftp" - | python3 - <<'PY' import os, sys p = os.environ["projectftp"].rstrip("/") root = os.environ.get("timftproot", "").rstrip("/") if not p or p == root or p == "/" or p == ".": print("REFUSING: projectftp is FTP-root or empty:", repr(p)) sys.exit(3) # Pad moet op dit project eindigen (voorkomt verkeerde secret). # Require "raytracer" as a path segment (secret leaf may include host dirs). segs = [s for s in p.split("/") if s] leaf = segs[-1] if segs else "" if "raytracer" not in [s.lower() for s in segs]: print("REFUSING: projectftp has no raytracer segment; leaf=%r nsegs=%d" % (leaf, len(segs))) sys.exit(3) print("deploy target ok (length=%d leaf=%s nsegs=%d)" % (len(p), leaf, len(segs))) PY - test -f build/index.html - test -f build/editor.html - test -f build/game.js - test -d build/images # Upload alleen build/. GEEN --delete. Excludes: CI/shot-helpers/bron. - | printf '%s\n' \ 'set ssl:verify-certificate no' \ 'set sftp:auto-confirm yes' \ 'set xfer:use-temp-file yes' \ 'set cmd:fail-exit yes' \ "mkdir -p -f $projectftp" \ "cd $projectftp" \ '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/ .' \ 'bye' \ | lftp -u "$timftpuser","$timftppassword" "$timftphost"