Publish Python and Rust Packages #9
This file contains 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: Publish Python and Rust Packages | |
on: | |
release: | |
types: [created] | |
workflow_dispatch: | |
permissions: | |
contents: read | |
id-token: write | |
concurrency: | |
group: "publish" | |
cancel-in-progress: true | |
jobs: | |
publish-python: | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest] | |
timeout-minutes: 10 | |
name: Build and publish Python package (${{ matrix.os }}) | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Set up Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install cibuildwheel | |
if [ "$RUNNER_OS" == "Linux" ]; then | |
sudo apt-get update | |
sudo apt-get install -y unzip | |
PROTOC_ZIP=protoc-23.4-linux-x86_64.zip | |
elif [ "$RUNNER_OS" == "macOS" ]; then | |
brew install unzip | |
PROTOC_ZIP=protoc-23.4-osx-x86_64.zip | |
fi | |
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v23.4/$PROTOC_ZIP | |
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc | |
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*' | |
rm -f $PROTOC_ZIP | |
shell: bash | |
- name: Build package | |
env: | |
CIBW_SKIP: "pp* *-musllinux*" # Skip PyPy and musllinux builds | |
CIBW_BEFORE_BUILD: | | |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | |
source $HOME/.cargo/env | |
pip install setuptools-rust | |
if command -v apt-get &> /dev/null; then | |
apt-get update && apt-get install -y protobuf-compiler | |
elif command -v brew &> /dev/null; then | |
brew install protobuf | |
fi | |
cargo build --bin stub_gen | |
CIBW_ENVIRONMENT: | | |
PATH="$HOME/.cargo/bin:$PATH" | |
CARGO_NET_GIT_FETCH_WITH_CLI=true | |
run: python -m cibuildwheel --output-dir dist | |
- name: Upload wheel artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: wheels-${{ matrix.os }} | |
path: dist/*.whl | |
publish-wheels: | |
needs: publish-python | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download all wheels | |
uses: actions/download-artifact@v3 | |
with: | |
path: dist | |
- name: Move wheels to dist directory | |
run: | | |
mkdir -p final_dist | |
find dist -name "*.whl" -exec mv {} final_dist/ \; | |
- name: Publish package | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
packages-dir: final_dist/ | |
publish-rust: | |
timeout-minutes: 10 | |
name: Build and publish Rust package | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y software-properties-common | |
sudo add-apt-repository -y ppa:maarten-fonville/protobuf | |
sudo apt-get update | |
sudo apt-get install -y libudev-dev pkg-config protobuf-compiler | |
- name: Cache Cargo registry | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cargo/registry | |
key: ${{ runner.os }}-cargo-registry | |
restore-keys: | | |
${{ runner.os }}-cargo-registry | |
- name: Cache Cargo index | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cargo/git | |
key: ${{ runner.os }}-cargo-index | |
restore-keys: | | |
${{ runner.os }}-cargo-index | |
- name: Publish Robstride package to crates.io | |
env: | |
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
run: | | |
cd klang/ | |
cargo publish |