on: [push]
jobs:
  test_checkout:
    runs-on: debian
    steps:
      - run: apt-get update -y && apt-get install -y git curl pdf2svg
      - run: |
          curl -L -O https://github.com/gohugoio/hugo/releases/download/v0.124.1/hugo_extended_0.124.1_linux-amd64.deb
          dpkg -i ./hugo_extended_0.124.1_linux-amd64.deb          
      - run: |
          TOKEN=$(echo -n "x-access-token:${GITHUB_TOKEN}" | base64)
          mkdir -p "${GITHUB_WORKSPACE}"
          cd "${GITHUB_WORKSPACE}"
          git init
          git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
          git -c http.extraHeader="Authorization: Basic ${TOKEN}" fetch origin "${GITHUB_SHA}"
          git checkout "${GITHUB_SHA}"
          git submodule update --init --recursive          
      - run: |
          cd "${GITHUB_WORKSPACE}"
          pdf2svg content/cv.pdf content/cv.svg
          hugo --minify
          cp "${GITHUB_WORKSPACE}/.domains" "${GITHUB_WORKSPACE}/public/"
      - run: |
          cd "${GITHUB_WORKSPACE}/public/"
          git init
          git config user.email "ci_action@example.com"
          git config user.name "CI"
          git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
          TOKEN=$(echo -n "x-access-token:${GITHUB_TOKEN}" | base64)
          git -c http.extraHeader="Authorization: Basic ${TOKEN}" push origin -d pages || true
          git checkout -b pages
          git add .
          git commit -m "gen pages"
          git -c http.extraHeader="Authorization: Basic ${TOKEN}" push -u origin pages
