FastAPI-Project / .github /workflows /build-deploy.yml
abdullah090809's picture
Added CD to Hugging Face
6d7787d
Raw
History Blame Contribute Delete
1.93 kB
name: Build and Deploy Code
on: [push, pull_request]
jobs:
job1:
environment:
name: testing
env:
DATABASE_HOSTNAME: localhost
DATABASE_PORT: 5432
DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
DATABASE_USERNAME: ${{ secrets.DATABASE_USERNAME }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
ALGORITHM: ${{ secrets.ALGORITHM }}
ACCESS_TOKEN_EXPIRE_MINUTES: ${{ secrets.ACCESS_TOKEN_EXPIRE_MINUTES }}
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
POSTGRES_DB: ${{ secrets.DATABASE_NAME }}_test
POSTGRES_USER: ${{ secrets.DATABASE_USERNAME }}
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
runs-on: ubuntu-latest
steps:
- name: Pulling Code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: pytest
deploy:
runs-on: ubuntu-latest
needs: [job1]
environment:
name: deploy
steps:
- name: Pulling code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Push to Hugging Face
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
git config --global user.email "ci@github.com"
git config --global user.name "GitHub Actions"
git remote add hf https://abdullah090809:$HF_TOKEN@huggingface.co/spaces/abdullah090809/fastapi-project
git push hf main --force