Skip to content

Commit cdab161

Browse files
committed
pre-commit hooks and better release action
1 parent 1ab9fdc commit cdab161

File tree

7 files changed

+74
-47
lines changed

7 files changed

+74
-47
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ Admin credentials are needed to access the setup.
133133

134134
- needs admin rights
135135
- we are using [semver](https://semver.org/) (see section on versioning)
136-
- we are using [GitHub Actions to deploy](./workflows/python_publish.yml)
137-
- PyPi credentials are stored as GitHub secrets
136+
- we are using [GitHub Actions to deploy](./workflows/release.yml)
138137

139138
Follow this workflow:
140139

.github/workflows/python_build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Update pip et al.
2929
run: |
3030
python -m pip install --upgrade pip
31-
python -m pip install --upgrade build
31+
python -m pip install --upgrade build twine
3232
3333
- uses: actions/checkout@v4
3434
with:
@@ -37,6 +37,8 @@ jobs:
3737
submodules: true
3838
- name: Build sdist
3939
run: python -m build --sdist
40+
- name: Check sdist
41+
run: twine check --strict dist/*
4042
- name: Install sdist
4143
run: pip install ./dist/pyprep-*
4244
- name: Clean up working directory
@@ -53,6 +55,8 @@ jobs:
5355
submodules: true
5456
- name: Build wheel
5557
run: python -m build --wheel
58+
- name: Check wheel
59+
run: twine check --strict dist/*
5660
- name: Install wheel
5761
run: pip install ./dist/pyprep-*.whl
5862
- name: Clean up working directory

.github/workflows/python_publish.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

.github/workflows/python_tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ jobs:
6363
- name: Check formatting
6464
if: matrix.platform == 'ubuntu-latest'
6565
run: |
66-
flake8 --docstring-convention numpy .
6766
pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
6867
6968
- name: Test with pytest

.github/workflows/release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Upload a Python Package using Twine when a release is created
2+
3+
name: build
4+
on: # yamllint disable-line rule:truthy
5+
release:
6+
types: [published]
7+
push:
8+
branches:
9+
- main
10+
pull_request:
11+
branches:
12+
- main
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
package:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-python@v5
23+
with:
24+
python-version: '3.12'
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
python -m pip install build twine
29+
- run: python -m build --sdist --wheel
30+
- run: twine check --strict dist/*
31+
- uses: actions/upload-artifact@v4
32+
with:
33+
name: dist
34+
path: dist
35+
36+
pypi-upload:
37+
needs: package
38+
runs-on: ubuntu-latest
39+
if: github.event_name == 'release'
40+
permissions:
41+
id-token: write # for trusted publishing
42+
environment:
43+
name: pypi
44+
url: https://pypi.org/p/pyprep
45+
steps:
46+
- uses: actions/download-artifact@v4
47+
with:
48+
name: dist
49+
path: dist
50+
- uses: pypa/gh-action-pypi-publish@release/v1
51+
if: github.event_name == 'release'

.pre-commit-config.yaml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
55
rev: v4.6.0
66
hooks:
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
- id: check-yaml
10-
- id: check-json
11-
- id: check-ast
12-
- id: check-added-large-files
13-
- id: check-case-conflict
14-
- id: check-docstring-first
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-json
11+
- id: check-ast
12+
- id: check-added-large-files
13+
- id: check-case-conflict
14+
- id: check-docstring-first
15+
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
rev: v0.6.2
18+
hooks:
19+
- id: ruff
20+
args: ["--fix"]
21+
- id: ruff-format

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dependencies = [
5454
# Dependencies for running the test infrastructure
5555
test = [
5656
"build",
57+
"twine",
5758
"ruff",
5859
"isort",
5960
"matplotlib",

0 commit comments

Comments
 (0)