diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d9e4c2d..4347e20 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,45 +1,69 @@ -name: Python +name: Release on: push: - pull_request: + tags: + - 'v*' + workflow_dispatch: + inputs: + draft_version: + description: '草稿版本号 (Draft version tag, e.g., v0.1.0-beta1)' + required: false + default: '' + type: string env: - PYTHON_VERSION: "3.9" + PYTHON_VERSION: '3.12' jobs: + sdist: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-python@v6 + with: + python-version: ${{ env.PYTHON_VERSION }} + - 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 + overwrite: true + macos: runs-on: macos-latest + strategy: + matrix: + target: [x86_64, universal2-apple-darwin] steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v5 + - uses: actions/setup-python@v6 with: python-version: ${{ env.PYTHON_VERSION }} architecture: x64 - uses: dtolnay/rust-toolchain@stable - - name: Build wheels - x86_64 - uses: PyO3/maturin-action@v1 - with: - target: x86_64 - args: --release --out dist --sdist - - name: Install built wheel - x86_64 - run: | - pip install aliyun-log-fastpb --no-index --find-links dist --force-reinstall - python -c "import aliyun_log_fastpb" - - name: Build wheels - universal2 + - name: Build wheels uses: PyO3/maturin-action@v1 with: - target: universal2-apple-darwin + target: ${{ matrix.target }} args: --release --out dist - - name: Install built wheel - universal2 + - name: Install built wheel + # 只在 universal2 上测试,x86_64 只构建不测试 + if: matrix.target == 'universal2-apple-darwin' run: | - pip install aliyun-log-fastpb --no-index --find-links dist --force-reinstall + pip install dist/aliyun_log_fastpb-*.whl --force-reinstall python -c "import aliyun_log_fastpb" - name: Upload wheels - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: wheels + name: wheels-macos-${{ matrix.target }} path: dist + overwrite: true windows: runs-on: windows-latest @@ -47,8 +71,8 @@ jobs: matrix: target: [x64, x86] steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v5 + - uses: actions/setup-python@v6 with: python-version: ${{ env.PYTHON_VERSION }} architecture: ${{ matrix.target }} @@ -59,14 +83,16 @@ jobs: target: ${{ matrix.target }} args: --release --out dist - name: Install built wheel + shell: bash run: | - pip install aliyun-log-fastpb --no-index --find-links dist --force-reinstall + pip install dist/aliyun_log_fastpb-*.whl --force-reinstall python -c "import aliyun_log_fastpb" - name: Upload wheels - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: wheels + name: wheels-windows-${{ matrix.target }} path: dist + overwrite: true linux: runs-on: ubuntu-latest @@ -74,27 +100,28 @@ jobs: matrix: target: [x86_64, i686] steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - with: - python-version: ${{ env.PYTHON_VERSION }} - architecture: x64 - - name: Build wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.target }} - manylinux: auto - args: --release --out dist - - name: Install built wheel - if: matrix.target == 'x86_64' - run: | - pip install aliyun-log-fastpb --no-index --find-links dist --force-reinstall - python -c "import aliyun_log_fastpb" - - name: Upload wheels - uses: actions/upload-artifact@v3 - with: - name: wheels - path: dist + - uses: actions/checkout@v5 + - uses: actions/setup-python@v6 + with: + python-version: ${{ env.PYTHON_VERSION }} + architecture: x64 + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.target }} + manylinux: auto + args: --release --out dist + - name: Install built wheel + if: matrix.target == 'x86_64' + run: | + pip install dist/aliyun_log_fastpb-*.whl --force-reinstall + python -c "import aliyun_log_fastpb" + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-linux-${{ matrix.target }} + path: dist + overwrite: true linux-cross: runs-on: ubuntu-latest @@ -102,35 +129,36 @@ jobs: matrix: target: [aarch64, armv7, s390x, ppc64le, ppc64] steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - with: - python-version: ${{ env.PYTHON_VERSION }} - - name: Build wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.target }} - manylinux: auto - args: --release --out dist - - uses: uraimo/run-on-arch-action@v3.0.1 - if: matrix.target != 'ppc64' - name: Install built wheel - with: - arch: ${{ matrix.target }} - distro: ubuntu20.04 - githubToken: ${{ github.token }} - install: | - apt-get update - apt-get install -y --no-install-recommends python3 python3-pip - pip3 install -U pip - run: | - pip3 install aliyun-log-fastpb --no-index --find-links dist/ --force-reinstall - python3 -c "import aliyun_log_fastpb" - - name: Upload wheels - uses: actions/upload-artifact@v3 - with: - name: wheels - path: dist + - uses: actions/checkout@v5 + - uses: actions/setup-python@v6 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.target }} + manylinux: auto + args: --release --out dist + - uses: uraimo/run-on-arch-action@v3.0.1 + if: matrix.target != 'ppc64' + name: Install built wheel + with: + arch: ${{ matrix.target }} + distro: ubuntu20.04 + # githubToken: ${{ github.token }} + install: | + apt-get update + apt-get install -y --no-install-recommends python3 python3-pip + pip3 install -U pip + run: | + pip3 install dist/aliyun_log_fastpb-*.whl --force-reinstall + python3 -c "import aliyun_log_fastpb" + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-linux-cross-${{ matrix.target }} + path: dist + overwrite: true musllinux: runs-on: ubuntu-latest @@ -140,33 +168,34 @@ jobs: - x86_64-unknown-linux-musl - i686-unknown-linux-musl steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - with: - python-version: ${{ env.PYTHON_VERSION }} - architecture: x64 - - name: Build wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.target }} - manylinux: musllinux_1_2 - args: --release --out dist - - name: Install built wheel - if: matrix.target == 'x86_64-unknown-linux-musl' - uses: addnab/docker-run-action@v3 - with: - image: alpine:latest - options: -v ${{ github.workspace }}:/io -w /io - run: | - apk add py3-pip - pip3 install -U pip - pip3 install aliyun-log-fastpb --no-index --find-links /io/dist/ --force-reinstall - python3 -c "import aliyun_log_fastpb" - - name: Upload wheels - uses: actions/upload-artifact@v3 - with: - name: wheels - path: dist + - uses: actions/checkout@v5 + - uses: actions/setup-python@v6 + with: + python-version: ${{ env.PYTHON_VERSION }} + architecture: x64 + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.target }} + manylinux: musllinux_1_2 + args: --release --out dist + - name: Install built wheel + if: matrix.target == 'x86_64-unknown-linux-musl' + uses: addnab/docker-run-action@v3 + with: + image: alpine:latest + options: -v ${{ github.workspace }}:/io -w /io + run: | + apk add py3-pip + pip3 install -U pip --break-system-packages + pip3 install dist/aliyun_log_fastpb-*.whl --force-reinstall --break-system-packages + python3 -c "import aliyun_log_fastpb" + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-musllinux-${{ matrix.target }} + path: dist + overwrite: true musllinux-cross: runs-on: ubuntu-latest @@ -178,50 +207,82 @@ jobs: - target: armv7-unknown-linux-musleabihf arch: armv7 steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - with: - python-version: ${{ env.PYTHON_VERSION }} - - name: Build wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.platform.target }} - manylinux: musllinux_1_2 - args: --release --out dist - - uses: uraimo/run-on-arch-action@v3.0.1 - name: Install built wheel - with: - arch: ${{ matrix.platform.arch }} - distro: alpine_latest - githubToken: ${{ github.token }} - install: | - apk add py3-pip - pip3 install -U pip + - uses: actions/checkout@v5 + - uses: actions/setup-python@v6 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + manylinux: musllinux_1_2 + args: --release --out dist + - uses: uraimo/run-on-arch-action@v3.0.1 + name: Install built wheel + with: + arch: ${{ matrix.platform.arch }} + distro: alpine_latest + githubToken: ${{ github.token }} + install: | + apk add py3-pip + pip3 install -U pip --break-system-packages + run: | + pip3 install dist/aliyun_log_fastpb-*.whl --force-reinstall --break-system-packages + python3 -c "import aliyun_log_fastpb" + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-musllinux-cross-${{ matrix.platform.arch }} + path: dist + overwrite: true + + pre-release: + name: Pre-Release Check + runs-on: ubuntu-latest + needs: + [sdist, macos, windows, linux, linux-cross, musllinux, musllinux-cross] + steps: + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + pattern: wheels-* + path: dist + merge-multiple: true + - name: List all artifacts run: | - pip3 install aliyun-log-fastpb --no-index --find-links dist/ --force-reinstall - python3 -c "import aliyun_log_fastpb" - - name: Upload wheels - uses: actions/upload-artifact@v3 - with: - name: wheels - path: dist + echo "=== All build artifacts ===" + ls -lh dist/ + echo "" + echo "=== Total files: $(ls -1 dist/ | wc -l) ===" release: name: Release runs-on: ubuntu-latest - if: "startsWith(github.ref, 'refs/tags/')" - needs: [ macos, windows, linux, linux-cross, musllinux, musllinux-cross ] + if: startsWith(github.ref, 'refs/tags/') || github.event.inputs.draft_version != '' + needs: [pre-release] steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: - name: wheels - - uses: actions/setup-python@v4 + pattern: wheels-* + path: dist + merge-multiple: true + - uses: actions/setup-python@v6 with: python-version: ${{ env.PYTHON_VERSION }} + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + files: dist/* + tag_name: ${{ github.event.inputs.draft_version != '' && github.event.inputs.draft_version || github.ref_name }} + draft: ${{ github.event.inputs.draft_version != '' }} + prerelease: false + generate_release_notes: true + fail_on_unmatched_files: true - name: Publish to PyPI + if: github.event.inputs.draft_version == '' && startsWith(github.ref, 'refs/tags/') env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | pip install --upgrade twine - twine upload --skip-existing * \ No newline at end of file + twine upload --skip-existing dist/* diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..395164d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,53 @@ +name: Tests + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +env: + PYTHON_VERSION: '3.12' + CARGO_TERM_COLOR: always + +jobs: + test: + name: Run Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: 'pip' + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + python -m venv .venv + source .venv/bin/activate + pip install -r requirements-dev.txt + + - name: Run Cargo tests + run: cargo test --verbose + + - name: Build Python extension + run: | + source .venv/bin/activate + pip install maturin + maturin develop + + - name: Run pytest + run: | + source .venv/bin/activate + pytest -v tests/ + diff --git a/README.md b/README.md index 6692e27..f497787 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [中文文档](README_CN.md) | English +[![Test](https://github.com/aliyun/aliyun-log-python-fastpb/actions/workflows/test.yml/badge.svg)](https://github.com/aliyun/aliyun-log-python-fastpb/actions/workflows/test.yml) + Fast protobuf serialization for Aliyun Log using PyO3 and quick-protobuf. ## Installation diff --git a/README_CN.md b/README_CN.md index 1146982..e35cda6 100644 --- a/README_CN.md +++ b/README_CN.md @@ -1,5 +1,7 @@ # aliyun-log-fastpb +[![Test](https://github.com/aliyun/aliyun-log-python-fastpb/actions/workflows/test.yml/badge.svg)](https://github.com/aliyun/aliyun-log-python-fastpb/actions/workflows/test.yml) + [English](README.md) | 中文文档 基于 PyO3 和 quick-protobuf 的阿里云日志高性能 protobuf 序列化库。