Skip to content

Commit 60ae62f

Browse files
author
Raunak Bhagat
authored
[FEAT] Build and upload to s3 builds (#3398)
# Overview New workflow to build commit and upload to AWS S3. - faster than previous - uses buildjet - utilizes build caching (from buildjet)
1 parent ec39dc0 commit 60ae62f

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

.github/actions/install/action.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Install uv, rust, and python
2+
description: Install uv, rust, and python
3+
inputs:
4+
python_version:
5+
description: The version of python to install
6+
required: false
7+
default: '3.9'
8+
runs:
9+
using: composite
10+
steps:
11+
- name: Install rust
12+
shell: bash
13+
run: |
14+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
15+
CARGO_BIN="$HOME/.cargo/bin"
16+
echo 'export PATH="$CARGO_BIN:$PATH"' >> $HOME/.bashrc
17+
echo "$CARGO_BIN" >> $GITHUB_PATH
18+
- name: Install uv
19+
shell: bash
20+
run: |
21+
curl -LsSf https://astral.sh/uv/install.sh | sh
22+
UV_BIN="$HOME/.local/bin"
23+
echo 'export PATH="$UV_BIN:$PATH"' >> $HOME/.bashrc
24+
echo "$UV_BIN" >> $GITHUB_PATH
25+
- name: Install (and pin) python version ${{ inputs.python_version }}
26+
shell: bash
27+
run: |
28+
uv python install ${{ inputs.python_version }}
29+
uv python pin ${{ inputs.python_version }}

.github/workflows/build-commit.yaml

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)