name: deploy to gh-pages

on:
  push:
    branches:
      - master

jobs:
  gh-pages:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: actions/setup-node@v1
        with:
          node-version: "10.x"

      - name: setup env
        run: |
          echo "NODE_VERSION=$(node --version)" >> $GITHUB_ENV

      - name: Cache node modules
        uses: actions/cache@v1
        env:
          cache-name: cache-node-modules
        with:
          path: node_modules
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{env.NODE_VERSION}}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-${{env.NODE_VERSION}}-

      - name: npm install
        run: npm install

      - name: build
        run: npm run build-storybook

      - name: deploy to gh-pages
        uses: JamesIves/github-pages-deploy-action@releases/v3
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BRANCH: gh-pages
          FOLDER: .out
          CLEAN: true
          SINGLE_COMMIT: true