This repository was archived by the owner on Jan 31, 2026. It is now read-only.
Build and Publish to PyPI #28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Publish to PyPI | |
| on: | |
| push: | |
| branches: [ master ] | |
| pull_request: | |
| branches: [ master ] | |
| release: | |
| types: [ published ] | |
| schedule: | |
| # Run weekly on Monday at 00:00 UTC to catch dependency updates | |
| - cron: '0 0 * * 1' | |
| workflow_dispatch: | |
| inputs: | |
| publish: | |
| description: 'Publish to PyPI (yes/no)' | |
| required: true | |
| default: 'yes' | |
| jobs: | |
| build_wheels: | |
| name: Build universal Python wheel | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install protobuf compiler | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y wget unzip | |
| wget https://github.com/protocolbuffers/protobuf/releases/download/v29.3/protoc-29.3-linux-x86_64.zip | |
| sudo unzip protoc-29.3-linux-x86_64.zip -d /usr/local | |
| protoc --version | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip setuptools wheel | |
| pip install numpy 'protobuf>=5.29.3,<6.0.0' pandas sprocket-boxcars-py openpyxl | |
| - name: Generate protobuf files | |
| run: | | |
| python utils/create_proto.py | |
| python utils/import_fixer.py | |
| - name: Build wheel | |
| run: python -m pip wheel -w wheelhouse --no-deps . | |
| - name: Test wheel installation | |
| run: | | |
| pip install wheelhouse/*.whl | |
| python -c "import carball; print('Import successful')" | |
| - name: Upload wheels as artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels | |
| path: ./wheelhouse/*.whl | |
| retention-days: 7 | |
| build_sdist: | |
| name: Build source distribution | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install protobuf compiler | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y wget unzip | |
| wget https://github.com/protocolbuffers/protobuf/releases/download/v29.3/protoc-29.3-linux-x86_64.zip | |
| sudo unzip protoc-29.3-linux-x86_64.zip -d /usr/local | |
| protoc --version | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip setuptools wheel | |
| pip install numpy 'protobuf>=5.29.3,<6.0.0' pandas sprocket-boxcars-py openpyxl | |
| - name: Generate protobuf files | |
| run: | | |
| python utils/create_proto.py | |
| python utils/import_fixer.py | |
| - name: Build sdist | |
| run: python setup.py sdist | |
| - name: Upload sdist as artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: sdist | |
| path: dist/*.tar.gz | |
| retention-days: 7 | |
| publish: | |
| name: Publish to PyPI | |
| needs: [build_wheels, build_sdist] | |
| runs-on: ubuntu-latest | |
| # Only publish on releases or manual workflow dispatch with 'yes' | |
| if: | | |
| github.event_name == 'release' || | |
| (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'yes') | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/sprocket-carball | |
| permissions: | |
| id-token: write # Required for trusted publishing | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| merge-multiple: true | |
| - name: List distributions | |
| run: ls -lh dist/ | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| skip-existing: true | |
| verbose: true |