name: Deploy to heroku + publish to NPM

on:
  release:
    types: [created]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
      - name: Install dependencies
        run: |
          npm ci
          
      - name: Linting
        run: npm run lint
        
      - name: Run tests
        run: npm test
        
      - uses: akhileshns/heroku-deploy@v3.6.8
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: "cabdriver"
          heroku_email: ${{secrets.HEROKU_EMAIL}}

  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 12
      - run: npm install
      - run: npm test
      - uses: JS-DevTools/npm-publish@v1
        with:
          token: ${{ secrets.NPM_TOKEN }}
