Skip to content

code update

code update #4

Workflow file for this run

# CI/CD workflow for vjson
# - Runs tests and linting on PRs and pushes
# - Builds wheels for all platforms
# - Auto-tags and publishes to PyPI on main branch
name: CI
on:
push:
branches:
- main
- master
- develop
tags:
- "*"
pull_request:
branches:
- main
- master
- develop
workflow_dispatch:
permissions:
contents: write
id-token: write
env:
CARGO_TERM_COLOR: always
PYTHON_VERSION: "3.12"
jobs:
# ============================================================
# Test & Lint
# ============================================================
test:
name: Test & Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Check formatting
run: cargo fmt -- --check
- name: Run clippy
run: cargo clippy --all-features -- -D warnings
- name: Run Rust tests
run: cargo test --all-features
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
pip install maturin pytest numpy
- name: Build and install
run: maturin develop
- name: Run Python tests
run: pytest tests/ -v --ignore=tests/test_simple.py || true
# ============================================================
# Build wheels for Linux (manylinux)
# ============================================================
linux:
name: Linux - ${{ matrix.target }}
needs: [test]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- x86_64
- aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.target }}
path: dist/*.whl
if-no-files-found: error
# ============================================================
# Build wheels for Linux (musllinux)
# ============================================================
musllinux:
name: Musllinux - ${{ matrix.target }}
needs: [test]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- x86_64
- aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-musllinux-${{ matrix.target }}
path: dist/*.whl
if-no-files-found: error
# ============================================================
# Build wheels for Windows
# ============================================================
windows:
name: Windows - ${{ matrix.target }}
needs: [test]
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
target:
- x64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: ${{ matrix.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.target }}
path: dist/*.whl
if-no-files-found: error
# ============================================================
# Build wheels for macOS
# ============================================================
macos:
name: macOS - ${{ matrix.target }}
needs: [test]
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- runner: macos-13
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.target }}
path: dist/*.whl
if-no-files-found: error
# ============================================================
# Build source distribution
# ============================================================
sdist:
name: Source Distribution
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist/*.tar.gz
if-no-files-found: error
# ============================================================
# Auto-tag and create release on main branch
# ============================================================
auto_release:
name: Auto Tag & Release
needs: [linux, musllinux, windows, macos, sdist]
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
outputs:
version: ${{ steps.get_version.outputs.version }}
tag: ${{ steps.get_version.outputs.tag }}
should_release: ${{ steps.check_tag.outputs.should_release }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version from Cargo.toml
id: get_version
run: |
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
echo "Detected version: $VERSION"
- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "v${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then
echo "Tag v${{ steps.get_version.outputs.version }} already exists"
echo "should_release=false" >> $GITHUB_OUTPUT
else
echo "Tag v${{ steps.get_version.outputs.version }} does not exist, will create"
echo "should_release=true" >> $GITHUB_OUTPUT
fi
- name: Create and push tag
if: steps.check_tag.outputs.should_release == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v${{ steps.get_version.outputs.version }}" -m "Release v${{ steps.get_version.outputs.version }}"
git push origin "v${{ steps.get_version.outputs.version }}"
- name: Download all wheels
if: steps.check_tag.outputs.should_release == 'true'
uses: actions/download-artifact@v4
with:
path: dist/
pattern: wheels-*
merge-multiple: true
- name: List artifacts
if: steps.check_tag.outputs.should_release == 'true'
run: ls -lhR dist/
- name: Create GitHub Release
if: steps.check_tag.outputs.should_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.get_version.outputs.version }}
name: Release v${{ steps.get_version.outputs.version }}
files: dist/*
generate_release_notes: true
draft: false
prerelease: false
# ============================================================
# Publish to PyPI
# ============================================================
publish:
name: Publish to PyPI
needs: [auto_release]
runs-on: ubuntu-latest
if: needs.auto_release.outputs.should_release == 'true'
environment:
name: pypi
url: https://pypi.org/p/vjson
permissions:
id-token: write
steps:
- name: Download all wheels
uses: actions/download-artifact@v4
with:
path: dist/
pattern: wheels-*
merge-multiple: true
- name: List packages
run: ls -lhR dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
skip-existing: true
verbose: true
# ============================================================
# Publish on tag push (manual release)
# ============================================================
publish_on_tag:
name: Publish (Tag)
needs: [linux, musllinux, windows, macos, sdist]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
environment:
name: pypi
url: https://pypi.org/p/vjson
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
- name: Download all wheels
uses: actions/download-artifact@v4
with:
path: dist/
pattern: wheels-*
merge-multiple: true
- name: List packages
run: ls -lhR dist/
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-path: "dist/*"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: dist/*
generate_release_notes: true
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
skip-existing: true
verbose: true