Skip to content

Commit 2f387b5

Browse files
committed
opinions about github workflows and badges
1 parent fbec3f4 commit 2f387b5

9 files changed

Lines changed: 211 additions & 44 deletions

File tree

.github/workflows/docs.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Generated by preen — do not edit manually
2+
# Regenerate with: preen sync
3+
4+
name: Documentation
5+
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: [main]
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
concurrency:
18+
group: "pages"
19+
cancel-in-progress: false
20+
21+
jobs:
22+
build:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
- name: Setup uv
28+
uses: astral-sh/setup-uv@v4
29+
- name: Install dependencies
30+
run: uv sync --extra docs
31+
- name: Setup Pages
32+
uses: actions/configure-pages@v4
33+
- name: Build documentation
34+
run: |
35+
uv run sphinx-build -W -b html docs docs/_build/html
36+
- name: Upload artifact
37+
uses: actions/upload-pages-artifact@v3
38+
with:
39+
path: docs/_build/html
40+
41+
deploy:
42+
environment:
43+
name: github-pages
44+
url: ${{ steps.deployment.outputs.page_url }}
45+
runs-on: ubuntu-latest
46+
needs: build
47+
if: github.ref == 'refs/heads/main'
48+
steps:
49+
- name: Deploy to GitHub Pages
50+
id: deployment
51+
uses: actions/deploy-pages@v4
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Generated by preen — do not edit manually
2+
# Regenerate with: preen sync
3+
4+
name: Publish Python Package
5+
6+
on:
7+
release:
8+
types: [published]
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: astral-sh/setup-uv@v4
16+
- name: Build package
17+
run: uv build
18+
- uses: actions/upload-artifact@v4
19+
with:
20+
name: python-package-distributions
21+
path: dist/
22+
23+
publish-to-pypi:
24+
name: Publish to PyPI
25+
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes
26+
needs:
27+
- build
28+
runs-on: ubuntu-latest
29+
environment:
30+
name: pypi
31+
url: https://pypi.org/p/preen
32+
permissions:
33+
id-token: write # IMPORTANT: mandatory for trusted publishing
34+
35+
steps:
36+
- name: Download all the dists
37+
uses: actions/download-artifact@v4
38+
with:
39+
name: python-package-distributions
40+
path: dist/
41+
- name: Publish distribution to PyPI
42+
uses: pypa/gh-action-pypi-publish@release/v1

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# preen
22

3+
[![PyPI version](https://badge.fury.io/py/preen.svg)](https://badge.fury.io/py/preen)
4+
[![CI](https://github.com/gojiplus/preen/actions/workflows/ci.yml/badge.svg)](https://github.com/gojiplus/preen/actions)
5+
[![Documentation](https://github.com/gojiplus/preen/actions/workflows/docs.yml/badge.svg)](https://gojiplus.github.io/preen)
6+
[![Downloads](https://pepy.tech/badge/preen)](https://pepy.tech/project/preen)
7+
38
**An opinionated, agentic CLI for Python package hygiene and release**
49

510
*"Get your feathers in order before you fly"*

docs/conf.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Generated by preen — do not edit manually
2+
# Regenerate with: preen sync
3+
4+
import importlib.metadata
5+
6+
project = "preen"
7+
version = importlib.metadata.version("preen")
8+
author = "Gaurav Sood"
9+
10+
extensions = [
11+
"sphinx.ext.autodoc",
12+
"sphinx.ext.napoleon",
13+
"sphinx.ext.viewcode",
14+
"sphinx.ext.intersphinx",
15+
"myst_parser",
16+
]
17+
18+
html_theme = "furo"
19+
20+
# MyST settings
21+
myst_enable_extensions = [
22+
"colon_fence",
23+
"deflist",
24+
]
25+
26+
# Intersphinx
27+
intersphinx_mapping = {{
28+
"python": ("https://docs.python.org/3", None),
29+
}}
30+
31+
# Napoleon settings (Google style)
32+
napoleon_google_docstring = True
33+
napoleon_numpy_docstring = False
20 Bytes
Binary file not shown.

preen/commands/init.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def get_package_metadata() -> Dict[str, Any]:
107107
"license": license_name,
108108
"repository_url": repository_url,
109109
"homepage_url": homepage_url,
110+
"github_username": github_username,
110111
"has_cli": has_cli,
111112
}
112113

@@ -237,6 +238,7 @@ def init_package(
237238
"license": "MIT",
238239
"repository_url": f"https://github.com/yourname/{package_name}",
239240
"homepage_url": f"https://github.com/yourname/{package_name}",
241+
"github_username": "yourname",
240242
"has_cli": False,
241243
}
242244
else:

preen/syncer.py

Lines changed: 72 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ def _render_ci_yml(python_versions: List[str], config: PreenConfig) -> str:
312312
"""
313313

314314

315-
def _render_release_yml(name: str, config: PreenConfig) -> str:
316-
"""Generate the content for a release workflow file.
315+
def _render_python_publish_yml(name: str, config: PreenConfig) -> str:
316+
"""Generate the content for a PyPI publishing workflow file.
317317
318318
Parameters
319319
----------
@@ -326,48 +326,50 @@ def _render_release_yml(name: str, config: PreenConfig) -> str:
326326
Returns
327327
-------
328328
str
329-
YAML content for ``release.yml``.
329+
YAML content for ``python-publish.yml``.
330330
"""
331-
tag_prefix = config.tag_prefix
332-
333331
return f"""# Generated by preen — do not edit manually
334332
# Regenerate with: preen sync
335333
336-
name: Release
334+
name: Publish Python Package
337335
338336
on:
339-
workflow_dispatch:
340-
inputs:
341-
version:
342-
description: 'Version to release (must match pyproject.toml)'
343-
required: true
337+
release:
338+
types: [published]
344339
345340
jobs:
346-
release:
341+
build:
347342
runs-on: ubuntu-latest
348-
environment: pypi # trusted publisher environment
349-
permissions:
350-
id-token: write
351-
contents: write
352-
353343
steps:
354344
- uses: actions/checkout@v4
355345
- uses: astral-sh/setup-uv@v4
356-
- name: Verify version matches
357-
run: |
358-
TOML_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\\(.*\\)"/\\1/')
359-
if [ "$TOML_VERSION" != "${{{{ inputs.version }}}}" ]; then
360-
echo "Version mismatch: pyproject.toml has $TOML_VERSION, input has ${{{{ inputs.version }}}}"
361-
exit 1
362-
fi
363-
- name: Build
346+
- name: Build package
364347
run: uv build
365-
- name: Publish to PyPI
348+
- uses: actions/upload-artifact@v4
349+
with:
350+
name: python-package-distributions
351+
path: dist/
352+
353+
publish-to-pypi:
354+
name: Publish to PyPI
355+
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes
356+
needs:
357+
- build
358+
runs-on: ubuntu-latest
359+
environment:
360+
name: pypi
361+
url: https://pypi.org/p/{name}
362+
permissions:
363+
id-token: write # IMPORTANT: mandatory for trusted publishing
364+
365+
steps:
366+
- name: Download all the dists
367+
uses: actions/download-artifact@v4
368+
with:
369+
name: python-package-distributions
370+
path: dist/
371+
- name: Publish distribution to PyPI
366372
uses: pypa/gh-action-pypi-publish@release/v1
367-
- name: Create Git tag
368-
run: |
369-
git tag {tag_prefix}${{{{ inputs.version }}}}
370-
git push origin {tag_prefix}${{{{ inputs.version }}}}
371373
"""
372374

373375

@@ -382,29 +384,54 @@ def _render_docs_yml() -> str:
382384
return """# Generated by preen — do not edit manually
383385
# Regenerate with: preen sync
384386
385-
name: Docs
387+
name: Documentation
386388
387389
on:
388390
push:
389391
branches: [main]
390392
pull_request:
391393
branches: [main]
392394
395+
permissions:
396+
contents: read
397+
pages: write
398+
id-token: write
399+
400+
concurrency:
401+
group: "pages"
402+
cancel-in-progress: false
403+
393404
jobs:
394-
docs:
405+
build:
395406
runs-on: ubuntu-latest
396407
steps:
397-
- uses: actions/checkout@v4
398-
- uses: astral-sh/setup-uv@v4
399-
- run: uv sync --extra docs
400-
- run: uv run sphinx-build -b html docs docs/_build
401-
402-
- name: Deploy to GitHub Pages
403-
if: github.ref == 'refs/heads/main'
404-
uses: peaceiris/actions-gh-pages@v3
408+
- name: Checkout
409+
uses: actions/checkout@v4
410+
- name: Setup uv
411+
uses: astral-sh/setup-uv@v4
412+
- name: Install dependencies
413+
run: uv sync --extra docs
414+
- name: Setup Pages
415+
uses: actions/configure-pages@v4
416+
- name: Build documentation
417+
run: |
418+
uv run sphinx-build -W -b html docs docs/_build/html
419+
- name: Upload artifact
420+
uses: actions/upload-pages-artifact@v3
405421
with:
406-
github_token: ${{ secrets.GITHUB_TOKEN }}
407-
publish_dir: docs/_build
422+
path: docs/_build/html
423+
424+
deploy:
425+
environment:
426+
name: github-pages
427+
url: ${{ steps.deployment.outputs.page_url }}
428+
runs-on: ubuntu-latest
429+
needs: build
430+
if: github.ref == 'refs/heads/main'
431+
steps:
432+
- name: Deploy to GitHub Pages
433+
id: deployment
434+
uses: actions/deploy-pages@v4
408435
"""
409436

410437

@@ -469,7 +496,9 @@ def sync_project(
469496
"docs": {"docs/conf.py": _render_docs_conf(name, author_str, config)},
470497
"ci": {".github/workflows/ci.yml": _render_ci_yml(python_versions, config)},
471498
"workflows": {
472-
".github/workflows/release.yml": _render_release_yml(name, config),
499+
".github/workflows/python-publish.yml": _render_python_publish_yml(
500+
name, config
501+
),
473502
".github/workflows/docs.yml": _render_docs_yml(),
474503
},
475504
}

preen/templates/files/README.md.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# {{ package_name }}
22

3+
[![PyPI version](https://badge.fury.io/py/{{ package_name }}.svg)](https://badge.fury.io/py/{{ package_name }})
4+
[![CI](https://github.com/{{ github_username }}/{{ package_name }}/actions/workflows/ci.yml/badge.svg)](https://github.com/{{ github_username }}/{{ package_name }}/actions)
5+
[![Documentation](https://github.com/{{ github_username }}/{{ package_name }}/actions/workflows/docs.yml/badge.svg)](https://{{ github_username }}.github.io/{{ package_name }})
6+
[![Downloads](https://pepy.tech/badge/{{ package_name }})](https://pepy.tech/project/{{ package_name }})
7+
38
{{ description }}
49

510
## Installation

tests/test_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_sync_creates_files(tmp_path: Path) -> None:
4848
"CITATION.cff",
4949
"docs/conf.py",
5050
".github/workflows/ci.yml",
51-
".github/workflows/release.yml",
51+
".github/workflows/python-publish.yml",
5252
".github/workflows/docs.yml",
5353
}
5454
assert all_files == expected

0 commit comments

Comments
 (0)