|
| 1 | +name: Build a Daft commit and store the outputted wheel in AWS S3 |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + workflow_call: |
| 6 | + secrets: |
| 7 | + ACTIONS_AWS_ROLE_ARN: |
| 8 | + description: The ARN of the AWS role to assume |
| 9 | + required: true |
| 10 | + outputs: |
| 11 | + wheel: |
| 12 | + description: The wheel file that was built |
| 13 | + value: ${{ jobs.build-commit.outputs.wheel }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + build-commit: |
| 17 | + runs-on: buildjet-8vcpu-ubuntu-2004 |
| 18 | + timeout-minutes: 15 # Remove for ssh debugging |
| 19 | + permissions: |
| 20 | + id-token: write |
| 21 | + contents: read |
| 22 | + outputs: |
| 23 | + wheel: ${{ steps.upload.outputs.wheel }} |
| 24 | + steps: |
| 25 | + - name: Checkout repo |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 1 |
| 29 | + - name: Configure AWS credentials |
| 30 | + uses: aws-actions/configure-aws-credentials@v4 |
| 31 | + with: |
| 32 | + aws-region: us-west-2 |
| 33 | + role-session-name: build-commit-workflow |
| 34 | + role-to-assume: ${{ secrets.ACTIONS_AWS_ROLE_ARN }} |
| 35 | + - name: Install rust + uv + python |
| 36 | + uses: ./.github/actions/install |
| 37 | + - name: Restore cached build artifacts |
| 38 | + uses: buildjet/cache@v4 |
| 39 | + with: |
| 40 | + path: ~/target |
| 41 | + key: ${{ runner.os }}-cargo-deps-${{ hashFiles('**/Cargo.lock') }} |
| 42 | + restore-keys: ${{ runner.os }}-cargo-deps- |
| 43 | + - name: Check if build already exists in AWS S3 |
| 44 | + run: | |
| 45 | + RESULT=$(aws s3 ls s3://github-actions-artifacts-bucket/builds/${{ github.sha }}/ | wc -l) |
| 46 | + if [ "$RESULT" -gt 1 ]; then |
| 47 | + echo "Error: More than one artifact found. Failing the job." |
| 48 | + exit 1 |
| 49 | + elif [ "$RESULT" -eq 0 ]; then |
| 50 | + echo "COMMIT_BUILT=0" >> $GITHUB_ENV |
| 51 | + echo "No artifacts found; will proceed with building a new wheel" |
| 52 | + elif [ "$RESULT" -eq 1 ]; then |
| 53 | + echo "COMMIT_BUILT=1" >> $GITHUB_ENV |
| 54 | + echo "Commit already built; reusing existing wheel" |
| 55 | + fi |
| 56 | + - name: Build release wheel |
| 57 | + run: | |
| 58 | + if [ "$COMMIT_BUILT" -eq 1 ]; then |
| 59 | + echo "Commit already built" |
| 60 | + exit 0 |
| 61 | + fi |
| 62 | + export CARGO_TARGET_DIR=~/target |
| 63 | + uv v |
| 64 | + source .venv/bin/activate |
| 65 | + uv pip install pip maturin boto3 |
| 66 | + maturin build --release |
| 67 | + - name: Upload wheel to AWS S3 |
| 68 | + id: upload |
| 69 | + run: | |
| 70 | + if [ "$COMMIT_BUILT" -eq 1 ]; then |
| 71 | + echo "Commit already built" |
| 72 | + wheel=$(aws s3 ls s3://github-actions-artifacts-bucket/builds/${{ github.sha }}/ | awk '{print $4}') |
| 73 | + echo "wheel=$wheel" >> $GITHUB_OUTPUT |
| 74 | + else |
| 75 | + count=$(ls ~/target/wheels/*.whl 2> /dev/null | wc -l) |
| 76 | + if [ "$count" -gt 1 ]; then |
| 77 | + echo "Found more than 1 wheel" |
| 78 | + exit 1 |
| 79 | + elif [ "$count" -eq 0 ]; then |
| 80 | + echo "Found no wheels" |
| 81 | + exit 1 |
| 82 | + fi |
| 83 | + for file in ~/target/wheels/*.whl; do |
| 84 | + aws s3 cp $file s3://github-actions-artifacts-bucket/builds/${{ github.sha }}/ --acl public-read --no-progress; |
| 85 | + file_basename=$(basename $file) |
| 86 | + echo "wheel=$file_basename" >> $GITHUB_OUTPUT |
| 87 | + done |
| 88 | + fi |
| 89 | + echo "Output python-release-wheel location:" >> $GITHUB_STEP_SUMMARY |
| 90 | + echo "https://us-west-2.console.aws.amazon.com/s3/buckets/github-actions-artifacts-bucket?prefix=builds/${{ github.sha }}/" >> $GITHUB_STEP_SUMMARY |
0 commit comments