when:
  - branch: main

steps:
  build-and-publish:
    image: node:20-alpine
    secrets:
      - codeberg_ssh_key
    commands:
      - apk add git openssh-client
      - git config --global user.email "woodpecker@bot.net"
      - git config --global user.name "woodpecker-bot"
      - git remote add codeberg-ssh git@codeberg.org:aleidk/personal-page.git
      - mkdir -p $HOME/.ssh
      - ssh-keyscan -t rsa codeberg.org >> $HOME/.ssh/known_hosts
      - echo "$CODEBERG_SSH_KEY" > $HOME/.ssh/id_rsa
      - chmod 0600 $HOME/.ssh/id_rsa
      - corepack enable
      - corepack prepare pnpm@latest --activate
      - pnpm install
      - pnpm build
      - |
        cat >dist/.domains <<EOL
        blog.panconpalta.win
        personal-page.aleidk.codeberg.page
        pages.personal-page.aleidk.codeberg.page
        EOL
      - pnpm exec gh-pages --dist dist --branch pages --dotfiles --remote codeberg-ssh
