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
100 changes: 100 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Publish package

# based on https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/

on:
push:
tags:
- '*'
- "!latest"

jobs:
test-and-build:
uses: ./.github/workflows/test.yml

check_version:
name: Check version
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes
needs: test-and-build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Read version from pyproject.toml
run: echo VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") >> "$GITHUB_ENV"
- run: echo $GITHUB_REF_NAME
- run: echo $VERSION
- name: Check that version and tag are identical
run: test $GITHUB_REF_NAME = $VERSION

publish-to-pypi:
name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes
needs:
- check_version
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/blaupause
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest
permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v3.0.0
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
"$GITHUB_REF_NAME"
--repo "$GITHUB_REPOSITORY"
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
"$GITHUB_REF_NAME" dist/**
--repo "$GITHUB_REPOSITORY"

latest-tag:
needs:
- publish-to-pypi
name: Update latest tag
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run latest-tag
uses: EndBug/latest-tag@latest
41 changes: 30 additions & 11 deletions .github/workflows/workflow.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: workflow
name: tests

on:
push:
Expand All @@ -7,50 +7,69 @@ on:
pull_request:
schedule:
- cron: '0 0 * * 1' # run every Monday
workflow_call:
workflow_dispatch:

env:
PYTEST_ADDOPTS: "--color=yes"

jobs:
workflow:
tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-13, windows-latest]
python-version: ["3.8", "3.10"]
python-version: ["3.13"]
include:
- os: ubuntu-latest
python-version: "3.9"
defaults:
run:
shell: bash -l {0}

steps:
- name: Initialisation
uses: actions/checkout@v4

- name: Set up conda
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
auto-update-conda: true
activate-environment: conda-environment
environment-file: .github/environment.yml

- name: Install package
run: python -m pip install .[dev]

- name: Unit tests
run: invoke test.unittest

if: matrix.os != 'ubuntu-latest'
- name: Unit tests with coverage
run: invoke test.coverage
if: matrix.os == 'ubuntu-latest'

- name: Documentation tests
run: invoke test.docs

- name: Jupyter notebook tests
run: invoke test.ipynb

- name: Upload coverage to Codecov.io
uses: codecov/codecov-action@v1
if: matrix.os == 'ubuntu-latest'

build:
needs: tests
name: Build wheel and sdist
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Install pypa/build
run: python -m pip install --user build
- name: Build wheel and source tarball
run: python -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ exclude: 'dev'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: check-merge-conflict # checks for files that contain merge conflict strings
- id: check-toml # checks toml files for parseable syntax
- id: debug-statements # checks for debugger imports and py37+ `breakpoint()` calls in python source

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
rev: v0.11.12
hooks:
# Run the linter.
- id: ruff
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

| Description | Badge |
| --- | --- |
| Tests | [![Build status](https://github.com/ubermag/micromagneticdata/workflows/workflow/badge.svg)](https://github.com/ubermag/micromagneticdata/actions?query=workflow%3Aworkflow) |
| Tests | [![tests](https://github.com/ubermag/micromagneticdata/actions/workflows/test.yml/badge.svg)](https://github.com/ubermag/micromagneticdata/actions/workflows/test.yml) |
| Linting | [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/ubermag/micromagneticdata/master.svg)](https://results.pre-commit.ci/latest/github/ubermag/micromagneticdata/master) |
| | [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) |
| Releases | [![PyPI version](https://badge.fury.io/py/micromagneticdata.svg)](https://badge.fury.io/py/micromagneticdata) |
Expand Down Expand Up @@ -72,7 +72,7 @@ Licensed under the BSD 3-Clause "New" or "Revised" License. For details, please

2. M. Beg, R. A. Pepper, and H. Fangohr. User interfaces for computational science: A domain specific language for OOMMF embedded in Python. [*AIP Advances* **7**, 56025](http://aip.scitation.org/doi/10.1063/1.4977225) (2017).

3. Marijan Beg, Martin Lang, Samuel Holt, Swapneel Amit Pathak, and Hans Fangohr. micromagneticdata: Python tools for the analysis of computational magnetism data DOI: [10.5281/zenodo.4624869](http://doi.org/10.5281/zenodo.4624869) (2023).
3. Marijan Beg, Martin Lang, Samuel Holt, Swapneel Amit Pathak, and Hans Fangohr. micromagneticdata: Python tools for the analysis of computational magnetism data DOI: [10.5281/zenodo.4624869](http://doi.org/10.5281/zenodo.4624869) (2025).

## Acknowledgements

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "micromagneticdata"
version = "0.65.3"
description = "Python tools for the analysis of computational magnetism data"
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.9"
license = {file = "LICENSE"}

authors = [
Expand Down Expand Up @@ -46,7 +46,8 @@ dev = [
"nbval",
"pre-commit",
"pytest-cov",
"twine"
"twine",
"tomli; python_version < '3.11'",
]

[project.urls]
Expand Down
10 changes: 8 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

import os
import shutil
import sys

import pytest
import tomli

if sys.version_info.minor < 11:
import tomli as tomllib
else:
import tomllib
from invoke import Collection, Exit, task

PYTHON = "python"
Expand Down Expand Up @@ -78,6 +83,7 @@ def build_dists(c):
if os.path.exists("dist"):
shutil.rmtree("dist")
c.run(f"{PYTHON} -m build")
c.run("twine check dist/*")


@task(build_dists)
Expand Down Expand Up @@ -113,7 +119,7 @@ def release(c):
raise e

with open("pyproject.toml", "rb") as f:
version = tomli.load(f)["project"]["version"]
version = tomllib.load(f)["project"]["version"]

c.run(f"git tag {version}") # fails if the tag exists
c.run("git tag -f latest") # `latest` tag for binder
Expand Down
Loading