13
13
PYPI_TEST_REPOSITORY_URL : https://test.pypi.org/legacy/
14
14
15
15
jobs :
16
- build_and_publish :
17
- name : Build and publish to PyPI
16
+ build :
17
+ name : Build package
18
18
runs-on : ubuntu-latest
19
- environment : pypi
20
- permissions :
21
- id-token : write
22
19
outputs :
23
- is_new_version : ${{ steps.check_version.outputs.is_new_version }}
24
- repository_url : ${{ steps.configure.outputs.repository_url }}
20
+ version : ${{ steps.build.outputs.version }}
25
21
steps :
26
22
- uses : actions/checkout@v3
27
23
30
26
with :
31
27
python-version : ' 3.12'
32
28
33
- - name : Configure settings
34
- id : configure
35
- run : |
36
- if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
37
- echo "repository_url=${{ env.PYPI_REPOSITORY_URL }}" >> $GITHUB_OUTPUT
38
- else
39
- echo "repository_url=${{ env.PYPI_TEST_REPOSITORY_URL }}" >> $GITHUB_OUTPUT
40
- fi
41
- echo "repository_url=${repository_url}"
42
-
43
29
- name : Install dependencies
44
- id : install
45
30
run : |
46
31
python -m pip install --upgrade pip
47
32
pip install poetry
@@ -51,22 +36,58 @@ jobs:
51
36
id : build
52
37
run : |
53
38
poetry build
39
+ echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT
40
+
41
+ - name : Upload artifact
42
+ uses : actions/upload-artifact@v3
43
+ with :
44
+ name : dist
45
+ path : dist/
54
46
47
+ check_version :
48
+ name : Check version
49
+ needs : build
50
+ runs-on : ubuntu-latest
51
+ outputs :
52
+ is_new_version : ${{ steps.check.outputs.is_new_version }}
53
+ steps :
55
54
- name : Check package version
56
- id : check_version
55
+ id : check
57
56
run : |
58
- version=$(poetry version -s)
57
+ version="${{ needs.build.outputs. version }}"
59
58
status_code=$(curl -o /dev/null -s -w "%{http_code}" https://pypi.org/project/${{ env.PACKAGE_NAME }}/${version}/)
60
59
if [ "$status_code" = "403" ]; then
61
- echo " is_new_version=true" >> $GITHUB_OUTPUT
60
+ is_new_version=true
62
61
else
63
- echo " is_new_version=false" >> $GITHUB_OUTPUT
62
+ is_new_version=false
64
63
fi
65
- echo "is_new_version=${is_new_version}"
64
+ echo "is_new_version=${is_new_version}" >> $GITHUB_OUTPUT
65
+
66
+ publish :
67
+ name : Publish to PyPI
68
+ needs : [build, check_version]
69
+ runs-on : ubuntu-latest
70
+ environment : pypi
71
+ permissions :
72
+ id-token : write
73
+ if : needs.check_version.outputs.is_new_version == 'true'
74
+ steps :
75
+ - name : Configure repository URL
76
+ id : configure
77
+ run : |
78
+ if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
79
+ echo "repository_url=${{ env.PYPI_REPOSITORY_URL }}" >> $GITHUB_OUTPUT
80
+ else
81
+ echo "repository_url=${{ env.PYPI_TEST_REPOSITORY_URL }}" >> $GITHUB_OUTPUT
82
+ fi
83
+
84
+ - name : Download artifact
85
+ uses : actions/download-artifact@v3
86
+ with :
87
+ name : dist
88
+ path : dist/
66
89
67
90
- name : Publish package
68
- id : publish
69
- if : ${{ always() && steps.check_version.outputs.is_new_version == 'true' }}
70
91
uses : pypa/gh-action-pypi-publish@release/v1
71
92
with :
72
93
repository-url : ${{ steps.configure.outputs.repository_url }}
0 commit comments