# Exclude page pipeline to be run on "pages" branch
when:
  branch:
    exclude: pages

# Recursive cloning is used to fully clone the themes given as Git submodules
clone:
  git:
    image: woodpeckerci/plugin-git
    settings:
      recursive: true

steps:
  # Build zola static files
  build:
    image: alpine
    commands:
      - apk add zola
      - zola build
    when:
      event: [ pull_request, push ]

  publish:
    image: bitnami/git
    # Must be set in Woodpecker configuration
    secrets: [ mail, codeberg_token ]
    commands:
      # Git configuration
      - git config --global user.email $MAIL
      - git config --global user.name "Woodpecker CI"
      - git clone -b pages https://$CODEBERG_TOKEN@codeberg.org/$CI_REPO.git $CI_REPO_NAME
      # Enter repository folder
      - cd $CI_REPO_NAME
      # Remove old files from repository folder
      - git rm -r "*"
      # Copy build step output to repository folder
      - cp -ar ../public/. .
      # Commit and push all static files with source commit SHA
      - git add --all
      - git commit -m "Woodpecker CI ${CI_COMMIT_SHA} [SKIP CI]"
      - git push
    when:
      event: push
