name: Deploy
'on':
  - workflow_dispatch
  - push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          ref: dev
      - name: Setup Node
        uses: actions/setup-node@v2
        with:
          node-version: 16.x
      - name: Install Hexo
        run: |
          npm install hexo-cli -g
          npm install -g gulp
      - name: Cache Modules
        uses: actions/cache@v2.1.1
        id: cache-modules
        with:
          path: node_modules
          key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}
      - name: Install Dependencies
        if: steps.cache-modules.outputs.cache-hit != 'true'
        run: |
          npm ci
      - name: Setting themes
        run: |
          git submodule init
          git submodule update
      - name: Setting Token
        run: |
          sed -i "s/.Baidu_Token/${{ secrets.BAIDU_TOKEN }}/" _config.yml
          sed -i "s/.v6_51_la/${{ secrets.v6_51_la }}/" _config.yml
          sed -i "s/.perf_51_la/${{ secrets.perf_51_la }}/" _config.yml
      - name: Generate
        run: |
          hexo clean
          hexo recommend
          hexo generate
          gulp
          git clone https://github.com/qystudio0/qystudio0.github.io.git .public
      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          personal_token: ${{ secrets.PERSONAL_TOKEN }}
          publish_dir: ./public
          external_repository: qystudio0/qystudio0.github.io
          publish_branch: dev
          exclude_assets: ''
          user_name: github-actions[bot]
          user_email: github-actions[bot]@users.noreply.github.com
