Skip to content

Commit 5237000

Browse files
Update the publishing process (#94)
1 parent 53aaf14 commit 5237000

File tree

7 files changed

+81
-51
lines changed

7 files changed

+81
-51
lines changed

.github/workflows/_build.yaml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ jobs:
3434

3535
- name: Install dependencies
3636
run: |
37-
python -m pip install --upgrade pip
38-
python -m pip install build
37+
python -m pip install --user --upgrade pip
38+
python -m pip install --user build
3939
4040
- name: Install hdf5 and netcdf (macOS)
4141
if: runner.os == 'macOS'
@@ -63,19 +63,37 @@ jobs:
6363
exit 1
6464
}
6565
66-
- name: Build the package
67-
run: python -m build --outdir .
66+
- name: Build Linux
67+
if: runner.os == 'linux'
68+
run: python -m build
69+
70+
- name: Store the distribution packages
71+
uses: actions/upload-artifact@v4
72+
# upload artifacts with the oldest supported version
73+
if: runner.os == 'linux' && inputs.python-version == '3.8'
74+
with:
75+
name: python-package-distributions
76+
path: dist/
77+
78+
- name: Build macOS
79+
if: runner.os == 'macOS'
80+
run: python -m build
81+
82+
- name: Build Windows
83+
if: runner.os == 'Windows'
84+
# put it here to avoid more filtering
85+
run: python -m build -o .
6886

6987
- name: Install the package on Linux or MacOS
7088
if: runner.os != 'Windows'
71-
run: python -m pip install python_cmethods*.whl
89+
run: python -m pip install --user dist/python_cmethods*.whl
7290

7391
- name: Install the package on Windows
7492
if: runner.os == 'Windows'
7593
run: |
7694
try {
7795
$WHEEL = Get-ChildItem -Path . -Filter "python_cmethods*.whl" -ErrorAction Stop
78-
python -m pip install $WHEEL
96+
python -m pip install --user $WHEEL
7997
} catch {
8098
Write-Error "Error: .whl file not found in the current directory."
8199
exit 1

.github/workflows/_pypi_publish.yaml

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,37 @@
33
# GitHub: https://github.com/btschwertfeger
44
#
55
# Template workflow to build the project and publish
6-
# the package to PyPI. It can be used to publish on the
7-
# test index and the "live" PyPI index.
6+
# the package to PyPI.
87
#
98

109
name: PyPI Publish
1110

1211
on:
1312
workflow_call:
14-
inputs:
15-
REPOSITORY_URL:
16-
type: string
17-
required: true
1813
secrets:
1914
API_TOKEN:
2015
required: true
2116

2217
permissions: read-all
2318

2419
jobs:
25-
PyPI-Publish:
26-
name: Upload to ${{ inputs.REPOSITORY_URL }}
20+
publish-to-pypi:
21+
name: Publish Python distribution to PyPI
2722
runs-on: ubuntu-latest
2823
permissions:
2924
id-token: write # IMPORTANT: this permission is mandatory for OIDC publishing
30-
25+
environment:
26+
name: pypi
27+
url: https://pypi.org/p/python-cmethods
3128
steps:
32-
- name: Checkout repository
33-
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
34-
with:
35-
fetch-depth: 0 # IMPORTANT: otherwise the current tag does not get fetched and the build version gets worse
36-
37-
- name: Set up Python 3.11
38-
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
29+
- name: Download all the distributions
30+
uses: actions/download-artifact@v4
3931
with:
40-
python-version: 3.11
41-
42-
- name: Install dependencies
43-
run: |
44-
python -m pip install --upgrade pip
45-
46-
- name: Check git status
47-
run: |
48-
if [[ -z "$(git status --porcelain)" ]]; then
49-
echo "No changes found."
50-
else
51-
echo "Changes detected. Please commit or discard changes before publishing."
52-
git status --porcelain
53-
exit 1
54-
fi
55-
56-
- name: Build the package
57-
run: python -m pip wheel -w dist --no-deps .
32+
name: python-package-distributions
33+
path: dist/
5834

5935
- name: Publish package distributions to PyPI (optional - testpypi)
6036
uses: pypa/gh-action-pypi-publish@release/v1
6137
with:
6238
password: ${{ secrets.API_TOKEN }}
63-
repository-url: ${{ inputs.REPOSITORY_URL }}
39+
repository-url: https://upload.pypi.org/legacy/
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (C) 2023 Benjamin Thomas Schwertfeger
3+
# GitHub: https://github.com/btschwertfeger
4+
#
5+
# Template workflow to build the project and publish
6+
# the package to test PyPI.
7+
#
8+
9+
name: PyPI Publish
10+
11+
on:
12+
workflow_call:
13+
secrets:
14+
API_TOKEN:
15+
required: true
16+
17+
permissions: read-all
18+
19+
jobs:
20+
publish-to-test-pypi:
21+
name: Publish Python distribution to PyPI
22+
runs-on: ubuntu-latest
23+
permissions:
24+
id-token: write # IMPORTANT: this permission is mandatory for OIDC publishing
25+
environment:
26+
name: testpypi
27+
url: https://test.pypi.org/p/python-cmethods
28+
steps:
29+
- name: Download all the distributions
30+
uses: actions/download-artifact@v4
31+
with:
32+
name: python-package-distributions
33+
path: dist/
34+
35+
- name: Publish package distributions to PyPI (optional - testpypi)
36+
uses: pypa/gh-action-pypi-publish@release/v1
37+
with:
38+
password: ${{ secrets.API_TOKEN }}
39+
repository-url: https://test.pypi.org/legacy/

.github/workflows/_test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ jobs:
3434

3535
- name: Install dependencies
3636
run: |
37-
python -m pip install --upgrade pip
37+
python -m pip install --user --upgrade pip
3838
3939
- name: Install package
40-
run: python -m pip install ".[dev,test]"
40+
run: python -m pip install --user ".[dev,test]"
4141

4242
- name: Run unit tests
4343
run: pytest -vv tests

.github/workflows/cicd.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ jobs:
9898
- Test
9999
- CodeQL
100100
name: Upload current version to Test PyPI
101-
uses: ./.github/workflows/_pypi_publish.yaml
102-
with:
103-
REPOSITORY_URL: https://test.pypi.org/legacy/
101+
uses: ./.github/workflows/_pypi_test_publish.yaml
104102
secrets:
105103
API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }}
106104

@@ -118,7 +116,5 @@ jobs:
118116
- CodeQL
119117
name: Upload the current release to PyPI
120118
uses: ./.github/workflows/_pypi_publish.yaml
121-
with:
122-
REPOSITORY_URL: https://upload.pypi.org/legacy/
123119
secrets:
124120
API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66

77
VENV := venv
8-
PYTHON := $(VENV)/bin/python3
8+
PYTHON := python
99
TESTS := tests
1010
PYTEST_OPTS := -vv
1111
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
@@ -18,7 +18,7 @@ help:
1818
##
1919
.PHONY: build
2020
build:
21-
$(PYTHON) -m pip wheel -w dist --no-deps .
21+
$(PYTHON) -m build .
2222

2323
## dev Installs the package in edit mode
2424
##

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ authors = [
1111
maintainers = [
1212
{ name = "Benjamin Thomas Schwertfeger", email = "contact@b-schwertfeger.de" },
1313
]
14-
description = "Collection of bias correction procedures for single and multidimensional climate data"
14+
description = "A collection of bias correction techniques written in Python - for climate sciences."
1515
readme = "README.md"
1616
license = { file = "LICENSE" }
1717
requires-python = ">=3.8"
@@ -83,6 +83,7 @@ jupyter = ["venv-kernel"]
8383
dev = [
8484
# building
8585
"setuptools_scm",
86+
"build",
8687
# documentation
8788
"sphinx",
8889
"sphinx-rtd-theme",

0 commit comments

Comments
 (0)