name: API Continuous Integration

on: [push]

jobs:
  test:
    name: Run all tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x]
        mongodb-version: ["6.0"]
    steps:
      - uses: actions/checkout@v5
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v6
        with:
          node-version: ${{ matrix.node-version }}
      - name: Start MongoDB
        uses: supercharge/mongodb-github-action@1.12.0
        with:
          mongodb-version: ${{ matrix.mongodb-version }}

#      - name: Get yarn cache directory path
#        id: yarn-cache-dir-path
#        run: echo "::set-output name=dir::$(yarn cache dir)"
#      - uses: actions/cache@v3
#        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
#        with:
#          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
#          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
#          restore-keys: |
#            ${{ runner.os }}-yarn-

      - name: Install whole project dependencies
        # if: steps.yarn-cache.outputs.cache-hit != 'true' # I think we want to install every time,
        # but use the cache?
        run: yarn --frozen-lockfile
      - name: yarn lint
        run: yarn lint
      - name: yarn build
        run: yarn build
      - name: yarn test
        run: yarn test
        env:
          CI: true
      # TODO: re-enable Slack webhooks when we set up slack.
      # - name: Slack Notification
      #   uses: rtCamp/action-slack-notify@v2
      #   env:
      #     SLACK_CHANNEL: bots
      #     SLACK_COLOR: "#4BB543"
      #     # SLACK_MESSAGE: "Post Content :rocket:"
      #     SLACK_TITLE: Totum API tests passed!
      #     SLACK_USERNAME: ValDev
      #     SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
      # - name: The job has failed
      #   if: ${{ failure() }}
      #   uses: rtCamp/action-slack-notify@v2
      #   env:
      #     SLACK_CHANNEL: bots
      #     SLACK_COLOR: "#FF0000"
      #     # SLACK_MESSAGE: "Post Content :rocket:"
      #     SLACK_TITLE: Mongoose REST Framework  tests failed :(
      #     SLACK_USERNAME: ValDev
      #     SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
