diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..74f5794 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +custom: https://xi-xu.me/#sponsorships diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac65f9e..5ba8bbc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,7 +85,7 @@ jobs: name: pypi url: https://pypi.org/p/tzst permissions: - id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write steps: - name: Download build artifacts @@ -96,3 +96,53 @@ jobs: - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + + update_badges: + needs: [build, publish] + if: always() && needs.build.result == 'success' + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} + + - name: Wait if this is after a publish + if: github.event_name == 'release' && github.event.action == 'published' + run: sleep 30 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Fetch PyPI version + id: pypi_version + run: | + pip install requests + python -c " + import requests, json + try: + data = requests.get('https://pypi.org/pypi/tzst/json').json() + version = data['info']['version'] + print(f'PyPI version: {version}') + except Exception as e: + print(f'Error fetching version: {e}') + version = 'unknown' + print(f'::set-output name=version::{version}') + " + + - name: Update README badge + run: | + echo "Updating PyPI badge with version: ${{ steps.pypi_version.outputs.version }}" + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + - name: Commit and push changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "Update badges [skip ci]" + file_pattern: README.md + branch: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} diff --git a/README.md b/README.md index 7bd18a3..9a4cb3b 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ A Python library for creating and manipulating `.tzst`/`.tar.zst` archives using Zstandard compression. -[![CI/CD](https://github.com/xixu-me/tzst/workflows/CI/CD/badge.svg)](https://github.com/xixu-me/tzst/actions) -[![PyPI version](https://badge.fury.io/py/tzst.svg)](https://badge.fury.io/py/tzst) -[![Python versions](https://img.shields.io/pypi/pyversions/tzst.svg)](https://pypi.org/project/tzst/) -[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) +[![CI/CD](https://github.com/xixu-me/tzst/actions/workflows/ci.yml/badge.svg)](https://github.com/xixu-me/tzst/actions/workflows/ci.yml) +[![PyPI - Version](https://img.shields.io/pypi/v/tzst)](https://pypi.org/project/tzst/) +[![GitHub License](https://img.shields.io/github/license/xixu-me/tzst)](LICENSE) +[![Sponsor](https://img.shields.io/badge/Sponsor-violet)](https://xi-xu.me/#sponsorships) ## Features @@ -30,7 +30,7 @@ pip install tzst ```bash git clone https://github.com/xixu-me/tzst.git cd tzst -pip install -e . +pip install . ``` ### Development Installation diff --git a/src/tzst/cli.py b/src/tzst/cli.py index 20eeb22..f140520 100644 --- a/src/tzst/cli.py +++ b/src/tzst/cli.py @@ -10,6 +10,12 @@ from .core import create_archive, extract_archive, list_archive, test_archive from .exceptions import TzstArchiveError, TzstDecompressionError +def print_banner() -> None: + """Print the version and copyright banner.""" + print() + print(f"tzst {__version__} : Copyright (c) 2025 Xi Xu") + + def format_size(size: int) -> str: """Format file size in human-readable format.""" size_float = float(size) @@ -240,7 +246,7 @@ Command Reference: parser.add_argument( "--version", action="version", - version=f"tzst {__version__} : Copyright (c) 2025 Xi Xu", + version=f"tzst {__version__}", ) subparsers = parser.add_subparsers( @@ -313,6 +319,9 @@ Command Reference: def main(argv: Optional[List[str]] = None) -> int: """Main entry point for the CLI.""" + print_banner() + print() + parser = create_parser() args = parser.parse_args(argv)