# This is a basic workflow to help you get started with Actions

name: Release with Testing

# Controls when the action will run. 
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  release:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [15.x]

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - name: Cache Node.js modules
      uses: actions/cache@v2
      with:
        # npm cache files are stored in `~/.npm` on Linux/macOS
        path: '**/node_modules'
        key: ${{ runner.OS }}-node-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
        restore-keys: |
          ${{ runner.OS }}-node-${{ matrix.node-version }}
          ${{ runner.OS }}-node-
          ${{ runner.OS }}-
    - name: Install Dependencies
      run: yarn install --frozen-lockfile
    - name: Lint files
      run: yarn lint
    - name: Test
      run: yarn test
    - name: Generate assets
      run: yarn build
    - name: Release via Auto
      env: 
        NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        GH_TOKEN: ${{ secrets.GH_TOKEN }}
      run: |
        git fetch --tags
        yarn release
