Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
619012a
shared release workflow
chrisdicaprio Aug 24, 2025
887ba5b
add mkdocs
chrisdicaprio Aug 24, 2025
2528323
dummy documentation for testing
chrisdicaprio Aug 24, 2025
3f39b6b
working directory arg; release
chrisdicaprio Aug 25, 2025
1631953
test release workflow
chrisdicaprio Aug 25, 2025
105c100
remove TODO comments
chrisdicaprio Aug 25, 2025
398e69c
add changelog
chrisdicaprio Aug 25, 2025
33654b7
use GNS changelog action
chrisdicaprio Aug 25, 2025
ce95b98
comment out job env and defaults
chrisdicaprio Aug 25, 2025
8e9b930
checkout repo before using working-directory
chrisdicaprio Aug 25, 2025
7f755e9
change changelog path
chrisdicaprio Aug 25, 2025
0d91312
explicit working dir for changelog
chrisdicaprio Aug 25, 2025
ccf0e85
x
chrisdicaprio Aug 25, 2025
3fb9dad
optional version
chrisdicaprio Aug 25, 2025
0a20ec8
conitidional inside step
chrisdicaprio Aug 25, 2025
e43c186
remove if statements
chrisdicaprio Aug 25, 2025
92d5f6b
add fi
chrisdicaprio Aug 25, 2025
3ddc559
set env var
chrisdicaprio Aug 25, 2025
fdeb714
swap if statement
chrisdicaprio Aug 25, 2025
34f9c53
set output of echo
chrisdicaprio Aug 25, 2025
630ccf7
fix if
chrisdicaprio Aug 25, 2025
8d1015e
test version
chrisdicaprio Aug 25, 2025
2db9f20
fix echo
chrisdicaprio Aug 25, 2025
922d28e
fix changelog
chrisdicaprio Aug 25, 2025
464fd21
explicit paths
chrisdicaprio Aug 25, 2025
c6baa2b
only release if there is a tag
chrisdicaprio Aug 25, 2025
6743ca2
fix if
chrisdicaprio Aug 25, 2025
3aab2dc
fix if again
chrisdicaprio Aug 25, 2025
3802972
pypi only if tag
chrisdicaprio Aug 25, 2025
70b0c5f
remove files use for testing release workflow
chrisdicaprio Aug 25, 2025
a2598f4
remove release test
chrisdicaprio Aug 25, 2025
08b54ac
remove components used for testing
chrisdicaprio Aug 25, 2025
91136b7
remove mkdocs
chrisdicaprio Aug 25, 2025
ee9bc72
split publication/deployment of docs from release/PyPI distribution
chrisdicaprio Aug 27, 2025
ef478e3
deploy docs
chrisdicaprio Aug 27, 2025
b9f855d
change name
chrisdicaprio Aug 27, 2025
3d68292
checkout repo
chrisdicaprio Aug 27, 2025
85b015a
setup venv
chrisdicaprio Aug 27, 2025
9430caf
white space
chrisdicaprio Aug 27, 2025
66ee2f3
add timeout and env
chrisdicaprio Aug 27, 2025
bc56e9f
split out setup python, poetry, and install package for sharing
chrisdicaprio Aug 27, 2025
749896f
move python install to actions
chrisdicaprio Aug 27, 2025
b329b49
actions/checkout
chrisdicaprio Aug 27, 2025
5272d6c
defaults
chrisdicaprio Aug 27, 2025
e550991
fix defaults
chrisdicaprio Aug 27, 2025
35f311e
remove defaults
chrisdicaprio Aug 27, 2025
20e289c
add shell to all steps
chrisdicaprio Aug 27, 2025
a344898
only shell with run
chrisdicaprio Aug 27, 2025
875824e
working directory
chrisdicaprio Aug 27, 2025
7929ded
cd to working dir
chrisdicaprio Aug 27, 2025
0ee8ee8
remove working-dir variable from steps
chrisdicaprio Aug 27, 2025
5f59bd3
fix cd
chrisdicaprio Aug 27, 2025
3c36a89
fix bug
chrisdicaprio Aug 27, 2025
b56bc39
cd every step
chrisdicaprio Aug 27, 2025
2a0f29a
set env
chrisdicaprio Aug 27, 2025
c080bed
a little test
chrisdicaprio Aug 27, 2025
01cbd18
use working-directory for run
chrisdicaprio Aug 27, 2025
775a1eb
use composite action
chrisdicaprio Aug 27, 2025
5f4bae5
reference action by repo
chrisdicaprio Aug 27, 2025
9dd547f
reference action by repo
chrisdicaprio Aug 27, 2025
848f0f6
fix small bugs
chrisdicaprio Aug 27, 2025
3bcdae9
boolians in composite actions are actually strings
chrisdicaprio Aug 27, 2025
e725d91
remove deprecated set-output, replace with
chrisdicaprio Aug 27, 2025
db97a35
retrigger checks
chrisdicaprio Aug 27, 2025
5d3aba0
add timeout, fix typo
chrisdicaprio Aug 27, 2025
74e305c
update changelog
chrisdicaprio Aug 27, 2025
f3030d4
switch to main branch
chrisdicaprio Aug 28, 2025
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
80 changes: 80 additions & 0 deletions .github/actions/python-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Setup Python Venv

# Reusable workflow for Python projects that checks out repo and installs with Poetry


inputs:
python-version:
description: A Python version to use
required: true
type: string
poetry-version:
description: The poetry version to use
required: false
type: string
working-directory:
description: The working directory
required: false
type: string
default: .
delete-poetry-lock:
description: Delete poetry lock file in order to test against newer versions
required: false
type: boolean
default: false

runs:
using: "composite"
steps:


#----------------------------------------------
# delete poetry.lock file in order to run tests against newer versions
#----------------------------------------------
- name: Delete poetry.lock file
if: ${{ inputs.delete-poetry-lock == 'true' }}
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
rm ./poetry.lock
echo "::Warning tile=poetry.lock::Poetry.lock is deleted in this workflow run. You might have to do this too when reproducing build errors."

#----------------------------------------------
# install Python
#----------------------------------------------
- uses: actions/setup-python@v5
id: pythonInstallStep
with:
python-version: ${{ inputs.python-version }}

#----------------------------------------------
# install Poetry
#----------------------------------------------
- name: Install and configure Poetry
uses: GNS-Science/install-poetry@main
with:
version: ${{ inputs.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
if: ${{ inputs.delete-poetry-lock == 'false' }}
uses: actions/cache@v4
with:
path: ${{ inputs.working-directory }}/.venv
key: venv-${{ runner.os }}-${{ steps.pythonInstallStep.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-python-run-tests

#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
shell: bash
if: inputs.delete-poetry-lock || steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
working-directory: ${{ inputs.working-directory }}
run:
poetry install --no-interaction --no-root --with dev --all-extras
86 changes: 86 additions & 0 deletions .github/workflows/python-deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Python Deploy Docs

# Publishes documentation for a python package to GitHub pages. Uses `mkdocs` for building documentation. Would commonly
# be one of two jobs along with 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"
poetry-version:
description: The poetry 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


# 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@v4

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

#----------------------------------------------
# build documentation
#----------------------------------------------
- name: build documentation
run: |
poetry 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
111 changes: 111 additions & 0 deletions .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Python Release

# Creates a GitHub release and publishes the package to PyPI. Would commonly be one of two jobs along
# with 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"
poetry-version:
description: The poetry version to use
required: false
type: string
default: "latest"
working-directory:
Comment thread
chrisdicaprio marked this conversation as resolved.
description: The working directory
required: false
type: string
default: .
timeout-minutes:
description: Maximum runtime in minutes
required: false
type: number
default: 10


# 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@v4

- name: install_package
uses: GNS-Science/nshm-github-actions/.github/actions/python-install@main
with:
python-version: ${{ inputs.python-version }}
poetry-version: ${{ inputs.poetry-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
Comment thread
chrisdicaprio marked this conversation as resolved.
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: >-
poetry 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
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
52 changes: 5 additions & 47 deletions .github/workflows/python-run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,57 +78,15 @@ jobs:
PYTHON: ${{ matrix.python-version }}
steps:

#----------------------------------------------
# check out repo
#----------------------------------------------
- uses: actions/checkout@v4

#----------------------------------------------
# delete poetry.lock file in order to run tests against newer versions
#----------------------------------------------
- name: Delete poetry.lock file
if: ${{ inputs.delete-poetry-lock }}
run: |
rm ./poetry.lock
echo "::Warning tile=poetry.lock::Poetry.lock is deleted in this workflow run. You might have to do this too when reproducing build errors."

#----------------------------------------------
# install Python
#----------------------------------------------
- uses: actions/setup-python@v5
id: pythonInstallStep
- name: install_package
uses: GNS-Science/nshm-github-actions/.github/actions/python-install@main
with:
python-version: ${{ matrix.python-version }}

#----------------------------------------------
# install Poetry
#----------------------------------------------
- name: Install and configure Poetry
uses: GNS-Science/install-poetry@main
with:
version: ${{ inputs.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
if: ${{ ! inputs.delete-poetry-lock }}
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.pythonInstallStep.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-python-run-tests

#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: inputs.delete-poetry-lock || steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run:
poetry install --no-interaction --no-root --with dev --all-extras
poetry-version: ${{ inputs.poetry-version }}
working-directory: ${{ inputs.working-directory }}
delete-poetry-lock: ${{ inputs.delete-poetry-lock }}

#----------------------------------------------
# Install tox-gh-actions.
Expand Down
35 changes: 35 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,38 @@ jobs:
python-versions: "['3.9', '3.10', '3.11']"
secrets: inherit
```

### [Python Release Workflow](./.github/workflows/python-release.yml)

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

Requires the secret `PYPI_API_TOKEN`.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would add this to the top of the yml file too, to be sure.


Example use:

```yml
jobs:
release-and-distribute:
uses: GNS-Science/nshm-github-actions/.github/workflows/python-release.yml@main
with:
python-version: '3.12'
secrets: inherit
```


### [Python Deploy Docs Workflow](./.github/workflows/python-deploy-docs.yml)

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

Requires that the branch or tag you want to use has permission to do so in the `github-pages` environment; see [GitHub documentation](https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments).

Example use:

```yml
jobs:
deploy-docs:
uses: GNS-Science/nshm-github-actions/.github/workflows/python-deploy-docs.yml@main
with:
python-version: '3.12'
secrets: inherit
```
2 changes: 1 addition & 1 deletion samplePythonProject/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion samplePythonProject/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ packages = [
]

dependencies = [
"pytest (>=8.3.5,<9.0.0)"
"pytest (>=8.3.5,<9.0.0)",
]

[tool.poetry.dependencies]
Expand Down
Loading