name: publish

on:
  push:
    branches:
      - test

jobs:
  publish:
    runs-on: ubuntu-latest
    env:
      SSH_PRIVATE_KEY: ${{ secrets.SSH_DEPLOY_PRIVATE_KEY }}
    steps:
      - name: checkout
        uses: actions/checkout@v4
        with:
          submodules: recursive
          
      - name: setup node
        uses: actions/setup-node@v4
        with:
          node-version: 'lts/*'

      - run: npm ci

      - run: npm run build

      - name: upload artifact
        uses: https://code.forgejo.org/forgejo/upload-artifact@v4
        with:
          path: _site

      - name: deploy
        run: |
          apt-get update && apt-get install -y rsync
          wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq
          eval $(ssh-agent -s)
          echo "$SSH_PRIVATE_KEY" | ssh-add -
          mkdir ~/.ssh
          year=$(yq '.year' content/_data/ese.yaml)
          rsync -rvh --progress --delete --chmod=ugo=rwX _site/ ese-deploy@ifsr.de:"$year"
