image: alpine/edge
packages:
  - curl
  - git
  - py3-pip
  - python3
sources:
  - https://git.sr.ht/~sumner/sublime-music
secrets:
  # README Personal Access Token
  - 2fb5fd72-fa96-46c6-ab90-6b7cabebba16
environment:
  REPO_NAME: sublime-music
triggers:
  - action: email
    condition: failure
    to: ~sumner/sublime-music-devel@lists.sr.ht
tasks:
  # Skip everything if not on master.
  - skip_not_master: |
      cd $REPO_NAME
      git branch --contains | grep master || echo "Skipping README deploy since not on master"
      git branch --contains | grep master || complete-build

  - setup: |
      pip3 install rst2html5
      echo "cd ${REPO_NAME}" >> ~/.buildenv
      echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.buildenv

  - readme: |
      set +x
      set -e
      rst2html5 --template="{body}" README.rst |                            \
        curl -H "Content-Type: text/html"                                   \
             -H "Authorization: Bearer $(cat ~/.readme-token)"              \
             -XPUT                                                          \
             --data-binary @-                                               \
             "https://git.sr.ht/api/repos/${REPO_NAME}/readme"
