stages:
  - build
  - release

.build-base:
  image: node:24-bookworm
  before_script:
    - apt-get update -qq && apt-get install -y -qq zip
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_PIPELINE_SOURCE == "web"

build-library:
  extends: .build-base
  stage: build
  script:
    - npm ci
    - npm run build:library
    - node ./scripts/pack-library.js
  artifacts:
    paths:
      - dfg-3dviewer-library.zip
    expire_in: 4 weeks

release-library:
  stage: release
  image: registry.gitlab.com/gitlab-org/cli:latest
  needs:
    - job: build-library
      artifacts: true
  rules:
    - if: $CI_COMMIT_TAG
  script:
    - echo "Publishing release $CI_COMMIT_TAG"
  release:
    tag_name: $CI_COMMIT_TAG
    name: 'Release $CI_COMMIT_TAG'
    description: 'DFG 3D Viewer JavaScript library — extract to web/libraries/dfg-3dviewer/ on Drupal.'
    assets:
      links:
        - name: dfg-3dviewer-library.zip
          url: '${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_TAG}/raw/dfg-3dviewer-library.zip?job=build-library'
          link_type: package
          filepath: '/dfg-3dviewer-library.zip'
