name: Continuous Deployment

on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@main
      - uses: actions/setup-node@main
        with:
          node-version: 16
      
      - name: Install dependencies
        run: |
          npm ci
          cd functions && npm ci
        
      - name: Run Vue.js unit tests
        run: npm run test:unit
      
      - run: npm run build
      - uses: w9jds/firebase-action@master
        with:
          args: deploy
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
      
      - name: Run Firebase integration tests
        run: npm run test
        working-directory: ./functions

      - name: Update Firestore database with train data
        uses: satak/webrequest-action@master
        with:
          url: https://us-central1-irishrailtracker.cloudfunctions.net/postLiveTrainData
          method: GET
      
      - name: Update Firestore database with station data
        uses: satak/webrequest-action@master
        with:
          url: https://us-central1-irishrailtracker.cloudfunctions.net/postStationData
          method: GET