name: Publish

on:
  push:
    branches:
      - master
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    # runs all of the steps inside the specified container rather than on the VM host.
    # Because of this the network configuration changes from host based network to a container network.
    container:
      image: node:10.16-jessie

    strategy:
      matrix:
        node-version: [14.x]

    steps:
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@main
        with:
          node-version: ${{ matrix.node-version }}
          registry-url: https://registry.npmjs.org
      - name: Checkout
        uses: actions/checkout@main
      - name: Install
        uses: borales/actions-yarn@master
        with:
          cmd: install # will run `yarn install` command
      - name: Build
        uses: borales/actions-yarn@master
        with:
          cmd: build # will run `yarn build` command
      - name: Test
        uses: borales/actions-yarn@master
        with:
          cmd: test # will run `yarn test` command
      - name: Test Integration
        uses: borales/actions-yarn@master
        with:
          cmd: integration # will run `yarn test` command
      - name: Publish
        if: contains(matrix.node-version, '14.x')
        run: |
          npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
          CI: true
