name: build
on: 
  push:
    branches: [master]
  pull_request:
    branches: [master]
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2.3.4
        with:
          lfs: true
          fetch-depth: 0
          fetch-tags: true
      - name: build
        run: |
          sudo gem install asciidoctor
          sudo gem install asciidoctor-pdf
          sudo gem install asciidoctor-diagram
          sudo gem install asciidoctor-multipage
          sudo apt install graphviz
          make documentation
          sed -i "s/locale\/ru\/_images\//https:\/\/raw.githubusercontent.com\/zamtmn\/zcad\/gh-pages\/locale\/ru\/_images\//g" cad_source/docs/userguide/userguide.ru.html
          sed -i "s/..\/images\/actions\//https:\/\/raw.githubusercontent.com\/zamtmn\/zcad\/gh-pages\/images_actions\/actions\//g" cad_source/docs/userguide/userguide.ru.html
          sed -i "s/_быстрый_старт/https:\/\/raw.githack.com\/zamtmn\/zcad\/gh-pages\/_быстрый_старт/g" cad_source/docs/userguide/userguide.ru.html
          sed -i "s/_для_разработчика/https:\/\/raw.githack.com\/zamtmn\/zcad\/gh-pages\/_для_разработчика/g" cad_source/docs/userguide/userguide.ru.html
          sed -i "s/_настройка_программы/https:\/\/raw.githack.com\/zamtmn\/zcad\/gh-pages\/_настройка_программы/g" cad_source/docs/userguide/userguide.ru.html
          sed -i "s/_общая_информация/https:\/\/raw.githack.com\/zamtmn\/zcad\/gh-pages\/_общая_информация/g" cad_source/docs/userguide/userguide.ru.html
          sed -i "s/_работа_с_программой/https:\/\/raw.githack.com\/zamtmn\/zcad\/gh-pages\/_работа_с_программой/g" cad_source/docs/userguide/userguide.ru.html
          cp -r cad_source/docs/images cad_source/docs/userguide/images_actions
          cp cad_source/docs/userguide/userguide.ru.html cad_source/docs/userguide/index.html
      - name: GitHub Pages
        if: success() && github.ref == 'refs/heads/master'
        uses: crazy-max/ghaction-github-pages@v2.3.0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          build_dir: cad_source/docs/userguide