python-package.yml - CI configuration

This workflow will install Python dependencies, run tests and lint with a variety of Python versions For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

 
name: BookServer Tests

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      BOOK_SERVER_CONFIG: test
      TEST_DBURL: postgresql://postgres:foo@localhost/runestone
      RUNESTONE_PATH: ${{ github.workspace }}/../RunestoneServer
      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
    strategy:
      matrix:
        python-version: ["3.8", "3.9"]

    steps:
      - name: Check out bookserver from GitHub.
        uses: actions/checkout@v2
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: Start Redis
        uses: supercharge/redis-github-action@1.2.0
        with:
          redis-version: 6
      - name: Install pre-reqs
        run: |
          # Start PostgreSQL. It's pre-installed; using a Docker image means we need to also install a client locally, and it's easy for the versions of the two to get out of sync and cause very weird errors.
          sudo systemctl start postgresql.service
          # Wait until the database is ready.
          pg_isready
          # Set a password for the postgres user to match the password in the ``TEST_DBURL`` above.
          sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'foo';"

          # Install and build the Runestone Components.
          mkdir ../RunestoneComponents
          git clone https://github.com/RunestoneInteractive/RunestoneComponents.git ../RunestoneComponents
          pushd ../RunestoneComponents
          npm install
          npm run build
          popd

          # Install the old server
          git clone https://github.com/RunestoneInteractive/RunestoneServer.git ../RunestoneServer

          # Prep pip for bookserver installation.
          pip install -U pip
          pip install poetry
      - name: Install bookserver
        run: |
          poetry install
      - name: Run the Pre Commit Check Script
        run: |
          poetry run python ./pre_commit_check.py

      - uses: act10ns/slack@v1
        with:
            status: ${{ job.status }}
            steps: ${{ toJson(steps) }}
            channel: "#builds"
        if: always()