Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify build and use trusted publisher #80

Merged
merged 8 commits into from
Sep 5, 2024
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
8 changes: 0 additions & 8 deletions .github/actions/build-conda-packages/action.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
name: Build Conda packages
description: Build the Conda packages
outputs:
platform:
description: The platform targeted by the Conda packages.
value: ${{ steps.get-platform.outputs.platform }}
runs:
using: composite
steps:
Expand All @@ -14,7 +10,3 @@ runs:
- run: conda build --no-anaconda-upload --output-folder dist .
# See https://github.com/conda-incubator/setup-miniconda/blame/059455a698430d8b68fa317268fa2e3da3492a98/README.md#L609-L610.
shell: bash -l {0}

- id: get-platform
run: uv run python -c 'from pathlib import Path; print(f"""platform={next(Path("dist").glob("*/jdk4py-*.tar.bz2")).parts[1]}""")' >> "$GITHUB_OUTPUT"
shell: bash
2 changes: 1 addition & 1 deletion .github/actions/build-java-runtime/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ inputs:
runs:
using: composite
steps:
- run: curl -LsSf https://astral.sh/uv/0.4.0/install.sh | sh
- run: curl -LsSf https://astral.sh/uv/0.4.5/install.sh | sh
shell: bash

- run: uv python install ${{ inputs.python-version }}
Expand Down
9 changes: 2 additions & 7 deletions .github/actions/build-python-wheel/action.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
name: Build Python wheel
description: Build the Python wheel
outputs:
filename:
description: The name of the built Python wheel.
value: ${{ steps.get-filename.outputs.filename }}
runs:
using: "composite"
steps:
- run: uv run python -m build --installer uv --wheel
- run: uv build --wheel
shell: bash

- id: get-filename
run: uv run python -c 'from pathlib import Path; print(f"""filename={next(Path("dist").glob("jdk4py-*.whl")).parts[1]}""")' >> "$GITHUB_OUTPUT"
- run: uv run twine check dist/*
shell: bash
67 changes: 48 additions & 19 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Deploy Conda and PyPI packages
name: Deploy Conda packages and Python wheels
on:
push:
branches:
- main

jobs:
deploy:
build:
name: Build on ${{ matrix.runner }}
runs-on: ${{ matrix.runner }}
environment: deployment
strategy:
matrix:
runner:
Expand All @@ -16,37 +16,66 @@ jobs:
- ubuntu-24.04
- ubuntu-24.04-arm64 # GitHub-hosted larger runner in the ActiveViam organization.
- windows-2022
name: Deploy on ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/build-java-runtime
with:
python-version: "3.12"
python-version: "3.10"

- uses: ./.github/actions/build-python-wheel

- id: build-python-wheel
uses: ./.github/actions/build-python-wheel
- uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: jdk4py-${{ matrix.runner }}-python-wheel
path: dist/jdk4py-*.whl

- id: build-conda-packages
uses: ./.github/actions/build-conda-packages
- uses: ./.github/actions/build-conda-packages

- name: Upload Conda packages
- uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: jdk4py-${{ matrix.runner }}-conda-packages
path: dist/*/jdk4py-*.tar.bz2

publish:
environment: deployment
name: Publish Conda packages and Python wheels
needs: build
runs-on: ubuntu-24.04
permissions:
# Required for trusted publishing.
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
merge-multiple: true
path: dist/

- name: List Conda packages and Python wheels
run: ls -R dist/

- name: Publish Conda packages
env:
JDK4PY_CONDA_CHANNEL_TOKEN: ${{ secrets.CONDA_CHANNEL_TOKEN }}
JDK4PY_CONDA_CHANNEL_URL: ${{ vars.CONDA_CHANNEL_URL }}
JDK4PY_CONDA_CHANNEL_USERNAME: ${{ vars.CONDA_CHANNEL_USERNAME }}
JDK4PY_CONDA_PLATFORM: ${{ steps.build-conda-packages.outputs.platform }}
run: |
ls dist/$JDK4PY_CONDA_PLATFORM/jdk4py-*.tar.bz2 | \
cd dist/
ls */jdk4py-*.tar.bz2 | \
while read filepath; do
echo Uploading ${filepath}
curl --fail --user "$JDK4PY_CONDA_CHANNEL_USERNAME":"$JDK4PY_CONDA_CHANNEL_TOKEN" --upload-file ${filepath} "$JDK4PY_CONDA_CHANNEL_URL/$JDK4PY_CONDA_PLATFORM/"
curl --fail --user "$JDK4PY_CONDA_CHANNEL_USERNAME":"$JDK4PY_CONDA_CHANNEL_TOKEN" --upload-file ${filepath} "$JDK4PY_CONDA_CHANNEL_URL/$(dirname $filepath)/"
done
shell: bash

- name: Upload Python wheel
env:
JDK4PY_PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
JDK4PY_WHEEL_FILENAME: ${{ steps.build-python-wheel.outputs.filename }}
run: uv run twine upload dist/"$JDK4PY_WHEEL_FILENAME" --username __token__ --password "$JDK4PY_PYPI_TOKEN"
shell: bash
# Conda packages are nested inside platform specific directories.
# Deleting all sub directories only leaves Python wheels in `dist/`.
# This is required to not confuse `twine upload` when `dist/*` is passed.
# See https://github.com/pypa/gh-action-pypi-publish/blob/36978192ca7715ea2e0d12e82d5518a651a9f739/twine-upload.sh#L208C43-L208C61.
- name: Keep only Python wheels
run: rm -R -- dist/*/

- name: Publish Python wheels
uses: pypa/gh-action-pypi-publish@release/v1
32 changes: 15 additions & 17 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:

jobs:
test:
name: Test on ${{ matrix.runner }} with Python ${{ matrix.python }}
runs-on: ${{ matrix.runner }}
strategy:
matrix:
Expand All @@ -15,45 +16,44 @@ jobs:
- ubuntu-24.04-arm64 # GitHub-hosted larger runner in the ActiveViam organization.
- windows-2022
python:
- "3.12"
- "3.10"
include:
- runner: ubuntu-24.04
python: "3.11"
- runner: ubuntu-24.04
python: "3.10"
python: "3.12"
fail-fast: false
name: Test on ${{ matrix.runner }} with Python ${{ matrix.python }}
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/build-java-runtime

- id: build-python-wheel
uses: ./.github/actions/build-python-wheel
- uses: ./.github/actions/build-python-wheel

# No need to test each platform and Python version.
- if: ${{ matrix.runner == 'ubuntu-24.04' && matrix.python == '3.12' }}
- if: ${{ matrix.runner == 'ubuntu-24.04' && matrix.python == '3.10' }}
run: uv run ruff format --check .

# No need to test each platform and Python version.
- if: ${{ matrix.runner == 'ubuntu-24.04' && matrix.python == '3.12' }}
- if: ${{ matrix.runner == 'ubuntu-24.04' && matrix.python == '3.10' }}
run: uv run ruff check .

# No need to test each platform and Python version.
- if: ${{ matrix.runner == 'ubuntu-24.04' && matrix.python == '3.12' }}
- if: ${{ matrix.runner == 'ubuntu-24.04' && matrix.python == '3.10' }}
run: uv run mypy

- run: uv run pytest

# The Python wheels are not tied to a specific Python version.
- if: ${{ matrix.python == '3.12' }}
- if: ${{ matrix.python == '3.10' }}
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: ${{ steps.build-python-wheel.outputs.filename }}
path: dist/${{ steps.build-python-wheel.outputs.filename }}
name: jdk4py-${{ matrix.runner }}-python-wheel
path: dist/jdk4py-*.whl

conda-package:
name: Test Conda packaging on ${{ matrix.runner }}
runs-on: ${{ matrix.runner }}
strategy:
matrix:
Expand All @@ -63,20 +63,18 @@ jobs:
- ubuntu-24.04
- ubuntu-24.04-arm64 # GitHub-hosted larger runner in the ActiveViam organization.
- windows-2022
name: Test Conda packaging on ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/build-java-runtime
with:
# No need to test each Python version.
python-version: "3.12"
python-version: "3.10"

- id: build-conda-packages
uses: ./.github/actions/build-conda-packages
- uses: ./.github/actions/build-conda-packages

- uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: jdk4py-${{ steps.build-conda-packages.outputs.platform }}-conda-packages
path: dist/${{ steps.build-conda-packages.outputs.platform }}/jdk4py-*.tar.bz2
name: jdk4py-${{ matrix.runner }}-conda-packages
path: dist/*/jdk4py-*.tar.bz2
13 changes: 7 additions & 6 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% set pyproject = load_file_data("pyproject.toml") %}
{% set dev_dependencies = pyproject["tool"]["uv"]["dev-dependencies"] %}
{% set version = load_file_data("src/jdk4py/version.json") %}

package:
Expand All @@ -15,21 +16,21 @@ build:

requirements:
build:
# Must be available on anaconda (not conda-forge).
# Keep in sync with version in `pyproject.toml`.
- hatchling ==1.21.1
- python {{ python }}
- pip ==24.2
{% for dependency in dev_dependencies if dependency.startswith("hatchling ") %}
- {{ dependency }}
{% endfor %}
run:
- python {{ python }}

test:
source_files:
- tests/
requires:
# Must be available on anaconda (not conda-forge).
# Keep in sync with version in `pyproject.toml`.
- pytest ==7.4.4
{% for dependency in dev_dependencies if dependency.startswith("pytest ") %}
- {{ dependency }}
{% endfor %}
commands:
- pytest

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[build-system]
build-backend = "hatchling.build"
requires = [
# Keep in sync with version in `conda.recipe/meta.yaml` and the section `tool.uv.dev-dependencies` in this file.
# Keep pinned to ensure same version is used by `conda build` (version must be available on anaconda).
# Keep in sync with version in `tool.uv.dev-dependencies`.
"hatchling ==1.21.1",
]

Expand Down Expand Up @@ -61,11 +62,10 @@ select = ["ALL"]

[tool.uv]
dev-dependencies = [
"build",
# Keep in sync with version in `build-system.requires`.
"hatchling ==1.21.1",
"mypy",
# Keep in sync with version in `conda.recipe/meta.yaml`.
# Keep pinned to ensure same version is used by `conda build` (version must be available on anaconda).
"pytest ==7.4.4",
"ruff",
"twine",
Expand Down
2 changes: 1 addition & 1 deletion src/jdk4py/version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"21.0.4.0"
"21.0.4.1"
Loading
Loading