build-commit #118
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: build-commit | |
on: | |
workflow_dispatch: | |
inputs: | |
arch: | |
type: choice | |
options: | |
- x86 | |
- arm | |
description: The machine architecture to build for | |
required: true | |
default: x86 | |
python_version: | |
type: string | |
description: The version of python to use | |
required: false | |
default: "3.9" | |
jobs: | |
build-commit: | |
runs-on: ${{ inputs.arch == 'x86' && 'buildjet-8vcpu-ubuntu-2004' || 'buildjet-8vcpu-ubuntu-2204-arm' }} | |
timeout-minutes: 30 # Remove for ssh debugging | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Set platform substring | |
run: | | |
if [ "${{ inputs.arch }}" == "x86" ]; then | |
platform_substring=x86 | |
else | |
platform_substring=aarch | |
fi | |
echo "platform_substring=$platform_substring" >> $GITHUB_ENV | |
echo "Running on $platform_substring build machines" | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: us-west-2 | |
role-session-name: build-commit-workflow | |
role-to-assume: ${{ secrets.ACTIONS_AWS_ROLE_ARN }} | |
- name: Install uv, rust, python | |
uses: ./.github/actions/install | |
with: | |
python_version: ${{ inputs.python_version }} | |
- name: Restore cached build artifacts | |
uses: buildjet/cache@v4 | |
with: | |
path: ~/target/release | |
key: ${{ runner.os }}-${{ inputs.arch == 'x86' && 'x86' || 'arm' }}-cargo-deps-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: ${{ runner.os }}-${{ inputs.arch == 'x86' && 'x86' || 'arm' }}-cargo-deps- | |
- name: Setup uv environment | |
run: | | |
uv v | |
source .venv/bin/activate | |
uv pip install boto3 packaging | |
- name: Check if build already exists in AWS S3 | |
run: | | |
source .venv/bin/activate | |
wheel_name=$(python .github/ci-scripts/get_wheel_name_from_s3.py \ | |
--commit-hash "${{ github.sha }}" \ | |
--platform-substring "$platform_substring" \ | |
) | |
if [ "$wheel_name" ]; then | |
echo "Python wheel for this commit already built and uploaded" | |
else | |
echo "No python wheel for this commit found; proceeding with build" | |
fi | |
echo "wheel_name=$wheel_name" >> $GITHUB_ENV | |
- name: Build release wheel | |
run: | | |
if [ "$wheel_name" ]; then | |
echo "Python wheel for this commit already built and uploaded" | |
exit 0 | |
fi | |
export CARGO_TARGET_DIR=~/target | |
source .venv/bin/activate | |
uv pip install pip maturin boto3 | |
maturin build --release | |
- name: Upload wheel to AWS S3 | |
run: | | |
if [ "$wheel_name" ]; then | |
echo "Python wheel for this commit already built and uploaded" | |
exit 0 | |
fi | |
source .venv/bin/activate | |
wheel_name=$(python .github/ci-scripts/upload_wheel_to_s3.py \ | |
--commit-hash "${{ github.sha }}" \ | |
--platform-substring "$platform_substring" \ | |
--path-to-wheel-dir ~/target/wheels \ | |
) | |
echo "wheel_name=$wheel_name" >> $GITHUB_ENV | |
- name: Print url of the built wheel to GitHub Actions Summary Page | |
run: | | |
console_url="https://us-west-2.console.aws.amazon.com/s3/object/github-actions-artifacts-bucket?prefix=builds/${{ github.sha }}/$wheel_name" | |
download_url="https://github-actions-artifacts-bucket.s3.us-west-2.amazonaws.com/builds/${{ github.sha }}/$wheel_name" | |
echo "View the location of the built wheel in the AWS console here:" >> $GITHUB_STEP_SUMMARY | |
echo "$console_url" >> $GITHUB_STEP_SUMMARY | |
echo "Directly download the wheel here:" >> $GITHUB_STEP_SUMMARY | |
echo "$download_url" >> $GITHUB_STEP_SUMMARY |