BlueGit

timfa 66wiki

Pipeline Editor

Pipelines Pipeline Editor

Pipeline Editor

No issues found

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
# BlueGit CI (vertaald uit .gitlab-ci.yml; GitLab is alleen nog backup).
# Secrets (repo, beschermd, eigen FTP-host): timftphost, timftpuser, timftppassword, timftproot, projectftp.
stages:
- validate
- deploy
validate_json:
stage: validate
image: python:3.12-slim
rules:
# Merge request pipelines
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: on_success
# Pushes to master
- if: $CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE == "push"
when: on_success
# Everything else: do not run
- when: never
script:
- python -V
- |
python - <<'PY'
import json
import sys
from pathlib import Path
root = Path("web")
data_dir = root / "data"
templates_dir = root / "templates"
if not data_dir.is_dir():
print(f"ERROR: data directory not found: {data_dir.resolve()}")
sys.exit(1)
if not templates_dir.is_dir():
print(f"ERROR: templates directory not found: {templates_dir.resolve()}")
sys.exit(1)
# NEW: ensure all files under /data are .json (no other extensions, no extensionless files)
bad_files = []
for p in sorted(data_dir.rglob("*")):
if p.is_file() and p.suffix.lower() != ".json":
bad_files.append(p.as_posix())
if bad_files:
print("\nDATA DIRECTORY VALIDATION FAILED\n")
print("ERROR: Non-JSON files found under web/data (only .json allowed):")
for bf in bad_files:
print(" - " + bf)
sys.exit(1)
json_files = sorted(data_dir.rglob("*.json"))
if not json_files:
print(f"ERROR: No .json files found under {data_dir}")
sys.exit(1)
errors = []
checked = 0
for jf in json_files:
checked += 1
rel = jf.as_posix()
# 1) JSON syntax check
try:
obj = json.loads(jf.read_text(encoding="utf-8"))
except Exception as e:
errors.append(f"{rel}: invalid JSON ({e})")
continue
if not isinstance(obj, dict):
errors.append(f"{rel}: JSON root must be an object")
continue
# 2) type exists and is valid
t = obj.get("type")
if not isinstance(t, str) or not t.strip():
errors.append(f"{rel}: missing or invalid 'type'")
continue
t = t.strip()
n = obj.get("name")
if not isinstance(n, str) or not n.strip():
errors.append(f"{rel}: missing or invalid 'name'")
continue
# 3) template exists
tpl = templates_dir / f"{t}.template"
if not tpl.is_file():
errors.append(
f"{rel}: type '{t}' has no matching template ({tpl.as_posix()})"
)
if errors:
print("\nJSON VALIDATION FAILED\n")
for e in errors:
print(" - " + e)
print(f"\nChecked {checked} file(s), found {len(errors)} issue(s).")
sys.exit(1)
print(f"OK: {checked} JSON file(s) validated successfully.")
PY
ftp_upload:
stage: deploy
image: debian:bookworm-slim
resource_group: production
rules:
- if: $CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE == "push"
script:
- apt-get update -qy
- apt-get install -y --no-install-recommends lftp python3 ca-certificates
# BlueGit expandeert $timftproot in secrets niet (GitLab deed dat wel).
- export projectftp="$(python3 -c 'import os;r=os.environ.get("timftproot","");print(os.environ["projectftp"].replace("${timftproot}",r).replace("$timftproot",r))')"
- test -n "$projectftp"
# In-place sync instead of "rm -r + mirror": live folders never disappear during a deploy.
# - no --only-newer/--ignore-time: the fresh CI checkout gives every file a new mtime, so the
# default size+time comparison re-uploads all files (correct even if FTP mtimes are unreliable)
# - --delete removes remote files that no longer exist in web/ (runs after the transfers)
# - xfer:use-temp-file uploads to a temp name and renames, so a file is never served half-written
# - cmd:fail-exit makes the job fail if the mirror fails
- lftp -u $timftpuser,$timftppassword $timftphost -e "set ssl:verify-certificate no; set sftp:auto-confirm yes; set xfer:use-temp-file yes; mkdir -p -f $projectftp; set cmd:fail-exit yes; mirror -R --delete --parallel=4 web $projectftp; quit"
needs: [validate_json]