name: Publish

on:
  push:
    branches:
      - master

jobs:
  publish:
    runs-on: ubuntu-20.04

    services:
      memcached:
        image: memcached:latest
        ports:
        - 11211:11211
        options: >-
          --health-cmd "timeout 5 bash -c 'cat < /dev/null > /dev/udp/127.0.0.1/11211'" 
          --health-interval 10s 
          --health-timeout 5s
          --health-retries 5
      rabbitmq:
        image: rabbitmq:latest
        ports:
        - 5672:5672
        options: >-
          --health-cmd "rabbitmq-diagnostics -q ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    strategy:
      matrix:
        node-version: [8.11.4]

    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Set up Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
        registry-url: 'https://registry.npmjs.org'
        always-auth: true

    - name: Install project dependencies
      run: |
        npm install

    - name: Build and Test
      run: |
        export CXX="g++-4.8"
        npm test

    - name: Publish to npm
      run: npm publish
      env:
        NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}