on:
  push:
    branches:
      - master

name: master
jobs:
  publish:
    runs-on: ubuntu-latest
    if: "!contains(github.event.head_commit.message, 'VERSION-SKIP-CI')"
    strategy:
      matrix:
        python-version: [ 3.8 ]
    steps:
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - uses: actions/checkout@master
        with:
          persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
          fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
      - name: build
        run: |
          python -m pip install --upgrade pip
          pip install setuptools
          make install
          make sdist
      - name: commit version
        run: |
          git add VERSION.txt
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git add .
          git commit -m "VERSION-SKIP-CI"
      - name: Push version
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.TOKEN_CICD }}
          branch: "master"
          force: true
      - name: make doc
        run: |
          make doc
      - name: commit doc
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git add .
          git commit -m "docs"
      - name: Push doc
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.TOKEN_CICD }}
          branch: "gh-pages"
          force: true
      - name: topypi
        uses: pypa/gh-action-pypi-publish@master
        with:
          user: ${{ secrets.pypi_login }}
          password: ${{ secrets.pypi_passwd }}
          skip_existing: true
          verbose: true
      - name: todocker
        uses: docker/build-push-action@v1
        with:
          username: ${{ secrets.docker_login }}
          password: ${{ secrets.docker_passwd }}
          repository: cottephi/tablewriter
          tag_with_ref: true