Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 12 additions & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,20 @@ name: CI
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12", "3.13"]

steps:
- uses: actions/checkout@v6

- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: uv sync --all-extras

- name: Lint with ruff
run: |
uv run ruff check src tests
uv run ruff format --check src tests
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

- name: Run tests
run: uv run pytest
permissions:
contents: read

publish:
needs: test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
environment: pypi

permissions:
id-token: write

steps:
- uses: actions/checkout@v6

- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Build package
run: uv build

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
jobs:
test:
uses: ./.github/workflows/test.yml
with:
coverage: true
secrets:
codecov_token: ${{ secrets.CODECOV_TOKEN }}
96 changes: 96 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Release

on:
push:
tags:
- "v*"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

permissions:
contents: read

jobs:
test:
uses: ./.github/workflows/test.yml

build:
needs: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6

- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true

- name: Set up Python
run: uv python install 3.12

- name: Verify version consistency
run: |
uv run python - <<'PY'
import os
import tomllib

with open("pyproject.toml", "rb") as f:
pyproject_version = tomllib.load(f)["project"]["version"]

with open("uv.lock", "rb") as f:
lock = tomllib.load(f)
lock_version = next(
package["version"]
for package in lock["package"]
if package["name"] == "ytstudio-cli"
)

tag = os.environ["GITHUB_REF"]
expected_tag = f"refs/tags/v{pyproject_version}"
if lock_version != pyproject_version:
raise SystemExit(
f"uv.lock version {lock_version} does not match "
f"pyproject.toml version {pyproject_version}"
)
if tag != expected_tag:
raise SystemExit(f"tag {tag} does not match package version {expected_tag}")
PY

- name: Build package
run: uv build

- name: Smoke test wheel
run: |
uv venv /tmp/ytstudio-smoke
uv pip install --python /tmp/ytstudio-smoke/bin/python dist/*.whl
/tmp/ytstudio-smoke/bin/ytstudio --version
/tmp/ytstudio-smoke/bin/yts --version
/tmp/ytstudio-smoke/bin/ytstudio --help
/tmp/ytstudio-smoke/bin/ytstudio videos --help

- name: Upload dist artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/

publish:
needs: build
runs-on: ubuntu-latest
environment: pypi

permissions:
id-token: write

steps:
- name: Download dist artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
76 changes: 76 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Test

on:
workflow_call:
inputs:
coverage:
description: "Report and upload coverage (3.12 only)"
type: boolean
default: false
secrets:
codecov_token:
required: false

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12", "3.13"]

steps:
- uses: actions/checkout@v6

- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: uv sync --locked --group dev

- name: Lint with ruff
run: |
uv run ruff check src tests scripts
uv run ruff format --check src tests scripts

- name: Run tests
run: uv run pytest

- name: Write coverage summary
if: inputs.coverage && matrix.python-version == '3.12'
run: |
{
echo "## Coverage"
echo
echo '```text'
uv run coverage report
echo '```'
} >> "$GITHUB_STEP_SUMMARY"

- name: Generate HTML coverage report
if: inputs.coverage && matrix.python-version == '3.12'
run: uv run coverage html

- name: Upload coverage artifacts
if: inputs.coverage && matrix.python-version == '3.12'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
coverage.xml
htmlcov/

- name: Upload coverage to Codecov
if: inputs.coverage && matrix.python-version == '3.12'
uses: codecov/codecov-action@v5
with:
files: coverage.xml
fail_ci_if_error: false
token: ${{ secrets.codecov_token }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<p align="center">
<a href="https://github.com/jdwit/ytstudio-cli/actions/workflows/ci.yml"><img src="https://github.com/jdwit/ytstudio-cli/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
<a href="https://codecov.io/gh/jdwit/ytstudio-cli"><img src="https://codecov.io/gh/jdwit/ytstudio-cli/branch/main/graph/badge.svg" alt="Coverage"></a>
<a href="https://pypi.org/project/ytstudio-cli/"><img src="https://img.shields.io/pypi/v/ytstudio-cli" alt="PyPI"></a>
<a href="https://pypi.org/project/ytstudio-cli/"><img src="https://img.shields.io/pypi/pyversions/ytstudio-cli" alt="Python"></a>
</p>
Expand Down
Loading
Loading