-
Notifications
You must be signed in to change notification settings - Fork 174
131 lines (127 loc) · 4.53 KB
/
build-commit.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: build-commit
on:
workflow_call:
inputs:
arch:
description: The machine architecture to build for
required: true
type: string
python_version:
description: The version of Python to use
required: true
type: string
secrets:
ACTIONS_AWS_ROLE_ARN:
description: The AWS Role ARN for secrets access
required: true
outputs:
wheel_url:
description: The name of the built wheel
value: ${{ jobs.build-commit.outputs.wheel_url }}
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
outputs:
wheel_url: ${{ steps.set-wheel-name.outputs.wheel_url }}
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
id: set-wheel-name
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
echo "wheel_url=$download_url" >> $GITHUB_OUTPUT
env:
wheel_url: ${{ env.wheel_url }}