Skip to content

Commit 6afd6d5

Browse files
authored
ci: publish releases to github and pypi
* Use composite actions for Python initialization and clean-up * Update the Ruff pre-commit hook to v0.13.1 * Only `ruff checkout --output-format=github` for the pre-commit `hook-stage=manual` * Upgrade to actions/checkout@v5 * Add build validation to PRs targeting main * Track project version in `usajobsapi/_version.py` * Publish releases to GitHub Releases using `python-semantic-release` * Publish releases to PyPI
1 parent 26e996c commit 6afd6d5

9 files changed

Lines changed: 180 additions & 40 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: python-init
2+
description: "Initialize a job for Python with uv"
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Install Python
7+
uses: actions/setup-python@v5
8+
with:
9+
python-version-file: "pyproject.toml"
10+
11+
- name: Install uv
12+
uses: astral-sh/setup-uv@v6
13+
with:
14+
enable-cache: true
15+
16+
- name: Install the project
17+
run: uv sync --locked --all-extras --dev
18+
shell: bash
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: python-post
2+
description: "Clean-up a job that uses 'python-init'"
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Minimize uv cache
7+
run: uv cache prune --ci
8+
shell: bash

.github/workflows/ci.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: ["main"]
7+
8+
jobs:
9+
lint:
10+
name: Lint Python
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v5
15+
- uses: ./.github/actions/python-init
16+
- name: Run pre-commit
17+
run: uv run pre-commit run --all-files --hook-stage manual
18+
- uses: ./.github/actions/python-post
19+
20+
test:
21+
name: Test Python
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- uses: actions/checkout@v5
26+
- uses: ./.github/actions/python-init
27+
- name: Run tests
28+
run: uv run pytest tests
29+
- uses: ./.github/actions/python-post

.github/workflows/ci.yml

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

.github/workflows/release.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: build
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
5+
cancel-in-progress: true
6+
7+
on:
8+
pull_request:
9+
branches: [main] # PR verification only (base=main)
10+
push:
11+
branches: [main] # releases on merges to main
12+
13+
jobs:
14+
# Build job for PR verification
15+
build:
16+
if: github.event_name == 'pull_request'
17+
name: Build
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
22+
steps:
23+
- uses: actions/checkout@v5
24+
with:
25+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
26+
- uses: ./.github/actions/python-init
27+
- name: Build sdist and wheel
28+
run: uv build
29+
- uses: ./.github/actions/python-post
30+
31+
# Publish releases on changes to main
32+
release:
33+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'paddy74/python-usajobsapi'
34+
name: Create a Release
35+
runs-on: ubuntu-latest
36+
permissions:
37+
contents: write # tags + GitHub Release
38+
id-token: write # PyPI Trusted Publishing
39+
environment:
40+
name: pypi
41+
url: https://pypi.org/p/python-usajobsapi
42+
43+
steps:
44+
- uses: actions/checkout@v5
45+
with:
46+
fetch-depth: 0
47+
48+
- name: Python Semantic Release
49+
id: release
50+
uses: python-semantic-release/python-semantic-release@v10
51+
with:
52+
github_token: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Publish pkg to GitHub Releases
55+
uses: python-semantic-release/publish-action@v10
56+
if: steps.release.outputs.released == 'true'
57+
with:
58+
github_token: ${{ secrets.GITHUB_TOKEN }}
59+
60+
- name: Publish pkg to PyPI
61+
uses: pypa/gh-action-pypi-publish@release/v1
62+
if: steps.release.outputs.released == 'true'
63+
with:
64+
packages-dir: dist
65+
skip-existing: true

.pre-commit-config.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ repos:
2222
- id: forbid-bidi-controls
2323

2424
- repo: https://github.com/astral-sh/ruff-pre-commit
25-
rev: v0.12.11
25+
rev: v0.13.1
2626
hooks:
27-
- id: ruff
27+
- id: ruff-check
28+
name: ruff-check (local)
29+
stages: [pre-commit, pre-push]
30+
- id: ruff-check
31+
name: ruff-check (ci)
32+
stages: [manual]
33+
args: [--output-format=github]
2834
- id: ruff-format

pyproject.toml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "python-usajobsapi"
7-
version = "0.1.0"
87
description = "A Python wrapper for the USA Jobs REST API."
98
readme = "README.md"
109
requires-python = ">=3.11"
@@ -13,7 +12,13 @@ dependencies = [
1312
"pydantic>=2.11.7",
1413
"requests>=2.32.5",
1514
]
15+
dynamic = ["version"]
1616

17+
[project.optional-dependencies]
18+
build = ["uv ~= 0.8.17"]
19+
20+
[tool.hatch.version]
21+
path = "usajobsapi/_version.py"
1722
[tool.hatch.build.targets.wheel]
1823
packages = ["usajobsapi"]
1924

@@ -24,9 +29,20 @@ dev = [
2429
"ruff>=0.12.11",
2530
]
2631

32+
[tool.semantic_release]
33+
branch = "main"
34+
build_command = """
35+
python -m pip install -e '.[build]'
36+
uv lock --upgrade-package "$PACKAGE_NAME"
37+
git add uv.lock
38+
uv build
39+
"""
40+
version_variables = ["usajobsapi/_version.py:__version__"]
41+
commit_message = "chore: release v{version}"
42+
2743
[tool.ruff]
2844
line-length = 88
29-
target-version = "py39"
45+
target-version = "py311"
3046

3147
[tool.pytest.ini_options]
3248
addopts = "-q"

usajobsapi/_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
__license__ = "GPL3"
22
__title__ = "python-usajobsapi"
3+
__version__ = "0.0.0"

uv.lock

Lines changed: 33 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)