---
kind: pipeline
name: test

platform:
  os: linux
  arch: amd64

steps:
  - name: eslint
    image: node:lts
    commands:
      - npm install > /dev/null
      - npm run lint
    environment:
      FORCE_COLOR: true
      NPM_CONFIG_LOGLEVEL: error

  - name: assets
    image: node:lts
    commands:
      - npm install > /dev/null
      - npm run build
    environment:
      FORCE_COLOR: true
      NPM_CONFIG_LOGLEVEL: error

  - name: testbuild
    image: thegeeklab/hugo:0.93.2
    commands:
      - mkdir -p exampleSite/themes/ && ln -s $(pwd)/ exampleSite/themes/hugo-geekdoc
      - hugo --panicOnWarning -s exampleSite/ -b http://localhost/

  - name: html-validation
    image: thegeeklab/vnu
    commands:
      - vnu --skip-non-html --also-check-css --errors-only --filterfile .vnuignore exampleSite/public

  - name: link-validation
    image: thegeeklab/link-validator
    commands:
      - link-validator -ro --exclude "https://github.com/thegeeklab/hugo-geekdoc/edit/main/*"
    environment:
      LINK_VALIDATOR_BASE_DIR: exampleSite/public

  - name: page-validation
    image: thegeeklab/lhci
    commands:
      - lhci autorun
    environment:
      LHCI_SERVER_URL: https://drone-artifact.rknet.org/${DRONE_REPO_NAME}/

  - name: page-validation-upload
    image: plugins/s3
    settings:
      access_key:
        from_secret: s3_access_key
      bucket: drone-artifact
      endpoint: https://sp.rknet.org
      path_style: true
      secret_key:
        from_secret: s3_secret_access_key
      source: lhci_reports/dist/*
      strip_prefix: lhci_reports/dist/
      target: /${DRONE_REPO_NAME}
    when:
      status:
        - failure
        - success

  - name: page-validation-link
    image: thegeeklab/drone-github-comment
    settings:
      api_key:
        from_secret: github_token
      key: pr-${DRONE_PULL_REQUEST}
      message: lhci_reports/dist/summary.md
      skip_missing: true
      update: true
    when:
      ref:
        - refs/pull/**
      status:
        - failure
        - success

trigger:
  ref:
    - refs/heads/main
    - refs/tags/**
    - refs/pull/**

---
kind: pipeline
name: build

platform:
  os: linux
  arch: amd64

steps:
  - name: assets
    image: node:lts
    commands:
      - npm install > /dev/null
      - npm run build
    environment:
      FORCE_COLOR: true
      NPM_CONFIG_LOGLEVEL: error

  - name: package
    image: thegeeklab/alpine-tools
    commands:
      - echo "${DRONE_TAG:-latest}" > VERSION
      - tar -zcvf dist/hugo-geekdoc.tar.gz -X .tarignore .

  - name: checksum
    image: thegeeklab/alpine-tools
    commands:
      - cd dist/ && sha256sum * > ../sha256sum.txt

  - name: changelog
    image: thegeeklab/git-chglog
    commands:
      - git fetch -tq
      - git-chglog --no-color --no-emoji ${DRONE_TAG:---next-tag unreleased unreleased}
      - git-chglog --no-color --no-emoji -o CHANGELOG.md ${DRONE_TAG:---next-tag unreleased unreleased}

  - name: release
    image: plugins/github-release
    settings:
      api_key:
        from_secret: github_token
      files:
        - dist/*
        - sha256sum.txt
      note: CHANGELOG.md
      overwrite: true
      title: ${DRONE_TAG}
    when:
      ref:
        - refs/tags/**

trigger:
  ref:
    - refs/heads/main
    - refs/tags/**
    - refs/pull/**

depends_on:
  - test

---
kind: pipeline
name: docs

platform:
  os: linux
  arch: amd64

concurrency:
  limit: 1

steps:
  - name: markdownlint
    image: thegeeklab/markdownlint-cli
    commands:
      - markdownlint 'exampleSite/content/**/*.md' 'README.md'

  - name: spellcheck
    image: node:lts-alpine
    commands:
      - npm install -g spellchecker-cli
      - spellchecker --files 'exampleSite/content/**/*.md' 'README.md' -d .dictionary -p spell indefinite-article syntax-urls frontmatter --frontmatter-keys title --no-suggestions
    environment:
      FORCE_COLOR: true
      NPM_CONFIG_LOGLEVEL: error

  - name: assets
    image: node:lts
    commands:
      - npm install > /dev/null
      - npm run svg-sprite-list
      - mkdir -p exampleSite/themes/hugo-geekdoc/
      - curl -sSL https://github.com/thegeeklab/hugo-geekdoc/releases/latest/download/hugo-geekdoc.tar.gz | tar -xz -C exampleSite/themes/hugo-geekdoc/ --strip-components=1
    when:
      ref:
        - refs/heads/main
        - refs/tags/**

  - name: assets-main
    image: node:lts
    commands:
      - npm install > /dev/null
      - npm run build
      - npm run svg-sprite-list
      - mkdir -p exampleSite/themes/ && ln -s $(pwd)/ exampleSite/themes/hugo-geekdoc
    environment:
      FORCE_COLOR: true
      NPM_CONFIG_LOGLEVEL: error
    when:
      ref:
        - refs/pull/**

  - name: build
    image: thegeeklab/hugo:0.93.2
    commands:
      - hugo --panicOnWarning -s exampleSite/

  - name: beautify
    image: node:lts-alpine
    commands:
      - npm install -g js-beautify
      - html-beautify -r -f 'exampleSite/public/**/*.html'
    environment:
      FORCE_COLOR: true
      NPM_CONFIG_LOGLEVEL: error

  - name: publish
    image: plugins/s3-sync
    settings:
      access_key:
        from_secret: s3_access_key
      bucket: geekdocs-root
      delete: true
      endpoint: https://sp.rknet.org
      path_style: true
      secret_key:
        from_secret: s3_secret_access_key
      source: exampleSite/public/
      strip_prefix: exampleSite/public/
    when:
      ref:
        - refs/heads/main
        - refs/tags/**

trigger:
  ref:
    - refs/heads/main
    - refs/tags/**
    - refs/pull/**

depends_on:
  - build

---
kind: pipeline
name: notifications

platform:
  os: linux
  arch: amd64

steps:
  - name: matrix
    image: thegeeklab/drone-matrix
    settings:
      homeserver:
        from_secret: matrix_homeserver
      password:
        from_secret: matrix_password
      roomid:
        from_secret: matrix_roomid
      template: "Status: **{{ build.Status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.Link }}){{#if build.Branch}} ({{ build.Branch }}){{/if}} by {{ commit.Author }}<br/> Message: {{ commit.Message.Title }}"
      username:
        from_secret: matrix_username
    when:
      status:
        - success
        - failure

trigger:
  ref:
    - refs/heads/main
    - refs/tags/**
  status:
    - success
    - failure

depends_on:
  - test
  - build
  - docs

---
kind: signature
hmac: bd8e739515bc29102da412272b61aa89cf18f9b4d1f62b502172131a51009c71

...