1+ name : Release Build and Deploy
2+ on :
3+ release :
4+ types : [published, created, edited]
5+ push :
6+ branches : [ "main" ]
7+ tags : [ "*" ]
8+ pull_request :
9+ branches : [ "main" ]
10+ workflow_dispatch :
11+ inputs :
12+ run_security :
13+ description : ' Run security check'
14+ type : boolean
15+ default : false
16+ run_deploy :
17+ description : ' Run deploy step'
18+ type : boolean
19+ default : false
20+ required : true
21+ jobs :
22+ build_and_test :
23+ name : Build and Test
24+ runs-on : ubuntu-latest
25+ strategy :
26+ matrix :
27+ python-version : ["3.10", "3.11", "3.12", "3.13"]
28+ steps :
29+ - uses : actions/checkout@v4
30+ - name : Set up Python ${{ matrix.python-version }}
31+ uses : actions/setup-python@v3
32+ with :
33+ python-version : ${{ matrix.python-version }}
34+ - name : Upgrade pip and install dependencies
35+ run : |
36+ python -m pip install --upgrade pip
37+ python -m pip install flake8 pytest pytest-asyncio build
38+ - name : Build package
39+ run : |
40+ python -m build
41+ python -m pip install -e .[all]
42+ - name : Lint with flake8
43+ run : |
44+ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
45+ flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
46+ # - name: Test with pytest
47+ # run: pytest tests/
48+ security :
49+ name : Security Check
50+ runs-on : ubuntu-latest
51+ if : startsWith(github.ref, 'refs/tags/') || inputs.run_security
52+ steps :
53+ - uses : actions/checkout@main
54+ - name : Run Safety CLI to check for vulnerabilities
55+ uses : pyupio/safety-action@v1
56+ with :
57+ api-key : ${{ secrets.SAFETY_API_KEY }}
58+ deploy :
59+ name : Deploy Package to PyPI
60+ runs-on : ubuntu-latest
61+ needs : [build_and_test, security]
62+ if : (github.event_name == 'release' && github.event.action == 'published' && needs.build_and_test.result == 'success' && needs.security.result == 'success') || inputs.run_deploy
63+ steps :
64+ - uses : actions/checkout@v4
65+ - name : Set up Python
66+ uses : actions/setup-python@v3
67+ with :
68+ python-version : ' 3.x'
69+ # - name: Verify PYPI_API_TOKEN is set
70+ # run: |
71+ # if [ -z "${{ secrets.PYPI_API_TOKEN }}" ]; then
72+ # echo "PYPI_API_TOKEN is not set";
73+ # exit 1;
74+ # fi
75+ - name : Upgrade pip and install build
76+ run : |
77+ python -m pip install --upgrade pip
78+ pip install build
79+ - name : Build package for deployment
80+ run : python -m build
81+ - name : Publish distribution 📦 to PyPI
82+ uses : pypa/gh-action-pypi-publish@release/v1
83+ # password: ${{ secrets.PYPI_API_TOKEN }}
0 commit comments