File tree 1 file changed +76
-0
lines changed
1 file changed +76
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Build and Publish Python Package
2
+
3
+ on :
4
+ workflow_dispatch :
5
+ inputs :
6
+ version :
7
+ description : ' Version to release'
8
+ required : true
9
+ type : string
10
+ push :
11
+ branches :
12
+ - ' release/[0-9]+.[0-9]+.[0-9]+'
13
+ - ' hotfix/[0-9]+.[0-9]+.[0-9]+'
14
+
15
+ jobs :
16
+ build :
17
+ name : Build Python distribution
18
+ runs-on : ubuntu-latest
19
+ steps :
20
+ - uses : actions/checkout@v3
21
+
22
+ - name : Set up Python
23
+ uses : actions/setup-python@v4
24
+ with :
25
+ python-version : ' 3.10'
26
+
27
+ - name : Install dependencies
28
+ run : |
29
+ python -m pip install --upgrade pip
30
+ pip install build wheel twine
31
+
32
+ - name : Build package
33
+ run : python setup.py sdist bdist_wheel
34
+
35
+ - name : Check if package version already exists
36
+ run : |
37
+ PACKAGE_NAME=$(python setup.py --name)
38
+ PACKAGE_VERSION=${{ github.event.inputs.version }}
39
+ if twine check dist/*; then
40
+ if pip install $PACKAGE_NAME==$PACKAGE_VERSION; then
41
+ echo "Error: Version $PACKAGE_VERSION of $PACKAGE_NAME already exists on PyPI"
42
+ exit 1
43
+ else
44
+ echo "Version $PACKAGE_VERSION of $PACKAGE_NAME does not exist on PyPI. Proceeding with upload."
45
+ fi
46
+ else
47
+ echo "Error: Twine check failed."
48
+ exit 1
49
+ fi
50
+
51
+ - name : Upload artifact
52
+ uses : actions/upload-artifact@v3
53
+ with :
54
+ name : dist
55
+ path : dist/
56
+
57
+ approve-and-publish :
58
+ needs : build
59
+ runs-on : ubuntu-latest
60
+ environment : release
61
+ permissions :
62
+ contents : read
63
+ id-token : write
64
+
65
+ steps :
66
+ - name : Download artifact
67
+ uses : actions/download-artifact@v3
68
+ with :
69
+ name : dist
70
+ path : dist/
71
+
72
+ - name : Publish package distributions to PyPI
73
+ uses : pypa/gh-action-pypi-publish@release/v1
74
+ with :
75
+ verbose : true
76
+ print-hash : true
You can’t perform that action at this time.
0 commit comments