Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 39 additions & 28 deletions .github/workflows/pypi-build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,61 @@
---
name: PyPi Build and Deploy 🐍📦
# Workflow from https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

on:
release:
types: [published]
# use this for testing
push:
# Use this for testing the package build.
branches:
- main
- v[0-9]+.[0-9]+.x # matches release branches like v2.12.x

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for? That'll run on our mega latest v2.9.x from three years ago 😁
On a serious note, where's that manual approval enabled/configured, in the PyPI project settings?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for?
To test that the package build works on the release branch.

That'll run on our mega latest v2.9.x from three years ago

Yes, but only if you would push a commit to it.

On a serious note, where's that manual approval enabled/configured, in the PyPI project settings?

https://github.com/ESMValGroup/ESMValTool/settings/environments/8132850576/edit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah thanks, I also reckon that's a good idea 🍺


jobs:
build-n-publish:
name: Build and publish ESMValTool on PyPi
build:
name: Build distribution 📦
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/ESMValTool/
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python 3.13
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.13"
- name: Install pep517
python-version: "3.x"
- name: Install pypa/build
run: >-
python -m
python3 -m
pip install
pep517
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
pep517.build
--source
--binary
--out-dir dist/
.
# - name: Publish distribution to Test PyPI
# uses: pypa/gh-action-pypi-publish@v1.13.0
# with:
# repository-url: https://test.pypi.org/legacy/
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v5
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/ESMValTool
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v6
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@v1.13.0
17 changes: 11 additions & 6 deletions doc/sphinx/source/community/release_strategy/release_strategy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ Make a pull request and get it merged into ``main``.
4. Create a release branch
~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a branch off the ``main`` branch and push it to GitHub.
The name of the release branch should be of the form ``vX.Y.x``,
where ``X.Y`` is the major and minor version number of the release, e.g.
``v2.1.x`` for the releases ``v2.1.0``, ``v2.1.1``, etc.
Ask someone with administrative permissions to set up branch protection rules
for it so only you and the person helping you with the release can push to it.
Announce the name of the branch in an issue and ask the members of the
Expand Down Expand Up @@ -562,21 +565,23 @@ on that branch.

The package is automatically uploaded to the
`PyPI <https://pypi.org/project/ESMValTool/>`__
by a GitHub action.
If has failed for some reason, build and upload the package manually by
following the instructions below.
by a GitHub action. Note that for security reasons, the upload needs to be
approved by someone from the
`ESMValGroup/technical-lead-development-team <https://github.com/orgs/ESMValGroup/teams/technical-lead-development-team>`__
who is not the author of the release.

Follow these steps to create a new Python package:
If the automatic build and upload has failed for some reason, do it manually by
following these instructions:

- Check out the tag corresponding to the release,
e.g. ``git checkout tags/v2.1.0``
- Make sure your current working directory is clean by checking the output
of ``git status`` and by running ``git clean -xdf`` to remove any files
ignored by git.
- Install the required packages:
``python3 -m pip install --upgrade pep517 twine``
``python3 -m pip install --upgrade build twine``
- Build the package:
``python3 -m pep517.build --source --binary --out-dir dist/ .``
``python3 -m build``
This command should generate two files in the ``dist`` directory, e.g.
``ESMValTool-2.1.0-py3-none-any.whl`` and ``ESMValTool-2.1.0.tar.gz``.
- Upload the package:
Expand Down
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[build-system]
requires = [
"setuptools >= 40.6.0",
"setuptools_scm>=6.2",
"setuptools>=80",
"setuptools_scm>=8",
]
build-backend = "setuptools.build_meta"

Expand All @@ -14,7 +14,6 @@ classifiers = [
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
Expand Down Expand Up @@ -87,7 +86,8 @@ dependencies = [
"zarr",
]
description = "A community tool for pre-processing data from Earth system models in CMIP and running analysis scripts"
license = {text = "Apache License, Version 2.0"}
license = "Apache-2.0"
license-files = ["LICENSE", "NOTICE"]
name = "ESMValTool"
requires-python = ">=3.12"

Expand Down Expand Up @@ -136,7 +136,6 @@ Issues = "https://github.com/ESMValGroup/ESMValTool/issues"

[tool.setuptools]
include-package-data = true
license-files = ["LICENSE"]
packages = ["esmvaltool"]
zip-safe = false

Expand Down