From bda859b41311e2637647b3e07cfce29c62f0259c Mon Sep 17 00:00:00 2001 From: iamprecieee Date: Fri, 21 Feb 2025 03:38:50 +0100 Subject: [PATCH] chore(deploy): set up ci/cd pipelines - add ci workflow to run pytest on pull request to staging - add cd workflow to auto-deploy on push to main --- .github/workflows/deploy.yml | 26 ++++++++++++++++++++++++++ .github/workflows/pytest.yml | 27 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/pytest.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..7cd5627 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,26 @@ +name: CD pipeline to auto-deploy on merges to main + +on: + push: + branches: + - main + +jobs: + auto-deploy: + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + + steps: + - name: deploy app + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.KEY }} + script: | + cd commit-quality-monitor + git pull origin main + source ./venv/bin/activate + pip install -r requirements.txt + sudo systemctl restart fastapi + sudo systemctl restart nginx \ No newline at end of file diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..1add64b --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,27 @@ +name: CI pipeline to run pytest on pull requests + +on: + pull_request: + branches: + - staging + +jobs: + pytest: + runs-on: ubuntu-latest + steps: + - name: Checkout repository for workflow access + uses: actions/checkout@v4 + + - name: set up python environment + uses: actions/setup-python@v3 + with: + python-version: '3.8' + + - name: install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: run tests + run: | + pytest \ No newline at end of file