name: CI
on:
  push:
    tags:
      - v*
    branches:
      - main
  pull_request:

permissions:
  # none-all, which doesn't exist, but
  # https://docs.github.com/en/actions/reference/authentication-in-a-workflow#using-the-github_token-in-a-workflow
  # implies that the token still gets created.  Elsewhere we learn that any
  # permission not mentioned here gets turned to `none`.
  actions: none

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4.6.1
        with:
          cache: 'pip'
      - name: install dependencies
        run: |
          sudo apt-get update -y
          sudo apt-get install -y libnss-db libdb-dev libcurl4-gnutls-dev libgnutls28-dev libldap2-dev libsasl2-dev
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          pip install pytest-github-actions-annotate-failures
      - name: Test
        run: |
          mkdir -p test-results
          if [[ ${{ github.event_name }} == 'pull_request' ]]; then
             echo ${{ github.event.pull_request.head.sha }}  > test-results/sha-number
          else
             echo ${{ github.sha }} > test-results/sha-number
          fi
          python setup.py test --addopts "-v --durations=0 --junitxml=test-results/junit.xml --cov=nss_cache"
      - uses: codecov/codecov-action@v3
        if: always()
      - name: Install
        run: pip install --user .
      - name: slapd Regression Test
        run: |
          sudo apt-get install -y slapd ldap-utils libnss-db db-util
          tests/slapd-regtest
      - uses: actions/upload-artifact@v3
        if: always()
        with:
          name: test-results
          path: test-results/
      - name: pylint
        run: |
          pip install pylint
          pylint nsscache nss_cache
        # TODO(jaq): eventually make this lint clean and remove this line
        continue-on-error: true
