name: CI
on: [push, pull_request]
permissions:
  contents: read

jobs:
  build:

    runs-on: ubuntu-20.04
    strategy:
      matrix:
        python-version: [3.6, 3.7, 3.8, 3.9, "3.10", 3.11, 3.12, pypy2.7, pypy3.9]

    steps:
    - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
      with:
        python-version: ${{ matrix.python-version }}
        allow-prereleases: true
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install protobuf==3.17.3 pycodestyle
    - name: Lint
      run: make -C tools/python lint
    - name: Test
      run: |
        make -C tools/python metaclean
        make -C tools/python test
        # Check re-generation didn't change anything (except locale.py)
        git checkout --  python/phonenumbers/geodata/locale.py
        status=$(git status --porcelain ) || :
        if [[ -n ${status} ]]; then
         echo "Regenerated files differ from checked-in versions: ${status}"
         git status
         exit 1
        fi
