Skip to content

Commit 0d6e454

Browse files
authored
ci: 👷 improve caching for Rust dependencies and FFmpeg in CI workflows (#168)
Signed-off-by: Onuralp SEZER <onuralp@ultralytics.com>
1 parent 635b702 commit 0d6e454

1 file changed

Lines changed: 37 additions & 6 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ jobs:
3232
- name: Set up Rust
3333
uses: dtolnay/rust-toolchain@stable
3434

35+
- name: Cache Rust dependencies
36+
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
37+
3538
- name: Format
3639
run: cargo fmt --all -- --check
3740

@@ -66,6 +69,12 @@ jobs:
6669
with:
6770
components: rustfmt, clippy
6871

72+
- name: Cache Rust dependencies
73+
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
74+
with:
75+
# Key on ffmpeg version so each container gets its own cache
76+
key: ffmpeg-${{ matrix.ffmpeg_version }}
77+
6978
- name: Clippy (annotate + video)
7079
run: cargo clippy --all --features annotate,video -- -D warnings
7180

@@ -81,11 +90,14 @@ jobs:
8190
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
8291

8392
- name: Install dependencies
84-
run: brew install ffmpeg pkg-config
93+
run: brew install ffmpeg
8594

8695
- name: Setup Rust
8796
uses: dtolnay/rust-toolchain@stable
8897

98+
- name: Cache Rust dependencies
99+
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
100+
89101
- name: Build (annotate + video features)
90102
run: cargo build --release --features "annotate,video,visualize" --bin ultralytics-inference
91103

@@ -95,29 +107,44 @@ jobs:
95107
runs-on: windows-latest
96108

97109
env:
98-
FFMPEG_DOWNLOAD_URL: https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full-shared.7z
110+
FFMPEG_VERSION: "8.1.1"
111+
FFMPEG_DOWNLOAD_URL: https://github.com/GyanD/codexffmpeg/releases/download/8.1.1/ffmpeg-8.1.1-full_build-shared.7z
99112

100113
steps:
101114
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
102115

103-
- name: Install dependencies
116+
- name: Cache FFmpeg
117+
id: cache-ffmpeg
118+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
119+
with:
120+
path: ffmpeg
121+
key: windows-ffmpeg-${{ env.FFMPEG_VERSION }}
122+
123+
- name: Download FFmpeg
124+
if: steps.cache-ffmpeg.outputs.cache-hit != 'true'
104125
run: |
105-
$VCINSTALLDIR = $(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath)
106-
Add-Content $env:GITHUB_ENV "LIBCLANG_PATH=${VCINSTALLDIR}\VC\Tools\LLVM\x64\bin"
107126
Invoke-WebRequest "${env:FFMPEG_DOWNLOAD_URL}" -OutFile ffmpeg-shared.7z
108127
7z x ffmpeg-shared.7z
109128
mkdir ffmpeg
110129
mv ffmpeg-*/* ffmpeg/
130+
131+
- name: Set FFmpeg environment variables
132+
run: |
133+
$VCINSTALLDIR = $(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath)
134+
Add-Content $env:GITHUB_ENV "LIBCLANG_PATH=${VCINSTALLDIR}\VC\Tools\LLVM\x64\bin"
111135
Add-Content $env:GITHUB_ENV "FFMPEG_DIR=${pwd}\ffmpeg"
112136
Add-Content $env:GITHUB_PATH "${pwd}\ffmpeg\bin"
113137
114138
- name: Setup Rust
115139
uses: dtolnay/rust-toolchain@stable
116140

141+
- name: Cache Rust dependencies
142+
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
143+
117144
- name: Build (annotate + video features)
118145
run: cargo build --features annotate,video
119146

120-
# Code coverage (runs on Ubuntu with FFmpeg 8 for full feature coverage)
147+
# Code coverage (runs on Ubuntu with FFmpeg dev libs for full feature coverage)
121148
coverage:
122149
name: coverage
123150
runs-on: ubuntu-latest
@@ -132,6 +159,10 @@ jobs:
132159
- name: Set up Rust
133160
uses: dtolnay/rust-toolchain@nightly
134161

162+
# Nightly toolchain version in rustc -V already gives this job a unique cache key
163+
- name: Cache Rust dependencies
164+
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
165+
135166
- name: Install cargo-llvm-cov
136167
uses: taiki-e/install-action@3235f8901fd37ffed0052b276cec25a362fb82e9 # v2.77.7
137168
with:

0 commit comments

Comments
 (0)