name: build

on:
  push:
    branches:
      - master
  pull_request:

jobs:
  build:
    if: "!contains(github.event.commits[0].message, '[skip ci]')"
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
    - uses: actions/checkout@v1

    - name: Install npm dependencies
      run: yarn install

    - name: Build
      run: yarn build

    - name: Run linters
      run: yarn lint

    - name: Run tests
      run: yarn test

    - name: Test in node
      run: node test/require-in-node

    - name: Check TypeScript
      run: |
        tsc --lib dom,es6 --noEmit test/ts/simple-usage.ts sweetalert2.d.ts
        tsc --lib dom,es6 --noEmit test/ts/dist-sweetalert2.ts sweetalert2.d.ts
        tsc --lib dom,es6 --noEmit test/ts/src-sweetalert2.ts sweetalert2.d.ts

    - name: Run automated release process with semantic-release
      if: github.event_name == 'push'
      uses: cycjimmy/semantic-release-action@v2
      with:
        extra_plugins: |
          @semantic-release/changelog
          @semantic-release/git
          @semantic-release/exec
      env:
        GH_TOKEN: ${{ secrets.GH_TOKEN }}
        NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

    - name: Report bundlezise to bundlewatch.io
      env:
        BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
      run: |
        yarn add --dev bundlewatch
        ./node_modules/.bin/bundlewatch
