name: Run Python Tests permissions: contents: read # ----------------- # --- Triggers ---- # ----------------- # This section defines when the workflow will run. on: # Run on every push to the 'main' branch push: branches: [ "main", "33-frontend-looks-like-logged-in-even-after-token-expires" ] # Also run on every pull request that targets the 'main' branch pull_request: branches: [ "main" ] # ----------------- # ------ Jobs ----- # ----------------- # A workflow is made up of one or more jobs that can run in parallel or sequentially. jobs: build-and-test: runs-on: ubuntu-latest services: mariadb: image: mariadb:11.4 env: MARIADB_ROOT_PASSWORD: rootpw MARIADB_DATABASE: group_project # Using the DB name your app expects MARIADB_USER: appuser MARIADB_PASSWORD: apppass # ADD THIS BLOCK BACK IN # This forces the job to wait until the DB is # actually responding before continuing. options: >- --health-cmd="mysqladmin ping -h 127.0.0.1 -u root -prootpw --silent" --health-interval=5s --health-timeout=2s --health-retries=20 # This is the job-level 'env' block # It will be used by the 'alembic' step env: MARIADB_HOST: mariadb # Use the service label as the host MARIADB_PORT: "3306" MARIADB_DB: group_project MARIADB_USER: appuser MARIADB_PASSWORD: apppass steps: - name: Check out repository code uses: actions/checkout@v4 - name: Set up Python 3.11 uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements.txt # This step will now wait for the healthcheck to pass # and will use the job-level 'env' block - name: Run Alembic migrations run: | alembic upgrade head working-directory: ./7project/backend # This step-level 'env' block overrides any local .env # file that your pytest setup might be loading - name: Run tests with pytest env: MARIADB_HOST: mariadb MARIADB_DB: group_project MARIADB_USER: appuser MARIADB_PASSWORD: apppass run: pytest working-directory: ./7project/backend