# SPDX-FileCopyrightText: 2023 Johannes Loher
#
# SPDX-License-Identifier: MIT

$schema: https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json

variables:
  - &node_image node:lts
  - &enable_pnpm
    - corepack enable
    - corepack prepare pnpm@latest --activate

when:
  - event: push
    branch: ${CI_REPO_DEFAULT_BRANCH}
  - event: pull_request
  - event: tag
  - event: manual

steps:
  install:
    image: *node_image
    commands:
      - <<: *enable_pnpm
      - pnpm install --frozen-lockfile
  lint:
    depends_on: install
    image: *node_image
    commands:
      - <<: *enable_pnpm
      - pnpm lint
  formatcheck:
    depends_on: install
    image: *node_image
    commands:
      - <<: *enable_pnpm
      - pnpm format:check
  typecheck:
    depends_on: install
    image: *node_image
    commands:
      - <<: *enable_pnpm
      - pnpm typecheck
  test:
    depends_on: install
    image: *node_image
    commands:
      - <<: *enable_pnpm
      - pnpm test
  reuse:
    depends_on: install
    image: fsfe/reuse:latest
    commands:
      - reuse lint
  commitlint:
    depends_on: install
    image: *node_image
    commands:
      - <<: *enable_pnpm
      - git fetch origin ${CI_COMMIT_TARGET_BRANCH}
      - pnpm exec commitlint --from origin/${CI_COMMIT_TARGET_BRANCH}
    when:
      event: pull_request
  build:
    depends_on: [lint, formatcheck, typecheck, test, reuse]
    image: *node_image
    commands:
      - export APPDATA=$(pwd)
      - <<: *enable_pnpm
      - pnpm build
