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

name: Cordova GitHub CI #

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

  # 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"
  test:
    # The type of runner that the job will run on
    runs-on: macOS-11

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      - name: Setup NodeJS 12
        uses: actions/setup-node@v1
        with:
          node-version: "12"

      - name: Cache Node.js modules
        uses: actions/cache@v2
        with:
          # npm cache files are stored in `~/.npm` on Linux/macOS
          path: ~/.npm
          key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.OS }}-node-
            ${{ runner.OS }}-

      - name: Install Dependencies
        run: npm ci

      - name: Lint Plugin
        run: npm run lint

      - name: Build Plugin
        run: npm run build

      - name: Install Cordova CLI
        run: |
          mkdir ~/.npm-global
          npm config set prefix '~/.npm-global'
          export PATH=~/.npm-global/bin:$PATH
          npm install cordova@10 -g

      - name: Create Cordova app, install plugin then build app
        run: |
          npm config set prefix '~/.npm-global'
          export PATH=~/.npm-global/bin:$PATH
          cd ..; cordova create myApp org.apache.cordova.myApp myApp; cd myApp;
          cordova platform add ios@latest --verbose
          cordova plugin add ../cordova-plugin-iosrtc --verbose
          cordova build ios --verbose
