Skip to content

Commit d83081d

Browse files
committed
ci: updated workflow
1 parent 4fa8b78 commit d83081d

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

.github/workflows/publish_python.yaml

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@ env:
1313
PYPI_TEST_REPOSITORY_URL: https://test.pypi.org/legacy/
1414

1515
jobs:
16-
build_and_publish:
17-
name: Build and publish to PyPI
16+
build:
17+
name: Build package
1818
runs-on: ubuntu-latest
19-
environment: pypi
20-
permissions:
21-
id-token: write
2219
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 }}
2521
steps:
2622
- uses: actions/checkout@v3
2723

@@ -30,18 +26,7 @@ jobs:
3026
with:
3127
python-version: '3.12'
3228

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-
4329
- name: Install dependencies
44-
id: install
4530
run: |
4631
python -m pip install --upgrade pip
4732
pip install poetry
@@ -51,22 +36,58 @@ jobs:
5136
id: build
5237
run: |
5338
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/
5446

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:
5554
- name: Check package version
56-
id: check_version
55+
id: check
5756
run: |
58-
version=$(poetry version -s)
57+
version="${{ needs.build.outputs.version }}"
5958
status_code=$(curl -o /dev/null -s -w "%{http_code}" https://pypi.org/project/${{ env.PACKAGE_NAME }}/${version}/)
6059
if [ "$status_code" = "403" ]; then
61-
echo "is_new_version=true" >> $GITHUB_OUTPUT
60+
is_new_version=true
6261
else
63-
echo "is_new_version=false" >> $GITHUB_OUTPUT
62+
is_new_version=false
6463
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/
6689

6790
- name: Publish package
68-
id: publish
69-
if: ${{ always() && steps.check_version.outputs.is_new_version == 'true' }}
7091
uses: pypa/gh-action-pypi-publish@release/v1
7192
with:
7293
repository-url: ${{ steps.configure.outputs.repository_url }}

0 commit comments

Comments
 (0)