Skip to content

fixed readme

fixed readme #141

# GitHub action file for Swan SDK
name: Swan 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: Swan 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