when:
  - event: pull_request

steps:
  change-path:
    image: alpine
    commands:
      - |
        sed -i.orig -e "s~pathPrefix: '/'~pathPrefix: '/documentation/pull_${CI_COMMIT_PULL_REQUEST}/'~" eleventy.config.mjs

  build:
    image: codeberg.org/woodpecker-plugins/node-pm@sha256:bff3ee2d7492e89a0dfbe6ee4c7d5ce636108cd973c0c355269f681e8dd8a196
    settings:
      run: build
      with: pnpm
      frozen_lockfile: true
      ignore_node_modules: true
    depends_on: change-path

  deploy-preview:
    image: codeberg.org/gedankenstuecke/git-pages-woodpecker-plugin@sha256:5257561a95054104f7499838817f3b447049a1edc14e87b99156b1302e0bce36
    settings:
      SITE_URL: https://codeberg.codeberg.page/documentation
      PATH: pull_${CI_COMMIT_PULL_REQUEST}
      TOKEN:
        from_secret: surge_forge_token
      UPLOAD_DIR: _site
    depends_on: build

  comment:
    image: mcs94/gitea-comment@sha256:f1a06366bfa34ff7594f369ebf81cbadd2d4410b7d51c9aa59c0c0264aa5fbd9
    settings:
      gitea_address: https://codeberg.org
      gitea_token:
        from_secret: surge_forge_token
      comment: 'Preview ready: https://codeberg.codeberg.page/documentation/pull_${CI_COMMIT_PULL_REQUEST}'
    depends_on: deploy-preview
