-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (84 loc) · 2.68 KB
/
Copy pathpython-package.yml
File metadata and controls
84 lines (84 loc) · 2.68 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
name: Release Build and Deploy
on:
release:
types: [published, created, edited]
push:
branches: [ "main" ]
tags: [ "*" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
inputs:
run_security:
description: 'Run security check'
type: boolean
default: false
run_deploy:
description: 'Run deploy step'
type: boolean
default: false
required: true
jobs:
build_and_test:
name: Build and Test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip and install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest pytest-asyncio build
- name: Build package
run: |
python -m build
python -m pip install -e .[all]
- name: Lint with flake8
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: pytest tests/
security:
name: Security Check
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') || inputs.run_security
steps:
- uses: actions/checkout@main
- name: Run Safety CLI to check for vulnerabilities
uses: pyupio/safety-action@v1
with:
api-key: ${{ secrets.SAFETY_API_KEY }}
deploy:
name: Deploy Package to PyPI
runs-on: ubuntu-latest
needs: [build_and_test, security]
if: (github.event_name == 'release' && github.event.action == 'published' && needs.build_and_test.result == 'success' && needs.security.result == 'success') || inputs.run_deploy
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Verify PYPI_API_TOKEN is set
run: |
if [ -z "${{ secrets.PYPI_API_TOKEN }}" ]; then
echo "PYPI_API_TOKEN is not set";
exit 1;
fi
- name: Upgrade pip and install build
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package for deployment
run: python -m build
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
password: ${{ secrets.PYPI_API_TOKEN }}