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
75 changes: 75 additions & 0 deletions .github/actions/python-install-uv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Setup Python Venv (uv)

# Composite action for Python projects that installs with uv

inputs:
python-version:
description: A Python version to use
required: true
type: string
uv-version:
description: The uv version to use
required: false
type: string
default: "latest"
working-directory:
description: The working directory
required: false
type: string
default: .
delete-uv-lock:
description: Delete uv.lock file in order to test against newer versions
required: false
type: boolean
default: false
optional-dependency-groups:
description: Which optional group or groups to install. Use comma delimiter for multiple groups e.g `dev,doc`.
required: false
type: string
default: ""

runs:
using: "composite"
steps:

#----------------------------------------------
# delete uv.lock file in order to run tests against newer versions
#----------------------------------------------
- name: Delete uv.lock file
if: ${{ inputs.delete-uv-lock == 'true' }}
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
echo "::Warning title=uv.lock::uv.lock is not deleted in this workflow run even though this was requested. See https://github.com/GNS-Science/nshm-github-actions/issues/26."

#----------------------------------------------
# install uv (and Python via uv)
# caching is handled automatically by setup-uv
#----------------------------------------------
- name: Install uv and Python
uses: astral-sh/setup-uv@v6
with:
version: ${{ inputs.uv-version }}
python-version: ${{ inputs.python-version }}
enable-cache: true
cache-dependency-glob: ${{ inputs.working-directory }}/uv.lock

#----------------------------------------------
# install dependencies via uv sync
#----------------------------------------------
- name: Install dependencies
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
GROUPS: ${{ inputs.optional-dependency-groups }}
run: |
if [ -z "$GROUPS" ]; then
uv sync --no-install-project --all-extras
else
GROUP_FLAGS=""
IFS=',' read -ra GROUPS_ARR <<< "$GROUPS"
for g in "${GROUPS_ARR[@]}"; do
GROUP_FLAGS="$GROUP_FLAGS --group ${g// /}"
done
uv sync --no-install-project --all-extras $GROUP_FLAGS
fi
1 change: 1 addition & 0 deletions .github/workflows/deploy-to-aws-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
uses: ./.github/workflows/deploy-to-aws.yml
with:
python-version: 3.11
node-version: 22.22.1
working-directory: samplePythonProject
aws-login: false
smoketest-query: 'query Query {country(code: "NZ") {capital}}'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-to-aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
working-directory: ${{ inputs.working-directory }}
environment: ${{ (inputs.environment && ((github.ref == 'refs/heads/main') && 'AWS_PROD' || 'AWS_TEST')) || '' }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- uses: actions/setup-python@v5
if: ${{ inputs.python-version != 'None' }}
Expand Down
95 changes: 95 additions & 0 deletions .github/workflows/python-deploy-docs-uv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Python Deploy Docs (uv)

# Publishes documentation for a python package to GitHub pages using uv. Uses `mkdocs` for building documentation.
# Would commonly be one of two jobs along with Python Release Workflow in a repo workflow triggered by e.g. tagging a version.

on:
workflow_call:
inputs:
python-version:
description: The python version to use
required: true
type: string
default: "3.10"
uv-version:
description: The uv version to use
required: false
type: string
default: "latest"
working-directory:
description: The working directory
required: false
type: string
default: .
timeout-minutes:
description: Maximum runtime in minutes
required: false
type: number
default: 10
optional-dependency-groups:
description: Which optional group or groups to install. Use comma delimiter for multiple groups e.g `dev,doc`.
required: false
type: string
default: dev


# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
timeout-minutes: ${{ inputs.timeout-minutes }}
defaults:
run:
working-directory: ${{ inputs.working-directory }}

steps:

- uses: actions/checkout@v5

- name: install_package
uses: GNS-Science/nshm-github-actions/.github/actions/python-install-uv@main
with:
python-version: ${{ inputs.python-version }}
uv-version: ${{ inputs.uv-version }}
working-directory: ${{ inputs.working-directory }}
optional-dependency-groups: ${{ inputs.optional-dependency-groups }}

#----------------------------------------------
# build documentation
# - uv sync installs the project root by default; the composite action
# uses --no-install-project, so sync here to bring it in before building
#----------------------------------------------
- name: build documentation
run: |
uv sync
uv run mkdocs build

#----------------------------------------------
# package and upload artifact for deployment to GitHub Pages
#----------------------------------------------
- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
path: ${{ inputs.working-directory }}/site


#----------------------------------------------
# deploy page
#----------------------------------------------
- name: Deploy Docs to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion .github/workflows/python-deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:

steps:

- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: install_package
uses: GNS-Science/nshm-github-actions/.github/actions/python-install@main
Expand Down
117 changes: 117 additions & 0 deletions .github/workflows/python-release-uv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Python Release (uv)

# Creates a GitHub release and publishes the package to PyPI using uv. Would commonly be one of two jobs along
# with Python Deploy Docs in a repo workflow triggered by e.g. tagging a version.
#
# Requires the secret `PYPI_API_TOKEN`.

on:
workflow_call:
inputs:
python-version:
description: The python version to use
required: true
type: string
default: "3.10"
uv-version:
description: The uv version to use
required: false
type: string
default: "latest"
working-directory:
description: The working directory
required: false
type: string
default: .
timeout-minutes:
description: Maximum runtime in minutes
required: false
type: number
default: 10
pypi-publish:
description: Publish to PyPI or not
required: false
type: boolean
default: true


# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: ${{ inputs.timeout-minutes }}
defaults:
run:
shell: bash
working-directory: ${{ inputs.working-directory }}
steps:

- uses: actions/checkout@v5

- name: install_package
uses: GNS-Science/nshm-github-actions/.github/actions/python-install-uv@main
with:
python-version: ${{ inputs.python-version }}
uv-version: ${{ inputs.uv-version }}
working-directory: ${{ inputs.working-directory }}

#----------------------------------------------
# get version
#----------------------------------------------
- name: Get version from tag
id: tag_name
run: |
echo name=current_version::${GITHUB_REF#refs/tags/v} >> "$GITHUB_OUTPUT"
shell: bash

#----------------------------------------------
# get changelog entry
#----------------------------------------------
- name: Get Changelog Entry
id: changelog_reader
uses: GNS-Science/changelog-reader-action@master
with:
validation_depth: 10
version: ${{ steps.tag_name.outputs.current_version }}
path: ${{ inputs.working-directory }}/CHANGELOG.md

#----------------------------------------------
# build wheels and tarball
#----------------------------------------------
- name: Build wheels and source tarball
run: >-
uv build

- name: show temporary files
run: >-
ls -l

#----------------------------------------------
# create GitHub release
#----------------------------------------------
- name: create github release
id: create_release
uses: GNS-Science/action-gh-release@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: ${{ steps.changelog_reader.outputs.changes }}
files: ${{ inputs.working-directory }}/dist/*.whl
draft: false
prerelease: false

#----------------------------------------------
# publish to PyPI
#----------------------------------------------
- name: publish to PyPI
if: ${{ inputs.pypi-publish }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
2 changes: 1 addition & 1 deletion .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
working-directory: ${{ inputs.working-directory }}
steps:

- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: install_package
uses: GNS-Science/nshm-github-actions/.github/actions/python-install@main
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/python-run-tests-test-uv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# A workflow that runs on push/PR to check that python-run-tests-uv.yml works

name: python-run-tests-uv test workflow

on:
workflow_dispatch:
push:
branches: [main, pre-release]
pull_request:
branches: [main, pre-release]

jobs:
call-test-workflow:
uses: ./.github/workflows/python-run-tests-uv.yml
with:
operating-systems: "['ubuntu-latest', 'macos-latest', 'windows-latest']"
python-versions: "['3.10', '3.11', '3.12', '3.13']"
working-directory: samplePythonProjectUv
fail-on-codecov-error: false
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/python-run-tests-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: ./.github/workflows/python-run-tests.yml
with:
operating-systems: "['ubuntu-latest', 'macos-latest', 'windows-latest']"
python-versions: "['3.9', '3.10', '3.11']"
python-versions: "['3.10', '3.11', '3.12', '3.13']"
working-directory: samplePythonProject
fail-on-codecov-error: false
secrets: inherit
Loading
Loading