Skip to content

Commit 49d3c17

Browse files
committed
Add release job to workflow
Prepare release package and publish to PyPI when a GitHub release is created. Signed-off-by: Gregers Gram Rygg <[email protected]>
1 parent 116e2d3 commit 49d3c17

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

.github/workflows/python.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ on:
55
branches:
66
- main
77
pull_request:
8+
release:
9+
types: [created]
10+
11+
env:
12+
REGISTRY_NAME: ${{ vars.REGISTRY_NAME }}
13+
REGISTRY_URI: ${{ vars.REGISTRY_URI }}
814

915
jobs:
1016
build:
@@ -37,7 +43,37 @@ jobs:
3743
path: htmlcov/
3844
- name: SonarCloud Scan
3945
uses: SonarSource/sonarcloud-github-action@master
40-
if: ${{ matrix.python-version == '3.11' }}
46+
if: ${{ matrix.python-version == '3.11' && env.SONAR_TOKEN != '' }}
4147
env:
4248
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
4349
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
50+
51+
publish:
52+
if: github.event_name == 'release'
53+
runs-on: ubuntu-latest
54+
needs: build
55+
56+
steps:
57+
- uses: actions/checkout@v3
58+
- name: Set up Python 3.11
59+
uses: actions/setup-python@v4
60+
with:
61+
python-version: 3.11
62+
- name: Install poetry
63+
run: |
64+
curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.4.2 python3 -
65+
- name: Update version in pyproject.toml
66+
run: |
67+
echo $GITHUB_REF_NAME | sed 's/^v//' | xargs poetry version
68+
- name: Install dependencies
69+
run: |
70+
poetry install
71+
- name: Registry config
72+
run: |
73+
poetry config repositories.$REGISTRY_NAME $REGISTRY_URI
74+
poetry config pypi-token.$REGISTRY_NAME $PYPI_TOKEN
75+
env:
76+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
77+
- name: Publish package to pypi
78+
run: |
79+
poetry publish --build --repository $REGISTRY_NAME

0 commit comments

Comments
 (0)