diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..cc8454b --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,60 @@ +# This workflow will install Python dependencies and run tests with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Create test environment file + working-directory: ./app + run: | + echo '${{ secrets.TEST_ENV_FILE }}' > .env.test + - name: Set up Python 3.14 + uses: actions/setup-python@v6 + with: + python-version: "3.14" + - name: Install dependencies + working-directory: ./app + run: | + python -m pip install --upgrade pip + pip install pip-tools + pip-sync + - name: Test database connection + working-directory: ./app + run: | + python -c " + from dotenv import load_dotenv + load_dotenv('.env.test') + import psycopg2 + import os + try: + conn = psycopg2.connect( + host=os.getenv('DB_HOST'), + database=os.getenv('DB_DATABASE'), + user=os.getenv('DB_USER'), + password=os.getenv('DB_PASSWORD'), + port=os.getenv('DB_PORT') + ) + print('Database connection successful') + conn.close() + except Exception as e: + print(f'Database connection failed: {e}') + exit(1) + " + - name: Test with pytest + working-directory: ./app + run: | + python -m pytest