Skip to content

Commit 38bb3a8

Browse files
committed
Add pre-release and release steps to master workflow.
1 parent 6e35021 commit 38bb3a8

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

.github/actions/unittests/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run unit tests
1+
name: Run unittests
22

33
inputs:
44
python-version:

.github/workflows/master.yml

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
unittests:
10-
name: Run tests
10+
name: Run unittests
1111
runs-on: ubuntu-latest
1212

1313
strategy:
@@ -23,3 +23,66 @@ jobs:
2323
uses: ./.github/actions/unittests
2424
with:
2525
python-version: ${{ matrix.python-version }}
26+
27+
prerelease:
28+
name: Pre-release (test-pypi)
29+
needs: unittests
30+
if: success()
31+
runs-on: ubuntu-latest
32+
33+
steps:
34+
- name: Build package
35+
run: python setup.py sdist bdist_wheel
36+
37+
- name: Upload artifact
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: py-dependency-injection
41+
path: dist/
42+
43+
- name: Publish to Test PyPI
44+
uses: pypa/gh-action-pypi-publish@releases/v1.8
45+
with:
46+
user: __token__
47+
password: ${{ secrets.TEST_PYPI_TOKEN }}
48+
repository_url: https://test.pypi.org/legacy/
49+
skip_existing: true
50+
51+
release:
52+
name: Release (pypi)
53+
needs: prerelease
54+
if: success()
55+
if: github.event_name == 'workflow_run' && github.event.workflow_run.event == 'workflow_dispatch'
56+
runs-on: ubuntu-latest
57+
58+
steps:
59+
- name: Download artifact
60+
uses: actions/download-artifact@v4
61+
with:
62+
name: py-dependency-injection
63+
path: dist/
64+
65+
- name: Extract version from setup.py
66+
id: extract-version
67+
run: |
68+
version=$(grep -Eo "version=['\"]([^'\"]+)['\"]" setup.py | awk -F"'" '{print $2}')
69+
echo "Using version: $version"
70+
echo "::set-output name=RELEASE_VERSION::$version"
71+
72+
- name: Publish to PyPI
73+
uses: pypa/gh-action-pypi-publish@releases/v1.8
74+
with:
75+
user: __token__
76+
password: ${{ secrets.PYPI_TOKEN }}
77+
repository_url: https://upload.pypi.org/legacy/
78+
skip_existing: true
79+
80+
- name: Set up Git
81+
run: |
82+
git config --global user.name "${{ github.actor }}"
83+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
84+
85+
- name: Create and push tag
86+
run: |
87+
git tag -a v${{ steps.extract-version.outputs.RELEASE_VERSION }} -m "Release version v${{ steps.extract-version.outputs.RELEASE_VERSION }}"
88+
git push origin v${{ steps.extract-version.outputs.RELEASE_VERSION }}

0 commit comments

Comments
 (0)