Skip to content

Commit 6ab0e25

Browse files
committed
Added workflow for release and build workflow now uses uv.
1 parent a3a5d27 commit 6ab0e25

File tree

3 files changed

+129
-14
lines changed

3 files changed

+129
-14
lines changed

.github/workflows/build.yml

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,45 @@ on:
77
pull_request:
88
branches:
99
- master
10-
1110
env:
1211
MAIN_PYTHON_VERSION: "3.12"
1312

13+
concurrency:
14+
# Cancel previous workflow run when a new commit is pushed to a feature branch
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
17+
1418
jobs:
19+
changed-files:
20+
runs-on: ubuntu-latest
21+
name: Get changed files
22+
outputs:
23+
any_python_changed: ${{ steps.raw-changed-python-files.outputs.any_changed }}
24+
changed_python_files: ${{ steps.changed-python-files.outputs.all_changed_files }}
25+
steps:
26+
- uses: actions/checkout@v5
27+
28+
- name: Get changed python files
29+
id: raw-changed-python-files
30+
uses: tj-actions/changed-files@v46
31+
with:
32+
files: |
33+
**.py
34+
uv.lock
35+
36+
- name: Check changed python files
37+
id: changed-python-files
38+
env:
39+
CHANGED_PYTHON_FILES: ${{ steps.raw-changed-python-files.outputs.all_changed_files }}
40+
run: |
41+
if [[ " $CHANGED_PYTHON_FILES " == *" uv.lock "* ]]; then
42+
# if uv.lock is changed, we need to check everything
43+
CHANGED_PYTHON_FILES="."
44+
fi
45+
echo "all_changed_files=$CHANGED_PYTHON_FILES" >> "$GITHUB_OUTPUT"
46+
1547
test:
48+
if: needs.changed-files.outputs.any_python_changed == 'true'
1649
name: "${{ matrix.os }}: ${{ matrix.python-version }}"
1750
runs-on: ${{ matrix.os }}
1851
strategy:
@@ -23,34 +56,42 @@ jobs:
2356

2457
steps:
2558
- uses: actions/checkout@v5
26-
- name: Set up Python ${{ matrix.python-version }}
27-
uses: actions/setup-python@v5
59+
- name: Install uv and set the Python version
60+
uses: astral-sh/setup-uv@v6
2861
with:
2962
python-version: ${{ matrix.python-version }}
63+
enable-cache: true
3064
- name: Install dependencies
3165
run: |
32-
python -m pip install --upgrade pip
33-
pip install .[dev]
34-
35-
- name: Run tests
66+
uv sync --frozen --all-extras --dev
67+
- name: Run tests with coverage
3668
run: |
37-
pytest -v
69+
uv run poe test-with-coverage -v
70+
- name: Upload coverage reports
71+
if: matrix.os == 'ubuntu-24.04' && matrix.python-version == env.MAIN_PYTHON_VERSION
72+
uses: actions/upload-artifact@v4
73+
with:
74+
name: coverage-${{ github.run_id }}
75+
path: reports
76+
retention-days: 30
77+
3878
style:
3979
name: Style
80+
if: needs.changed-files.outputs.any_python_changed == 'true'
4081
runs-on: ubuntu-latest
4182
steps:
4283
- uses: actions/checkout@v5
43-
- name: Set up Python ${{ env.MAIN_PYTHON_VERSION }}
44-
uses: actions/setup-python@v5
84+
- name: Install uv and set the Python version
85+
uses: astral-sh/setup-uv@v6
4586
with:
4687
python-version: ${{ env.MAIN_PYTHON_VERSION }}
88+
enable-cache: true
4789
- name: Install dependencies
4890
run: |
49-
python -m pip install --upgrade pip
50-
pip install .[dev]
91+
uv sync --frozen --group dev
5192
- name: Check style with Ruff
5293
run: |
53-
ruff check --output-format=github .
94+
uv run ruff check --output-format=github ${{ needs.changed-files.outputs.changed_python_files }}
5495
- name: Check format with Ruff
5596
run: |
56-
ruff format --check .
97+
uv run ruff format --check ${{ needs.changed-files.outputs.changed_python_files }}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Publish Python Package
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version of the new release, just as a number with no prepended "v"'
8+
required: true
9+
10+
env:
11+
PYTHON_VERSION: "3.12"
12+
NEW_VERSION: ${{ inputs.version }}
13+
NEW_TAG: v${{ inputs.version }}
14+
15+
jobs:
16+
increment-version:
17+
name: Bump version, commit and create tag
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v5
21+
- name: Install uv and set the Python version
22+
uses: astral-sh/setup-uv@v6
23+
with:
24+
python-version: ${{ env.PYTHON_VERSION }}
25+
enable-cache: true
26+
- name: Bump project version
27+
run: uv version "${{ env.NEW_VERSION }}"
28+
29+
- uses: EndBug/add-and-commit@v9
30+
id: commit_and_tag
31+
name: Commit the changes and create tag
32+
with:
33+
message: "Increment version to ${{ env.NEW_VERSION }}"
34+
tag: "${{ env.NEW_TAG }} --force"
35+
36+
build:
37+
name: Build the distribution package
38+
runs-on: ubuntu-latest
39+
needs: increment-version
40+
steps:
41+
- uses: actions/checkout@v5
42+
- name: Install uv and set the Python version
43+
uses: astral-sh/setup-uv@v6
44+
with:
45+
python-version: ${{ env.PYTHON_VERSION }}
46+
enable-cache: true
47+
48+
- name: Build a binary wheel and a source tarball
49+
run: uv build
50+
51+
- name: Store the package
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: python-package-distributions
55+
path: dist/
56+
57+
publish-to-pypi:
58+
name: Publish distribution 📦 to PyPI
59+
runs-on: ubuntu-latest
60+
needs: build
61+
environment:
62+
name: pypi
63+
url: https://pypi.org/p/mediafile
64+
permissions:
65+
id-token: write
66+
steps:
67+
- name: Download all the dists
68+
uses: actions/download-artifact@v5
69+
with:
70+
name: python-package-distributions
71+
path: dist/
72+
- name: Publish
73+
run: uv publish

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Upcoming
1010
the codebase with ``ruff``.
1111
- Moved changelog into its own file, ``changelog.rst``. Also added github workflow
1212
for automatic changelog reminders.
13+
- The project now uses ``uv`` for dependency management.
1314

1415
v0.13.0
1516
'''''''

0 commit comments

Comments
 (0)