Skip to content

Commit 3641e33

Browse files
authored
[workflows] Split build and test into separate steps (#963)
1 parent 5fbfd20 commit 3641e33

File tree

4 files changed

+152
-42
lines changed

4 files changed

+152
-42
lines changed

.github/actions/build_cli_target/action.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ runs:
2929
# Install gcc-mingw-w64-x86-64 for Windows target cross-compilation
3030
sudo apt-get install -y build-essential gcc-mingw-w64-x86-64
3131
32+
- name: Cache cross binary
33+
uses: actions/cache@v4
34+
id: cache-cross
35+
with:
36+
path: ~/.cargo/bin/cross
37+
key: cross-git-latest
38+
3239
- name: Install cross
3340
shell: bash
41+
if: steps.cache-cross.outputs.cache-hit != 'true'
3442
run: cargo install cross --git https://github.com/cross-rs/cross --force
3543

3644
- name: Build CLI ${{ inputs.target }} target (Windows GNU native)

.github/actions/setup_rust_cargo/action.yaml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,5 @@ runs:
1414
with:
1515
targets: wasm32-unknown-unknown
1616

17-
- uses: actions/cache@v4
18-
with:
19-
path: |
20-
~/.cargo/bin/
21-
~/.cargo/registry/index/
22-
~/.cargo/registry/cache/
23-
~/.cargo/git/db/
24-
target/
25-
key: ${{ runner.arch }}-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
17+
- name: Cache Rust dependencies
18+
uses: Swatinem/rust-cache@v2

.github/workflows/pull_request.yml

Lines changed: 108 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,83 @@ jobs:
6868
with:
6969
lfs: "true"
7070

71-
- name: Setup Xcode 16
71+
- name: Setup Rust & Cargo
72+
uses: ./.github/actions/setup_rust_cargo
73+
74+
- name: Build darwin target
75+
uses: ./.github/actions/build_cli_macos_target
7276
if: contains(matrix.platform.os-name, 'darwin')
73-
uses: maxim-lobanov/setup-xcode@v1
7477
with:
75-
xcode-version: 16
78+
target: ${{ matrix.platform.target }}
79+
profile: release
80+
force-sentry-dev: true
81+
82+
- name: Build unix/Windows target
83+
uses: ./.github/actions/build_cli_linux_windows_target
84+
if: ${{ !contains(matrix.platform.os-name, 'darwin') }}
85+
with:
86+
target: ${{ matrix.platform.target }}
87+
profile: release
88+
force-sentry-dev: true
89+
90+
- name: Upload built binary
91+
uses: actions/upload-artifact@v4
92+
if: always()
93+
with:
94+
name: binary-${{ matrix.platform.target }}
95+
path: target/${{ matrix.platform.target }}/release/trunk-analytics-cli*
96+
retention-days: 1
97+
98+
test:
99+
name: Test for ${{ matrix.platform.target }}
100+
needs: [build_release]
101+
strategy:
102+
matrix:
103+
platform:
104+
- os-name: linux-x86_64
105+
runs-on: ubuntu-latest
106+
target: x86_64-unknown-linux-musl
107+
108+
- os-name: linux-aarch64
109+
runs-on: ubuntu-24.04-arm
110+
target: aarch64-unknown-linux-musl
111+
112+
- os-name: x86_64-darwin
113+
runs-on: macos-latest
114+
target: x86_64-apple-darwin
115+
116+
- os-name: aarch64-darwin
117+
runs-on: macos-latest
118+
target: aarch64-apple-darwin
119+
120+
- os-name: windows-x86_64
121+
runs-on: public-amd64-4xlarge-dind-germany
122+
target: x86_64-pc-windows-gnu
123+
124+
runs-on: ${{ matrix.platform.runs-on }}
125+
steps:
126+
# we've been hitting out of free space issues
127+
- name: Delete unnecessary tools folder
128+
run: rm -rf /opt/hostedtoolcache
129+
130+
- name: Install build tools (Windows and Linux build)
131+
shell: bash
132+
if: ${{ !contains(matrix.platform.os-name, 'darwin') }}
133+
run: |
134+
sudo bash -c 'cat << EOF > /etc/apt/sources.list
135+
deb http://mirror.hetzner.com/ubuntu/packages jammy main restricted universe multiverse
136+
deb http://mirror.hetzner.com/ubuntu/packages jammy-updates main restricted universe multiverse
137+
deb http://mirror.hetzner.com/ubuntu/packages jammy-backports main restricted universe multiverse
138+
deb http://mirror.hetzner.com/ubuntu/packages jammy-security main restricted universe multiverse
139+
EOF'
140+
sudo apt-get update
141+
sudo apt-get install -y git-lfs build-essential
142+
git lfs install
143+
144+
- name: Checkout
145+
uses: actions/checkout@v4
146+
with:
147+
lfs: "true"
76148

77149
- name: Setup Rust & Cargo
78150
uses: ./.github/actions/setup_rust_cargo
@@ -99,21 +171,16 @@ jobs:
99171
target: ${{ matrix.platform.target }}
100172
codecov-token: ${{ secrets.CODECOV_TOKEN }}
101173

102-
- name: Build darwin target
103-
uses: ./.github/actions/build_cli_macos_target
104-
if: contains(matrix.platform.os-name, 'darwin')
174+
- name: Download built binary
175+
uses: actions/download-artifact@v4
105176
with:
106-
target: ${{ matrix.platform.target }}
107-
profile: release
108-
force-sentry-dev: true
177+
name: binary-${{ matrix.platform.target }}
178+
path: target/${{ matrix.platform.target }}/release/
109179

110-
- name: Build unix/Windows target
111-
uses: ./.github/actions/build_cli_linux_windows_target
112-
if: ${{ !contains(matrix.platform.os-name, 'darwin') }}
113-
with:
114-
target: ${{ matrix.platform.target }}
115-
profile: release
116-
force-sentry-dev: true
180+
- name: Make binary executable
181+
shell: bash
182+
if: ${{ !contains(matrix.platform.os-name, 'windows') }}
183+
run: chmod +x target/${{ matrix.platform.target }}/release/trunk-analytics-cli
117184

118185
- name: Extract step outcome
119186
shell: bash
@@ -169,13 +236,33 @@ jobs:
169236
- name: Build workspace
170237
run: cargo build --all
171238

239+
- name: Trunk Check
240+
uses: trunk-io/trunk-action@v1
241+
with:
242+
cache: false
243+
244+
build_pyo3:
245+
name: Build context-py
246+
runs-on: ubuntu-latest
247+
248+
steps:
249+
- uses: actions/checkout@v4
250+
251+
- name: Delete huge unnecessary tools folder
252+
run: rm -rf /opt/hostedtoolcache
253+
172254
- name: Setup and build pyo3
173255
uses: ./.github/actions/setup_build_pyo3
174256

257+
build_wasm:
258+
name: Build context-js (WASM)
259+
runs-on: ubuntu-latest
260+
261+
steps:
262+
- uses: actions/checkout@v4
263+
264+
- name: Delete huge unnecessary tools folder
265+
run: rm -rf /opt/hostedtoolcache
266+
175267
- name: Setup and build wasm
176268
uses: ./.github/actions/setup_build_wasm
177-
178-
- name: Trunk Check
179-
uses: trunk-io/trunk-action@v1
180-
with:
181-
cache: false

.github/workflows/pyo3.yml

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,39 @@ jobs:
8383
with:
8484
name: wheels-linux-${{ matrix.platform.target }}
8585
path: dist
86+
87+
- name: Upload wheel package to S3
88+
uses: ./.github/actions/upload_to_s3
89+
if: "!cancelled() && github.event_name != 'pull_request'"
90+
with:
91+
bucket: ${{ secrets.S3_ASSET_BUCKET }}
92+
name: linux-${{ matrix.platform.target }}
93+
path: dist
94+
s3-flags: --recursive
95+
role-to-assume: ${{ secrets.S3_UPLOAD_ROLE_ARN }}
96+
date: ${{ needs.get-date-sha.outputs.date }}
97+
sha: ${{ needs.get-date-sha.outputs.sha }}
98+
99+
linux-pytest:
100+
needs: [linux]
101+
runs-on: ${{ matrix.platform.runner }}
102+
strategy:
103+
fail-fast: false
104+
matrix:
105+
platform:
106+
- runner: ubuntu-latest
107+
target: x86_64
108+
- runner: ubuntu-latest
109+
target: aarch64
110+
steps:
111+
- uses: actions/checkout@v4
112+
113+
- name: Download wheels
114+
uses: actions/download-artifact@v4
115+
with:
116+
name: wheels-linux-${{ matrix.platform.target }}
117+
path: dist
118+
86119
- name: pytest
87120
if: ${{ startsWith(matrix.platform.target, 'x86_64') }}
88121
shell: bash
@@ -95,6 +128,7 @@ jobs:
95128
uv pip install -r requirements-dev.txt
96129
uv pip install context-py --find-links ../dist --force-reinstall
97130
pytest --cov
131+
98132
- name: pytest
99133
if: ${{ startsWith(matrix.platform.target, 'aarch64') }}
100134
uses: uraimo/run-on-arch-action@v2
@@ -122,18 +156,6 @@ jobs:
122156
slug: trunk-io/analytics-cli
123157
directory: ./context-py
124158

125-
- name: Upload wheel package to S3
126-
uses: ./.github/actions/upload_to_s3
127-
if: "!cancelled() && github.event_name != 'pull_request'"
128-
with:
129-
bucket: ${{ secrets.S3_ASSET_BUCKET }}
130-
name: linux-${{ matrix.platform.target }}
131-
path: dist
132-
s3-flags: --recursive
133-
role-to-assume: ${{ secrets.S3_UPLOAD_ROLE_ARN }}
134-
date: ${{ needs.get-date-sha.outputs.date }}
135-
sha: ${{ needs.get-date-sha.outputs.sha }}
136-
137159
macos:
138160
needs: [get-date-sha]
139161
runs-on: ${{ matrix.platform.runner }}

0 commit comments

Comments
 (0)