Skip to content

Commit 1b40427

Browse files
adamarnesenCopilot
andauthored
ci: add release to PyPI with semantic versioning (#36)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 78d73d6 commit 1b40427

File tree

8 files changed

+151
-9
lines changed

8 files changed

+151
-9
lines changed

.github/workflows/python-package.yml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ name: Python package
33
on:
44
push:
55
branches: [master, main]
6+
paths:
7+
- 'nisystemlink_examples/**'
8+
- 'tests/**'
9+
- 'pyproject.toml'
10+
- '.github/workflows/python-package.yml'
611
pull_request:
712
branches: [master, main]
8-
workflow_dispatch:
13+
paths:
14+
- 'nisystemlink_examples/**'
15+
- 'tests/**'
16+
- 'pyproject.toml'
17+
- '.github/workflows/python-package.yml'
918

1019
jobs:
1120
build-lint-unit-test:
@@ -25,4 +34,38 @@ jobs:
2534
- run: poetry run poe test
2635
- run: poetry run poe check
2736
- run: poetry run poe lint
28-
- run: poetry run poe types
37+
- run: poetry run poe types
38+
release:
39+
runs-on: ubuntu-latest
40+
needs: [build-lint-unit-test]
41+
if: github.event_name == github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')
42+
environment:
43+
name: pypi
44+
url: https://pypi.org/p/nisystemlink-examples
45+
permissions:
46+
id-token: write
47+
contents: write
48+
steps:
49+
- uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0
52+
token: ${{ secrets.GH_REPO_TOKEN }}
53+
- name: Install poetry
54+
run: pipx install poetry
55+
- uses: actions/setup-python@v5
56+
with:
57+
python-version: '3.10'
58+
cache: "poetry"
59+
- run: poetry install
60+
- name: Semantic release
61+
run: |
62+
pip install python-semantic-release==7.34.6
63+
git config --global user.name "github-actions"
64+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
65+
semantic-release version
66+
env:
67+
GH_TOKEN: ${{secrets.GH_REPO_TOKEN}}
68+
- name: Build package
69+
run: poetry build
70+
- name: Publish to PyPI
71+
uses: pypa/gh-action-pypi-publish@release/v1

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"python.testing.pytestArgs": ["tests"],
3+
"python.testing.unittestEnabled": false,
4+
"python.testing.pytestEnabled": true
5+
}

CONTRIBUTING.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,100 @@ You can also run all checks at once:
8080
poetry run poe format && poetry run poe lint && poetry run poe types && poetry run poe test
8181
```
8282

83+
## Commit Message Convention
84+
85+
This project uses [Conventional Commits](https://www.conventionalcommits.org/)
86+
for automated versioning and changelog generation of the `nisystemlink_examples`
87+
Python package.
88+
89+
**When conventional commits matter:**
90+
91+
- Commits to the `nisystemlink_examples/` package code
92+
- Changes to `tests/`, `pyproject.toml`, or the CI workflow
93+
- When merged to the `main` branch
94+
95+
For other contributions (examples, documentation, etc.), conventional commit
96+
format is optional but still encouraged for consistency.
97+
98+
### Commit Message Format
99+
100+
```md
101+
<type>[optional scope]: <description>
102+
103+
[optional body]
104+
105+
[optional footer(s)]
106+
```
107+
108+
### Common Types and Version Bumps
109+
110+
- **`fix:`** - A bug fix (triggers a **PATCH** version bump: 0.1.0 → 0.1.1)
111+
112+
```md
113+
fix: correct calculation error in test result processing fix(simulator):
114+
handle empty response from API endpoint
115+
```
116+
117+
- **`feat:`** - A new feature (triggers a **MINOR** version bump: 0.1.0 → 0.2.0)
118+
119+
```md
120+
feat: add support for querying test results by date range feat(testdata): add
121+
batch delete functionality for test results
122+
```
123+
124+
- **`feat!:`** or **`BREAKING CHANGE:`** - A breaking change (triggers a
125+
**MAJOR** version bump: 0.1.0 → 1.0.0)
126+
127+
```md
128+
feat!: remove deprecated create_result method
129+
```
130+
131+
Or with a footer:
132+
133+
```md
134+
feat: redesign simulator API
135+
136+
BREAKING CHANGE: The create_result method has been removed. Use
137+
create_results_and_steps instead.
138+
```
139+
140+
### Other Common Types (no version bump)
141+
142+
- **`docs:`** - Documentation changes only
143+
- **`style:`** - Code style changes (formatting, whitespace, etc.)
144+
- **`refactor:`** - Code refactoring without changing functionality
145+
- **`test:`** - Adding or updating tests
146+
- **`chore:`** - Maintenance tasks, dependency updates, etc.
147+
- **`ci:`** - CI/CD configuration changes
148+
149+
### Examples
150+
151+
```bash
152+
# Patch release (0.1.0 → 0.1.1)
153+
git commit -m "fix: handle empty response from API endpoint"
154+
155+
# Minor release (0.1.0 → 0.2.0)
156+
git commit -m "feat: add batch delete functionality for test results"
157+
158+
# Major release (1.0.0 → 2.0.0) - use commit editor for multi-line
159+
git commit
160+
# Then in the editor:
161+
# feat!: redesign simulator API with new parameter structure
162+
#
163+
# BREAKING CHANGE: Removed create_result(), use create_results_and_steps()
164+
```
165+
166+
**What triggers an automated release:**
167+
168+
When commits following the conventional format are merged to `main` and affect:
169+
170+
- `nisystemlink_examples/**` (package source code)
171+
- `tests/**` (test files)
172+
- `pyproject.toml` (package configuration)
173+
- `.github/workflows/python-package.yml` (CI/CD workflow)
174+
175+
The package will be automatically versioned, tagged, and published to PyPI.
176+
83177
## Security scanning with Snyk
84178

85179
This repository uses [Snyk](https://snyk.io/) for security scanning to identify
File renamed without changes.
File renamed without changes.

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.poetry]
2-
name = "nisystemlink-demo"
2+
name = "nisystemlink-examples"
33
version = "0.0.0"
44
description = "NI SystemLink examples and demo utilities"
55
authors = ["National Instruments"]
@@ -11,7 +11,7 @@ readme = "README.md"
1111
keywords = ["nisystemlink", "systemlink"]
1212
license = "MIT"
1313
packages = [
14-
{include = "nisystemlink_demo"}
14+
{include = "nisystemlink_examples"}
1515
]
1616

1717
[tool.poetry.dependencies]
@@ -45,7 +45,7 @@ match = "(main|master)"
4545

4646
[tool.poe.tasks]
4747
test = "pytest tests"
48-
lint = "flake8 nisystemlink_demo tests"
49-
check = "black --check nisystemlink_demo tests"
50-
format = "black nisystemlink_demo tests"
51-
types = "mypy nisystemlink_demo tests"
48+
lint = "flake8 nisystemlink_examples tests"
49+
check = "black --check nisystemlink_examples tests"
50+
format = "black nisystemlink_examples tests"
51+
types = "mypy nisystemlink_examples tests"

tests/testdata/test_simulator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Unit tests for the Simulator class."""
22

3-
from nisystemlink_demo.testdata.simulator import Simulator
3+
from nisystemlink_examples.testdata.simulator import Simulator
44

55

66
class TestSimulator:

0 commit comments

Comments
 (0)