-
Notifications
You must be signed in to change notification settings - Fork 7
166 lines (153 loc) · 5.25 KB
/
swan_pr_workflow.yml
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# GitHub action file for SwanHub SDK
name: SwanHub SDK Application Workflow
# Triggers the workflow on push or pull request
on:
push: # Triggered on a push to any branch ( do not change )
schedule:
# Run workflow at 4 AM EST (9 AM UTC)
- cron: '0 9 * * *'
# Run workflow at 7 PM EST (12 AM UTC next day)
- cron: '0 0 * * *'
release:
types: [ created ] # Triggers the workflow when a release is created.
# Defines the jobs that the workflow will execute
jobs:
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install black
run: |
pip3 install black
- name: Lint with Black
run: |
black --check ./**/*.py
TypeCheck:
needs: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install mypy and type stubs
run: |
pip3 install mypy
pip3 install types-requests
- name: Type Check with Mypy
run: |
mypy --ignore-missing-imports ./**/*.py
Test:
needs: TypeCheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install pytest
run: |
pip3 install -r requirements.txt
- name: Run tests
run: pytest
Build:
needs: Test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev'
steps:
- uses: actions/checkout@v4
- name: Cleanup /dist directory
run: |
rm -rf ./dist/*
- name: Build the project
run: |
python setup.py sdist bdist_wheel
# UNCOMMENT ONLY AFTER PM DECISION
Deployments:
needs: Build
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'created' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev')
steps:
- uses: actions/checkout@v4
- name: Download dependencies artifact
uses: actions/download-artifact@v2
with:
name: dependencies
- name: Load dependencies from cache
run: |
python -m pip3 install --no-index --find-links=dependencies twine
- name: Publish to PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
twine upload dist/*
# UNCOMMENT ONLY AFTER PM DECISION (Pluto)
# # Database setup job
# setup-database:
# runs-on: ubuntu-latest
# services: # Define the PostgreSQL service
# postgres:
# image: postgres:latest
# env:
# POSTGRES_DB: test_db # Database name
# POSTGRES_USER: test_user # Desired username
# POSTGRES_PASSWORD: test_password # Desired password
# ports:
# - 5432:5432
# steps:
# - name: Wait for PostgreSQL to start
# run: |
# for i in {1..30}; do
# nc -z localhost 5432 && break
# sleep 1
# done
# sleep 10
#
# - name: Install Python Dependencies
# run: |
# sudo apt-get -y install python3-pip3
# pip3 install --upgrade pip3
#
# - name: Database Setup Steps
# run: |
# python setup_database.py
# # Create a setup_database.py file and run it here
notify_reviewers:
needs: [ Lint, Test ] # Depends on the completion of previous jobs
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
# Optionally fetch PR information using GitHub API
- name: Get PR information
id: pr_info
run: |
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
PR_DATA=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER)
PR_REVIEWERS=$(echo $PR_DATA | jq -r '.requested_reviewers | .[].login')
echo "PR_REVIEWERS=$PR_REVIEWERS" >> $GITHUB_ENV
- name: Determine build status
run: |
if [[ ${{ needs.Lint.result }} == 'success' && ${{ needs.Test.result }} == 'success' && ${{ needs.Build.result }} == 'success' ]]; then
echo "BUILD_STATUS=succeeded" >> $GITHUB_ENV
else
echo "BUILD_STATUS=failed" >> $GITHUB_ENV
fi
# Send email notification
- name: Send email notification
uses: dawidd6/action-send-mail@v3
with:
# Add your email server configuration here
server_address: smtp.nbai.io
server_port: 587
username: ${{ secrets.EMAIL_USERNAME }}
password: ${{ secrets.EMAIL_PASSWORD }}
subject: SwanHub SDK PR Review Notification
# You can customize the body based on success or failure of previous jobs
body: |
body: Build ${{ env.BUILD_STATUS }}. Please review the PR.
to: ${{ env.PR_REVIEWERS }}
from: Your Name <arash.khosravi@nbai.com>
# Permissions setup for the workflow
permissions:
contents: read # Grants read access to the repository contents
pull-requests: write # Grants write access to pull requests
issues: write # Grants write access to issues (optional)
actions: read # Grants read access to other GitHub Actions workflows