name: github pages

on:
  push:
    branches:
      - main  # Set a branch to deploy

jobs:
  deploy:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: true  # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0    # Fetch all history for .GitInfo and .Lastmod

      - uses: FedericoCarboni/setup-ffmpeg@v2
        id: setup-ffmpeg

      - name: Run shell
        run: bash -x ./scripts/duration-length.sh
        shell: bash

      # deploy to duration-length-content branch in local repository
      - name: deploy duration-length-content branch
        uses: s0/git-publish-subdir-action@develop
        env:
          REPO: self
          BRANCH: duration-length-content
          FOLDER: content
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Clone ox-hugo
        run: git clone https://github.com/jsntn/ox-hugo.git ox-hugo

      - name: Set up Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: '0.87.0'
          extended: true

      - name: Build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./public
          cname: shufang.org

      - name: executing remote ssh commands using password
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          password: ${{ secrets.PASSWORD }}
          port: ${{ secrets.PORT }}
          script: whoami; cd ${{ secrets.WEBSITE_ABS_PATH }}; git pull
