# Deploy a static site to giantpanda.site on every push to main (GitLab CI).
# Source: https://files.giantpanda.site/ci/v1/gitlab-ci.yml
#
# 1. Put this job in .gitlab-ci.yml and fill in the variables: they are not secret, so they live in the repository.
# 2. Only the API key goes in GitLab (Settings → CI/CD → Variables): GIANTHOST_API_KEY, masked + protected.
#    Make it in Hub → Instellingen → API-sleutels with the purpose "Website publiceren" (only api:sites:publish).
# The deploy script is fetched on every run (always the newest v1). To pin it, compare it with the checksum:
#    echo "<sha256 from https://files.giantpanda.site/ci/v1/deploy-gianthost.mjs.sha256>  /tmp/deploy-gianthost.mjs" | sha256sum -c -
deploy-gianthost:
  stage: deploy
  image: node:22
  variables:
    GIANTHOST_PROFILE_ID: "00000000-0000-0000-0000-000000000000" # company profile of the customer
    GIANTHOST_SITE_ID: "klant-site"                               # the site id: <site id>.sites.giantpanda.site
    GIANTHOST_SOURCE_PATH: ""                                     # folder of the site in this repository; empty = root
    GIANTHOST_BUILD_DIR: "dist"                                   # build output, relative to GIANTHOST_SOURCE_PATH
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'
  script:
    - cd "${GIANTHOST_SOURCE_PATH:-.}"
    - npm ci
    - npm run build
    - curl -fsSL https://files.giantpanda.site/ci/v1/deploy-gianthost.mjs -o /tmp/deploy-gianthost.mjs
    - node /tmp/deploy-gianthost.mjs "$GIANTHOST_BUILD_DIR"
