Skip to content

Commit 7b25c41

Browse files
committed
Add public SDK CI + modern publish workflow
1 parent f63cf4b commit 7b25c41

File tree

2 files changed

+85
-54
lines changed

2 files changed

+85
-54
lines changed

.github/workflows/ci.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test-build:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
cache: pip
27+
28+
- name: Install
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install ".[dev]"
32+
pip install build
33+
34+
- name: Pytest
35+
run: pytest
36+
37+
- name: Build sdist/wheel
38+
run: python -m build
39+
40+
- name: Upload dist artifacts
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: dist-py${{ matrix.python-version }}
44+
path: dist/*
45+
if-no-files-found: error
46+
47+
- name: Upload coverage HTML
48+
if: ${{ matrix.python-version == '3.11' }}
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: coverage-html
52+
path: htmlcov/
53+
if-no-files-found: ignore

.github/workflows/publish.yml

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,51 @@
1-
name: Publish to PyPI and GitHub Packages
1+
name: Publish
22

33
on:
44
push:
55
tags:
66
- 'v*'
7+
workflow_dispatch: {}
78

89
jobs:
9-
deploy:
10+
publish:
1011
runs-on: ubuntu-latest
11-
12+
1213
permissions:
13-
contents: read
14-
packages: write
15-
14+
contents: write
15+
id-token: write
16+
1617
steps:
17-
- uses: actions/checkout@v3
18-
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
1921
- name: Set up Python
20-
uses: actions/setup-python@v4
22+
uses: actions/setup-python@v5
2123
with:
2224
python-version: '3.11'
23-
24-
- name: Install dependencies
25+
cache: pip
26+
27+
- name: Install
2528
run: |
2629
python -m pip install --upgrade pip
27-
pip install build wheel twine
28-
29-
- name: Build package
30+
pip install ".[dev]" build
31+
32+
- name: Test
33+
run: pytest
34+
35+
- name: Build
3036
run: python -m build
31-
32-
- name: Publish to PyPI
33-
env:
34-
TWINE_USERNAME: __token__
35-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
36-
run: twine upload dist/*
37-
38-
- name: Publish to GitHub Packages
39-
env:
40-
TWINE_USERNAME: __token__
41-
TWINE_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
42-
run: |
43-
twine upload dist/* \
44-
--repository-url https://upload.pypi.org/legacy/ || true
45-
46-
- name: Create Release
47-
uses: actions/create-release@v1
48-
env:
49-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Publish to PyPI (token)
39+
if: ${{ secrets.PYPI_API_TOKEN != '' }}
40+
uses: pypa/gh-action-pypi-publish@release/v1
5041
with:
51-
tag_name: ${{ github.ref }}
52-
release_name: Release ${{ github.ref }}
53-
body: |
54-
# Release ${{ github.ref }}
55-
56-
**PyPI:** https://pypi.org/project/hexarch-guardrails/
57-
58-
## Installation
59-
```bash
60-
pip install hexarch-guardrails
61-
```
62-
63-
## Changes
64-
See CHANGELOG.md for details.
65-
draft: false
66-
prerelease: false
67-
68-
- name: Upload Release Assets
69-
uses: softprops/action-gh-release@v1
42+
password: ${{ secrets.PYPI_API_TOKEN }}
43+
44+
- name: Publish to PyPI (trusted publishing)
45+
if: ${{ secrets.PYPI_API_TOKEN == '' }}
46+
uses: pypa/gh-action-pypi-publish@release/v1
47+
48+
- name: GitHub Release
49+
uses: softprops/action-gh-release@v2
7050
with:
7151
files: dist/*
72-
env:
73-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)