1+ # Create release and publish to Pypi when pushing tags
2+
3+ name : publish
4+
5+ # Trigger the workflow on push tags, matching vM.n.p, i.e. v3.2.10
6+ on :
7+ push :
8+ tags :
9+ - ' v[0-9]+.[0-9]+.[0-9]+'
10+
11+ # Jobs to do:
12+ # - build package
13+ # - create release with asset
14+ # - publish to Pypi
15+ jobs :
16+
17+ # -----------------------------------------------------------
18+ # create python env and setup package
19+ # -----------------------------------------------------------
20+ build :
21+
22+ # The type of runner that the job will run on
23+ runs-on : ubuntu-latest
24+
25+ # Steps represent a sequence of tasks that will be executed as part of the job
26+ steps :
27+ - name : Check out code
28+ uses : actions/checkout@v2
29+
30+ - name : Set up Python 3.x
31+ uses : actions/setup-python@v1
32+ with :
33+ python-version : ' 3.x'
34+
35+ - name : Install dependencies
36+ run : |
37+ python -m pip install --upgrade pip
38+ pip install setuptools wheel
39+
40+ # build package for tags, e.g. 3.2.1 extracted from 'refs/tags/v3.2.1'
41+ - name : Build package
42+ run : |
43+ echo ${GITHUB_REF#refs/tags/v} > version.txt
44+ python setup.py sdist --formats=gztar,zip
45+ python setup.py bdist_wheel
46+
47+
48+ # upload the artifacts for further jobs
49+ # - app-tag.tar.gz
50+ # - app-tag.zip
51+ # - app-tag-info.whl
52+ - name : Archive package
53+ uses : actions/upload-artifact@v2
54+ with :
55+ name : dist
56+ path : ./dist
57+
58+ # -----------------------------------------------------------
59+ # create release and upload asset
60+ # -----------------------------------------------------------
61+ release :
62+ runs-on : ubuntu-latest
63+
64+ # Run this job after build completes successfully
65+ needs : build
66+
67+ steps :
68+ - name : Checkout code
69+ uses : actions/checkout@v2
70+
71+ # download artifacts from job: build
72+ - name : Download artifacts from build
73+ uses : actions/download-artifact@v2
74+ with :
75+ name : dist
76+ path : dist
77+
78+ # create release and upload assets
79+ - name : Create release with assets
80+ uses : softprops/action-gh-release@v1
81+ with :
82+ files : |
83+ ./dist/*.tar.gz
84+ ./dist/*.zip
85+ ./dist/*.whl
86+ env :
87+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
88+
89+
90+ # -----------------------------------------------------------
91+ # publish to Pypi
92+ # -----------------------------------------------------------
93+ publish :
94+ runs-on : ubuntu-latest
95+
96+ # Run this job after both build and release completes successfully
97+ needs : [build, release]
98+
99+ steps :
100+ - name : Checkout code
101+ uses : actions/checkout@v2
102+
103+ - name : Download artifacts from release
104+ uses : actions/download-artifact@v2
105+ with :
106+ name : dist
107+ path : dist
108+
109+ # Error when two sdist files created in build job are uploaded to Pipi:
110+ # HTTPError: 400 Bad Request from https://upload.pypi.org/legacy/
111+ # Only one sdist may be uploaded per release.
112+ - name : Remove duplicated sdist
113+ run : rm ./dist/*.zip
114+
115+ - name : Publish to PyPI
116+ uses : pypa/gh-action-pypi-publish@master
117+ with :
118+ password : ${{ secrets.PYPI_PASSWORD }}
0 commit comments