1
- name : Publish Python Package
1
+ name : Build and Test Python Package
2
2
3
3
on :
4
+ pull_request :
5
+ branches :
6
+ - ' **' # Triggers on all branches with open PRs
7
+
4
8
push :
5
9
branches :
6
- - master
10
+ - master # Triggers on pushes to the main branch
7
11
8
12
jobs :
9
- build-and-publish :
13
+ build-and-test :
10
14
runs-on : ubuntu-latest
11
15
12
16
steps :
@@ -19,18 +23,48 @@ jobs:
19
23
python-version : ' 3.x'
20
24
21
25
- name : Install dependencies
22
- run : pip install -r requirements.txt
26
+ run : |
27
+ pip install setuptools wheel
28
+ pip install -r requirements.txt
23
29
24
30
- name : Get current version
25
31
id : get_version
26
32
run : |
27
- VERSION=$(python -c "exec(open('setup.py').read()) ; print(__version__)")
33
+ VERSION=$(python -c "from version import __version__ ; print(__version__)")
28
34
echo "VERSION=$VERSION" >> $GITHUB_ENV
29
35
30
36
- name : Build the package
31
37
run : |
32
38
python setup.py sdist bdist_wheel
33
39
40
+ # - name: Run tests
41
+ # run: |
42
+ # pip install pytest
43
+ # pytest
44
+
45
+ publish-and-tag :
46
+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
47
+ runs-on : ubuntu-latest
48
+ needs : build-and-test
49
+
50
+ steps :
51
+ - name : Checkout code
52
+ uses : actions/checkout@v2
53
+
54
+ - name : Set up Python
55
+ uses : actions/setup-python@v2
56
+ with :
57
+ python-version : ' 3.x'
58
+
59
+ - name : Install dependencies
60
+ run : |
61
+ pip install setuptools wheel
62
+ pip install -r requirements.txt
63
+
64
+ - name : Build the package
65
+ run : |
66
+ python setup.py sdist bdist_wheel
67
+
34
68
- name : Publish to PyPI
35
69
env :
36
70
TWINE_USERNAME : ${{ secrets.PYPI_USERNAME }}
40
74
twine upload dist/*
41
75
42
76
- name : Create Git tag
43
- if : success()
44
77
run : |
45
78
git config user.name "GitHub Actions"
46
79
git config user.email "[email protected] "
47
80
git tag -a v${{ env.VERSION }} -m "Release version ${{ env.VERSION }}"
48
81
git push origin v${{ env.VERSION }}
49
-
0 commit comments