Skip to content

Commit 226b2cc

Browse files
Merge pull request #41 from GNS-Science/feature/40-uv
add uv workflows and sample project
2 parents ecf6343 + e162aad commit 226b2cc

23 files changed

Lines changed: 917 additions & 15 deletions
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Setup Python Venv (uv)
2+
3+
# Composite action for Python projects that installs with uv
4+
5+
inputs:
6+
python-version:
7+
description: A Python version to use
8+
required: true
9+
type: string
10+
uv-version:
11+
description: The uv version to use
12+
required: false
13+
type: string
14+
default: "latest"
15+
working-directory:
16+
description: The working directory
17+
required: false
18+
type: string
19+
default: .
20+
delete-uv-lock:
21+
description: Delete uv.lock file in order to test against newer versions
22+
required: false
23+
type: boolean
24+
default: false
25+
optional-dependency-groups:
26+
description: Which optional group or groups to install. Use comma delimiter for multiple groups e.g `dev,doc`.
27+
required: false
28+
type: string
29+
default: ""
30+
31+
runs:
32+
using: "composite"
33+
steps:
34+
35+
#----------------------------------------------
36+
# delete uv.lock file in order to run tests against newer versions
37+
#----------------------------------------------
38+
- name: Delete uv.lock file
39+
if: ${{ inputs.delete-uv-lock == 'true' }}
40+
shell: bash
41+
working-directory: ${{ inputs.working-directory }}
42+
run: |
43+
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."
44+
45+
#----------------------------------------------
46+
# install uv (and Python via uv)
47+
# caching is handled automatically by setup-uv
48+
#----------------------------------------------
49+
- name: Install uv and Python
50+
uses: astral-sh/setup-uv@v6
51+
with:
52+
version: ${{ inputs.uv-version }}
53+
python-version: ${{ inputs.python-version }}
54+
enable-cache: true
55+
cache-dependency-glob: ${{ inputs.working-directory }}/uv.lock
56+
57+
#----------------------------------------------
58+
# install dependencies via uv sync
59+
#----------------------------------------------
60+
- name: Install dependencies
61+
shell: bash
62+
working-directory: ${{ inputs.working-directory }}
63+
env:
64+
GROUPS: ${{ inputs.optional-dependency-groups }}
65+
run: |
66+
if [ -z "$GROUPS" ]; then
67+
uv sync --no-install-project --all-extras
68+
else
69+
GROUP_FLAGS=""
70+
IFS=',' read -ra GROUPS_ARR <<< "$GROUPS"
71+
for g in "${GROUPS_ARR[@]}"; do
72+
GROUP_FLAGS="$GROUP_FLAGS --group ${g// /}"
73+
done
74+
uv sync --no-install-project --all-extras $GROUP_FLAGS
75+
fi

.github/workflows/deploy-to-aws-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
uses: ./.github/workflows/deploy-to-aws.yml
2121
with:
2222
python-version: 3.11
23+
node-version: 22.22.1
2324
working-directory: samplePythonProject
2425
aws-login: false
2526
smoketest-query: 'query Query {country(code: "NZ") {capital}}'

.github/workflows/deploy-to-aws.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
working-directory: ${{ inputs.working-directory }}
100100
environment: ${{ (inputs.environment && ((github.ref == 'refs/heads/main') && 'AWS_PROD' || 'AWS_TEST')) || '' }}
101101
steps:
102-
- uses: actions/checkout@v4
102+
- uses: actions/checkout@v5
103103

104104
- uses: actions/setup-python@v5
105105
if: ${{ inputs.python-version != 'None' }}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Python Deploy Docs (uv)
2+
3+
# Publishes documentation for a python package to GitHub pages using uv. Uses `mkdocs` for building documentation.
4+
# Would commonly be one of two jobs along with Python Release Workflow in a repo workflow triggered by e.g. tagging a version.
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
python-version:
10+
description: The python version to use
11+
required: true
12+
type: string
13+
default: "3.10"
14+
uv-version:
15+
description: The uv version to use
16+
required: false
17+
type: string
18+
default: "latest"
19+
working-directory:
20+
description: The working directory
21+
required: false
22+
type: string
23+
default: .
24+
timeout-minutes:
25+
description: Maximum runtime in minutes
26+
required: false
27+
type: number
28+
default: 10
29+
optional-dependency-groups:
30+
description: Which optional group or groups to install. Use comma delimiter for multiple groups e.g `dev,doc`.
31+
required: false
32+
type: string
33+
default: dev
34+
35+
36+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
37+
permissions:
38+
contents: write
39+
pages: write
40+
id-token: write
41+
42+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
43+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
44+
concurrency:
45+
group: "pages"
46+
cancel-in-progress: false
47+
48+
jobs:
49+
deploy:
50+
environment:
51+
name: github-pages
52+
url: ${{ steps.deployment.outputs.page_url }}
53+
runs-on: ubuntu-latest
54+
timeout-minutes: ${{ inputs.timeout-minutes }}
55+
defaults:
56+
run:
57+
working-directory: ${{ inputs.working-directory }}
58+
59+
steps:
60+
61+
- uses: actions/checkout@v5
62+
63+
- name: install_package
64+
uses: GNS-Science/nshm-github-actions/.github/actions/python-install-uv@main
65+
with:
66+
python-version: ${{ inputs.python-version }}
67+
uv-version: ${{ inputs.uv-version }}
68+
working-directory: ${{ inputs.working-directory }}
69+
optional-dependency-groups: ${{ inputs.optional-dependency-groups }}
70+
71+
#----------------------------------------------
72+
# build documentation
73+
# - uv sync installs the project root by default; the composite action
74+
# uses --no-install-project, so sync here to bring it in before building
75+
#----------------------------------------------
76+
- name: build documentation
77+
run: |
78+
uv sync
79+
uv run mkdocs build
80+
81+
#----------------------------------------------
82+
# package and upload artifact for deployment to GitHub Pages
83+
#----------------------------------------------
84+
- name: Upload artifact
85+
uses: actions/upload-pages-artifact@v4
86+
with:
87+
path: ${{ inputs.working-directory }}/site
88+
89+
90+
#----------------------------------------------
91+
# deploy page
92+
#----------------------------------------------
93+
- name: Deploy Docs to GitHub Pages
94+
id: deployment
95+
uses: actions/deploy-pages@v4

.github/workflows/python-deploy-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858

5959
steps:
6060

61-
- uses: actions/checkout@v4
61+
- uses: actions/checkout@v5
6262

6363
- name: install_package
6464
uses: GNS-Science/nshm-github-actions/.github/actions/python-install@main
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Python Release (uv)
2+
3+
# Creates a GitHub release and publishes the package to PyPI using uv. Would commonly be one of two jobs along
4+
# with Python Deploy Docs in a repo workflow triggered by e.g. tagging a version.
5+
#
6+
# Requires the secret `PYPI_API_TOKEN`.
7+
8+
on:
9+
workflow_call:
10+
inputs:
11+
python-version:
12+
description: The python version to use
13+
required: true
14+
type: string
15+
default: "3.10"
16+
uv-version:
17+
description: The uv version to use
18+
required: false
19+
type: string
20+
default: "latest"
21+
working-directory:
22+
description: The working directory
23+
required: false
24+
type: string
25+
default: .
26+
timeout-minutes:
27+
description: Maximum runtime in minutes
28+
required: false
29+
type: number
30+
default: 10
31+
pypi-publish:
32+
description: Publish to PyPI or not
33+
required: false
34+
type: boolean
35+
default: true
36+
37+
38+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
39+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
40+
concurrency:
41+
group: "pages"
42+
cancel-in-progress: false
43+
44+
jobs:
45+
release:
46+
runs-on: ubuntu-latest
47+
timeout-minutes: ${{ inputs.timeout-minutes }}
48+
defaults:
49+
run:
50+
shell: bash
51+
working-directory: ${{ inputs.working-directory }}
52+
steps:
53+
54+
- uses: actions/checkout@v5
55+
56+
- name: install_package
57+
uses: GNS-Science/nshm-github-actions/.github/actions/python-install-uv@main
58+
with:
59+
python-version: ${{ inputs.python-version }}
60+
uv-version: ${{ inputs.uv-version }}
61+
working-directory: ${{ inputs.working-directory }}
62+
63+
#----------------------------------------------
64+
# get version
65+
#----------------------------------------------
66+
- name: Get version from tag
67+
id: tag_name
68+
run: |
69+
echo name=current_version::${GITHUB_REF#refs/tags/v} >> "$GITHUB_OUTPUT"
70+
shell: bash
71+
72+
#----------------------------------------------
73+
# get changelog entry
74+
#----------------------------------------------
75+
- name: Get Changelog Entry
76+
id: changelog_reader
77+
uses: GNS-Science/changelog-reader-action@master
78+
with:
79+
validation_depth: 10
80+
version: ${{ steps.tag_name.outputs.current_version }}
81+
path: ${{ inputs.working-directory }}/CHANGELOG.md
82+
83+
#----------------------------------------------
84+
# build wheels and tarball
85+
#----------------------------------------------
86+
- name: Build wheels and source tarball
87+
run: >-
88+
uv build
89+
90+
- name: show temporary files
91+
run: >-
92+
ls -l
93+
94+
#----------------------------------------------
95+
# create GitHub release
96+
#----------------------------------------------
97+
- name: create github release
98+
id: create_release
99+
uses: GNS-Science/action-gh-release@master
100+
env:
101+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
with:
103+
body: ${{ steps.changelog_reader.outputs.changes }}
104+
files: ${{ inputs.working-directory }}/dist/*.whl
105+
draft: false
106+
prerelease: false
107+
108+
#----------------------------------------------
109+
# publish to PyPI
110+
#----------------------------------------------
111+
- name: publish to PyPI
112+
if: ${{ inputs.pypi-publish }}
113+
uses: pypa/gh-action-pypi-publish@release/v1
114+
with:
115+
user: __token__
116+
password: ${{ secrets.PYPI_API_TOKEN }}
117+
skip-existing: true

.github/workflows/python-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
working-directory: ${{ inputs.working-directory }}
5252
steps:
5353

54-
- uses: actions/checkout@v4
54+
- uses: actions/checkout@v5
5555

5656
- name: install_package
5757
uses: GNS-Science/nshm-github-actions/.github/actions/python-install@main
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# A workflow that runs on push/PR to check that python-run-tests-uv.yml works
2+
3+
name: python-run-tests-uv test workflow
4+
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches: [main, pre-release]
9+
pull_request:
10+
branches: [main, pre-release]
11+
12+
jobs:
13+
call-test-workflow:
14+
uses: ./.github/workflows/python-run-tests-uv.yml
15+
with:
16+
operating-systems: "['ubuntu-latest', 'macos-latest', 'windows-latest']"
17+
python-versions: "['3.10', '3.11', '3.12', '3.13']"
18+
working-directory: samplePythonProjectUv
19+
fail-on-codecov-error: false
20+
secrets: inherit

.github/workflows/python-run-tests-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: ./.github/workflows/python-run-tests.yml
1919
with:
2020
operating-systems: "['ubuntu-latest', 'macos-latest', 'windows-latest']"
21-
python-versions: "['3.9', '3.10', '3.11']"
21+
python-versions: "['3.10', '3.11', '3.12', '3.13']"
2222
working-directory: samplePythonProject
2323
fail-on-codecov-error: false
2424
secrets: inherit

0 commit comments

Comments
 (0)