pipeline:
  apko-image:
    image: distroless.dev/apko:latest
    commands:
      - echo $REGISTRY_SECRET | apko login --username ariadne --password-stdin gitea.treehouse.systems
      - apko publish --arch $(uname -m) apko.yaml gitea.treehouse.systems/ariadne/ariadne.space-hugo:latest
    secrets: [REGISTRY_SECRET]

  deploy:
    image: gitea.treehouse.systems/ariadne/ariadne.space-hugo:latest
    commands:
      # build the new site
      - hugo

      # fetch the old newswire
      - curl -s https://ariadne.space/newswire.txt > oldnewswire.txt

      # set up the SSH deployment key and upload the site
      - | 
          mkdir $HOME/.ssh
          echo "$SSH_KEY">$HOME/.ssh/id_ed25519
          echo "$SSH_KNOWN_HOSTS">$HOME/.ssh/known_hosts
          chown 600 $HOME/.ssh/id_ed25519
          rsync -avHAX public/ kaniini@ariadne.space:public/

      # if the newswire has changed, publish the new one.
      - |
          cmp oldnewswire.txt public/newswire.txt || \
              curl -s -H "Authorization: Bearer $MASTODON_SECRET" -F "status=$(cat public/newswire.txt)" \
              https://social.treehouse.systems/api/v1/statuses

    secrets: [SSH_KEY, SSH_KNOWN_HOSTS, MASTODON_SECRET]
