name: CI and testing (feature branch)

on:
  push:
    branches:
      - 'feature/*'
      - 'hotfix/*'
  pull_request:
    branches:
      - 'feature/*'
      - 'hotfix/*'

jobs:
  build-unix:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: ['ubuntu-latest', 'macos-latest']
        node-version: [12.x, 14.x]
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        id: checkout

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        id: node
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm ci
      - run: npm run build --if-present
      - run: npm audit fix
      - run: npm test
        env:
          FIGMA_TOKEN: ${{ secrets.FIGMA_TOKEN }}
          FIGMA_URL: ${{ secrets.FIGMA_URL }}
      - run: npm install -g
      - run: npm run figmagic
        env:
          FIGMA_TOKEN: ${{ secrets.FIGMA_TOKEN }}
          FIGMA_URL: ${{ secrets.FIGMA_URL }}
      - run: \[ -d .figmagic \]
      - run: \[ -f .figmagic/figma.json \]
        env:
          CI: true

  build-windows:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: ['windows-latest']
        node-version: [12.x, 14.x]
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        id: checkout

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        id: node
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm ci
      - run: npm run build --if-present
      - run: npm audit fix
      - run: npm test
        env:
          FIGMA_TOKEN: ${{ secrets.FIGMA_TOKEN }}
          FIGMA_URL: ${{ secrets.FIGMA_URL }}
      - run: npm install -g
      - run: npm run figmagic
        env:
          FIGMA_TOKEN: ${{ secrets.FIGMA_TOKEN }}
          FIGMA_URL: ${{ secrets.FIGMA_URL }}
      - run: Test-Path .figmagic
      - run: Test-Path .figmagic/figma.json -PathType leaf
        env:
          CI: true
