-
Notifications
You must be signed in to change notification settings - Fork 1
107 lines (93 loc) · 3.35 KB
/
create_pull_request.yml
File metadata and controls
107 lines (93 loc) · 3.35 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
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.11' # You can change this to your preferred version
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=23oiefnergoiejrgio" >> .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
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
create_pull_request:
runs-on: ubuntu-latest
needs: test # This creates the dependency link
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