name: Generator Volto CI
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [14.x]
        python-version: [3.7]
    steps:
      - uses: actions/checkout@v2
      - name: debug
        working-directory: api
        run: ls -al

      # node setup
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}

      # node cache
      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - uses: actions/cache@v1
        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      # install create-volto-app
      - run: npm -g install ./

      # create a project
      - run: create-volto-app my-volto-app

      # node install
      - run: yarn install --frozen-lockfile

      # install additional deps
      - run: yarn add cypress cypress-file-upload@3.5.3 start-server-and-test xmlrpc

      # Cypress install
      - run: yarn cy:install

      # python setup
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}

      # python cache
      - uses: actions/cache@v1
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
          restore-keys: |
            ${{ runner.os }}-pip-

      # python install
      - run: pip install virtualenv
      - name: pip install
        working-directory: api
        run: pip install -r requirements.txt
      - name: buildout
        working-directory: api
        run: buildout
        env:
          CI: true

      - name: Cypress acceptance tests
        run: yarn ci:cypress:run

      - name: Test if npm packs correctly
        run: npm pack --dry-run
        if: success()
