From e5bdaabbc6a2a4b897dcd3d322ba3c0affd5943f Mon Sep 17 00:00:00 2001 From: Michel Albert Date: Mon, 12 Aug 2024 08:31:31 +0200 Subject: [PATCH 1/2] Create pythonpackage.yml Add github workflow to publish the python package --- .github/workflows/pythonpackage.yml | 69 +++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/pythonpackage.yml diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml new file mode 100644 index 0000000..d553065 --- /dev/null +++ b/.github/workflows/pythonpackage.yml @@ -0,0 +1,69 @@ +--- +name: Python package + +# yamllint disable-line rule:truthy +on: + push: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: + - "3.10" + - "3.11" + - "3.12" + - "3.x" + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install .[dev,test] + - name: Test with pytest + run: | + pytest + + quality-control: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Run pre-commit checks + run: | + pip install pre-commit + pre-commit run --all + + + publish: + needs: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build distribution + if: > + github.event_name == 'push' && + startsWith(github.event.ref, 'refs/tags') + run: | + python -m pip install --upgrade pip wheel build + pip install .[dev,test] + pyproject-build + - name: Publish package + if: > + github.event_name == 'push' && + startsWith(github.event.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@v1.5.0 + with: + user: __token__ + password: ${{ secrets.pypi_token }} From 9ff78ec727b619e80e33281ab1df340ce1df519d Mon Sep 17 00:00:00 2001 From: Michel Albert Date: Mon, 12 Aug 2024 08:34:59 +0200 Subject: [PATCH 2/2] Only execute publish job if commit is tagged --- .github/workflows/pythonpackage.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index d553065..8dbcd26 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -49,6 +49,9 @@ jobs: publish: needs: test runs-on: ubuntu-latest + if: > + github.event_name == 'push' && + startsWith(github.event.ref, 'refs/tags') steps: - uses: actions/checkout@v4 - name: Build distribution @@ -60,9 +63,6 @@ jobs: pip install .[dev,test] pyproject-build - name: Publish package - if: > - github.event_name == 'push' && - startsWith(github.event.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@v1.5.0 with: user: __token__