| 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}raytracer). |
| 4 | # GEEN mirror --delete (tuinslang-incident): live files mogen niet verdwijnen. |
| 5 | # Deployt map build/ (NIET web/, NIET repo-root). |
| 6 | stages: [test, build, deploy] |
| 7 | |
| 8 | workflow: |
| 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 | |
| 16 | unit_tests: |
| 17 | stage: test |
| 18 | image: node:20-bookworm |
| 19 | script: |
| 20 | - node --test test/*.test.js |
| 21 | |
| 22 | build_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 | |
| 48 | ftp_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 | - export projectftp="$(python3 -c 'import os;r=os.environ.get("timftproot","");print(os.environ["projectftp"].replace("${timftproot}",r).replace("$timftproot",r))')" |
| 61 | - test -n "$projectftp" |
| 62 | - | |
| 63 | python3 - <<'PY' |
| 64 | import os, sys |
| 65 | p = os.environ["projectftp"].rstrip("/") |
| 66 | root = os.environ.get("timftproot", "").rstrip("/") |
| 67 | if not p or p == root or p == "/" or p == ".": |
| 68 | print("REFUSING: projectftp is FTP-root or empty:", repr(p)) |
| 69 | sys.exit(3) |
| 70 | # Pad moet op dit project eindigen (voorkomt verkeerde secret). |
| 71 | leaf = p.rsplit("/", 1)[-1] |
| 72 | if leaf != "raytracer" and not p.endswith("/raytracer"): |
| 73 | print("REFUSING: projectftp does not end with raytracer:", p) |
| 74 | sys.exit(3) |
| 75 | print("deploy target ok (path redacted length=%d leaf=%s)" % (len(p), leaf)) |
| 76 | PY |
| 77 | - test -f build/index.html |
| 78 | - test -f build/editor.html |
| 79 | - test -f build/game.js |
| 80 | - test -d build/images |
| 81 | # Upload alleen build/. GEEN --delete. Excludes: CI/shot-helpers/bron. |
| 82 | - | |
| 83 | printf '%s\n' \ |
| 84 | 'set ssl:verify-certificate no' \ |
| 85 | 'set sftp:auto-confirm yes' \ |
| 86 | 'set xfer:use-temp-file yes' \ |
| 87 | 'set cmd:fail-exit yes' \ |
| 88 | "mkdir -p -f $projectftp" \ |
| 89 | "cd $projectftp" \ |
| 90 | '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/ .' \ |
| 91 | 'bye' \ |
| 92 | | lftp -u "$timftpuser","$timftppassword" "$timftphost" |