@@ -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
338336on:
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
345340jobs:
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
387389on:
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+
393404jobs:
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 }
0 commit comments