Commit f2d9a26c authored by Yamada Hiroyuki's avatar Yamada Hiroyuki
Browse files

Update Build System

- Use cibuildwheel instead of hatch
- Use PyPI trusted workflow
parent 9457b208
Loading
Loading
Loading
Loading
Loading
+18 −86
Original line number Diff line number Diff line
@@ -16,65 +16,25 @@ jobs:
        with:
          name: README
          path: README.md
  test:
    strategy:
      matrix:
        runs-on: [ubuntu-latest, macos-13, macos-14, windows-latest]
      fail-fast: false
    runs-on: ${{ matrix.runs-on }}
    steps:
      - uses: actions/checkout@v4
      - name: Install Hatch
        uses: pypa/hatch@install
      - name: Run Test
        run: |
          hatch run test:install
          hatch run test-38:install
          hatch run test:run-cov
          hatch run test-38:run-cov
          hatch run cov:combine
          echo '## Test Coverage on ${{ matrix.runs-on }}' >> $GITHUB_STEP_SUMMARY
          echo '```' >> $GITHUB_STEP_SUMMARY
          hatch -q run cov:report >> $GITHUB_STEP_SUMMARY
          echo '```' >> $GITHUB_STEP_SUMMARY
        shell: bash
  build_winmac:
  build_wheel:
    needs: readme
    strategy:
      matrix:
        runs-on: [macos-13, macos-14, windows-latest]
        runs-on: [macos-13, macos-14, windows-latest, ubuntu-latest]
      fail-fast: false
    runs-on: ${{ matrix.runs-on }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: |
            3.8
            3.9
            3.10
            3.11
            3.12
          cache: 'pip'
      - uses: actions/download-artifact@v4
        with:
          name: README
          path: README
      - run: mv README/README.md README.md
      - run: pip3.8 wheel . -w dist --no-deps
      - run: pip3.9 wheel . -w dist --no-deps
      - run: pip3.10 wheel . -w dist --no-deps
      - run: pip3.11 wheel . -w dist --no-deps
      - run: pip3.12 wheel . -w dist --no-deps
      - uses: actions/cibuildwheel@v2.22.0
      - uses: actions/upload-artifact@v4
        with:
          name: dist-${{ matrix.runs-on }}
          path: dist
      - name: Upload to PyPI
        run: |
          pip install twine
          python -m twine upload -u __token__ -p ${{ secrets.pypi_password }} --skip-existing dist/cpprb-*
        if: github.event_name == 'push' && startsWith(github.event.ref,'refs/tags/v')
          name: dist-${{ matrix.runs-on }}-${{ strategy.job-index }}
          path: ./wheelhouse/*.whl
  build_targz:
    needs: readme
    runs-on: ubuntu-latest
@@ -82,57 +42,29 @@ jobs:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.8'
          python-version: '3.9'
          cache: 'pip'
      - uses: actions/download-artifact@v4
        with:
          name: README
          path: README
      - run: mv README/README.md README.md
      - run: python setup.py build_ext sdist
      - run: python -m build --sdist
      - uses: actions/upload-artifact@v4
        with:
          name: dist-sdist
          path: dist
      - run: pip --disable-pip-version-check install twine
      - name: Upload to PyPI
        run: python -m twine upload -u __token__ -p ${{ secrets.pypi_password }} --skip-existing dist/cpprb-*tar.gz
        if: github.event_name == 'push' && startsWith(github.event.ref,'refs/tags/v')
  build_manylinux:
          path: dist/*.tar.gz
  upload:
    needs: [build_wheel, build_targz]
    environment: pypi
    runs-on: ubuntu-latest
    strategy:
      matrix:
        arch: ["x86_64", "aarch64"]
    permissions:
      id-token: write
    if: github.event_name == 'push' && startsWith(github.event.ref,'refs/tags/v')
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3'
          cache: 'pip'
      - uses: docker/setup-qemu-action@v3
        if: ${{ matrix.arch }} == "aarch64"
        with:
          platforms: arm64
      - uses: docker/setup-buildx-action@v3
      - uses: docker/build-push-action@v5
        with:
          push: false
          build-args: |
            ON_CI=1
            arch=${{ matrix.arch }}
          file: Dockerfile
          cache-to: type=gha,mode=max,scope=${{github.ref_name}}
          cache-from: type=gha,scope=${{github.ref_name}}
          load: true
          tags: cpprb/wheel:latest
      - run: |
          docker create --name wheel cpprb/wheel:latest
          docker cp wheel:/dist/. dist/
      - uses: actions/upload-artifact@v4
      - uses: actions/download-artifact@v4
        with:
          name: dist-manylinux-${{ matrix.arch }}
          pattern: 'dist-*'
          path: dist
      - run: pip --disable-pip-version-check install twine
      - name: Upload to PyPI
        run: python -m twine upload -u __token__ -p ${{ secrets.pypi_password }} --skip-existing dist/cpprb-*
        if: github.event_name == 'push' && startsWith(github.event.ref,'refs/tags/v')
          merge-multiple: true
      - uses: pypa/gh-action-pypi-publish@release/v1
+1 −0
Original line number Diff line number Diff line
.coverage*
build
dist
wheelhouse
*egg-info
*.so
*.c
+0 −13
Original line number Diff line number Diff line
@@ -20,19 +20,6 @@ RUN ON_CI=${ON_CI} /opt/python/cp38-cp38/bin/pip wheel . -w /work/wheel --no-dep
    auditwheel repair /work/wheel/cpprb-*.whl -w /dist


FROM python:latest AS test
WORKDIR /work
RUN --mount=type=cache,target=/root/.cache/pip \
    pip install hatch
COPY pyproject.tom setup.py LICENSE MANIFEST.in .
COPY src src/
RUN hatch env create test
COPY test test/
RUN hatch run test:run-cov && \
    hatch run cov:combine && \
    hatch run cov:report


FROM scratch AS results
COPY --from=manylinux /dist/cpprb-* /dist/
CMD [""]

deps.nix

deleted100644 → 0
+0 −36
Original line number Diff line number Diff line
with import <nixpkgs> {};
let
  hatch-config = ({
    x86_64-linux = {
      system = "x86_64-unknown-linux-gnu";
      sha256 = "0i7vf48350mcwz6vcd46awsblm36a6ih7vrfjadppij0a6047apd";
    };
    aarch64-linux = {
      system = "aarch64-unknown-linux-gnu";
      sha256 = "0lxnkjlfff81zv34d0l5cjybgyxa5lz0p8lm1gzl2mf8alwgbv7i";
    };
    x86_64-darwin = {
      system = "x86_64-apple-darwin";
      sha256 = "1nl036mqvbq38imna22ign2wb1b255qn3vsq3vr4n993fqq6jlhx";
    };
    aarch64-darwin = {
      system = "aarch64-apple-darwin";
      sha256 = "0y5hscgwfcrl2nk92mzbxqs882qmwz0hjlkay0hxav2yk1gs27mf";
    };
  })."${builtins.currentSystem}";
in {
  hatch = stdenv.mkDerivation {
    name = "hatch";
    src = (builtins.fetchurl {
      url = "https://github.com/pypa/hatch/releases/download/hatch-v1.13.0/hatch-${hatch-config.system}.tar.gz";
      sha256 = hatch-config.sha256;
    });
    phases = ["installPhase" "patchPhase"];
    installPhase = ''
      mkdir -p $out/bin
      tar -xzf $src -O > $out/bin/hatch
      chmod +x $out/bin/hatch
    '';
  };
  bash = bashInteractive;
}
+2 −2
Original line number Diff line number Diff line
#! /usr/bin/env nix
#! nix --extra-experimental-features ``flakes nix-command`` shell
#! nix --override-input nixpkgs ``github:NixOS/nixpkgs/release-23.11``
#! nix --impure --file deps.nix hatch bash
#! nix -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/branch-off-24.11.tar.gz
#! nix --impure nixpkgs#actionlint nixpkgs#uv
#! nix --command bash

echo 'Enter Dev Shell'
Loading