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