-
Notifications
You must be signed in to change notification settings - Fork 1
138 lines (117 loc) · 4.08 KB
/
Copy pathcreate_pull_request.yml
File metadata and controls
138 lines (117 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Unit Tests
on:
push:
branches:
- dev
jobs:
test:
runs-on: ubuntu-latest
# Define Redis as a service container
services:
redis:
image: redis
# Map port 6379 on the container to 6379 on the host machine
ports:
- 6379:6379
# Health check to ensure Redis is up before tests run
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
REDIS_HOST: localhost
REDIS_PORT: 6379
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12' # 3.12+ required for PEP 695 generic syntax
cache: 'pip'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install pytest # Ensures pytest is available even if not in requirements.txt
pip install pytest pytest-cov
- name: Create .env file
run: |
echo "DATABASE_URL=sqlite+aiosqlite:///:memory:" >> .env
echo "JWT_SECRET=QQeN+k4IeRh5ziyGIWbKISx7v7g9k6+Ze1ApTOmqzk8=" >> .env
echo "MAIL_USERNAME=$testusername@mail.com" >> .env
echo "MAIL_FROM_NAME=$donotreply" >> .env
echo "MAIL_PASSWORD=secretsMAIL_PASSWORD" >> .env
echo "MAIL_FROM=brianobot9@gmail.com" >> .env
echo "MAIL_PORT=465" >> .env
echo "MAIL_SERVER=smtp.gmail.com" >> .env
- name: Run Tests
id: coverage_step
run: |
mkdir logs
coverage run -m pytest
coverage report --fail-under=90
PERCENT=$(coverage report | grep TOTAL | awk '{print $NF}' | sed 's/%//')
echo "PERCENTAGE=$PERCENT" >> $GITHUB_OUTPUT
- name: Create Coverage Badge
uses: schneegans/dynamic-badges-action@v1.7.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: b56b3d61a5e739fd26252cda094bace2
filename: fastapi_project_structure_coverage.json
label: Coverage
message: ${{ steps.coverage_step.outputs.PERCENTAGE }}%
valColorRange: ${{ steps.coverage_step.outputs.PERCENTAGE }}
maxColorRange: 100
minColorRange: 0
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install tools
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install ruff black isort
- name: Ruff
run: ruff check app conftest.py
- name: Black
run: black --check app conftest.py
- name: isort
run: isort --profile black --check-only app conftest.py
- name: Mypy
run: mypy app
create_pull_request:
runs-on: ubuntu-latest
needs: [test, lint] # gate the auto-PR on tests AND lint/type checks
if: github.actor == 'brianobot'
permissions:
contents: write
pull-requests: write
env:
GITHUB_TOKEN: ${{ secrets.MY_PERSONAL_TOKEN }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Create Pull Request
run: |
# Check if a PR already exists from dev to master
PR_EXISTS=$(gh pr list --head dev --base master --state open --json number -q '.[0].number')
if [ -z "$PR_EXISTS" ]; then
echo "No open PR found. Creating a new one..."
gh pr create \
--head dev \
--base master \
--title "Auto-PR: Dev to Master" \
--body "Automated PR triggered by push from ${{ github.actor }}" \
--assignee "${{ github.actor }}"
else
echo "PR already exists: #$PR_EXISTS. Skipping creation."
fi