Skip to content

Commit 24d669b

Browse files
committed
ci(workflows): optimize GitHub Actions caching and fix macOS hashFiles bug
- Implement workaround for GitHub Actions bug (actions/runner-images#13341) affecting hashFiles on macOS - Replace manual Go caching with built-in actions/setup-go cache - Switch to specialized caching actions for Rust (Swatinem/rust-cache) - Add taiki-e/cache-cargo-install-action for cargo-c installation - Simplify step names and improve workflow readability - Calculate file hashes directly for reliable caching on macOS runners
1 parent 64505d1 commit 24d669b

2 files changed

Lines changed: 42 additions & 60 deletions

File tree

.github/workflows/ffmpeg-release.yml

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,43 +44,24 @@ jobs:
4444
exit 1
4545
fi
4646
47-
- name: Checkout code
48-
uses: actions/checkout@v6
47+
- uses: actions/checkout@v6
4948

50-
- name: Set up Go
51-
uses: actions/setup-go@v6
49+
- uses: actions/setup-go@v6
5250
with:
5351
go-version: '1.24'
52+
cache: true
5453

55-
- name: Cache Go modules and build cache
56-
uses: actions/cache@v4
57-
with:
58-
path: |
59-
~/go/pkg/mod
60-
~/.cache/go-build
61-
key: ${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('go.sum', 'go.mod') }}
62-
restore-keys: |
63-
${{ runner.os }}-${{ runner.arch }}-go-
64-
65-
- name: Install Rust toolchain
66-
uses: dtolnay/rust-toolchain@stable
54+
- uses: dtolnay/rust-toolchain@stable
6755
with:
6856
toolchain: stable
6957

70-
- name: Cache Rust cargo
71-
uses: actions/cache@v4
58+
- uses: Swatinem/rust-cache@v2
7259
with:
73-
path: |
74-
~/.cargo/bin/
75-
~/.cargo/registry/index/
76-
~/.cargo/registry/cache/
77-
~/.cargo/git/db/
78-
key: ${{ runner.os }}-${{ runner.arch }}-cargo-stable
79-
restore-keys: |
80-
${{ runner.os }}-${{ runner.arch }}-cargo-
60+
cache-bin: false
8161

82-
- name: Install cargo-c
83-
run: cargo install cargo-c
62+
- uses: taiki-e/cache-cargo-install-action@v2
63+
with:
64+
tool: cargo-c
8465

8566
- name: Install Linux dependencies
8667
if: matrix.os == 'linux'
@@ -90,11 +71,19 @@ jobs:
9071
if: matrix.os == 'darwin'
9172
run: brew update && brew install yasm autoconf ragel meson nasm automake libtool python3
9273

74+
- name: Calculate file hashes
75+
id: file-hashes
76+
run: |
77+
echo "libraries-hash=$(sha256sum internal/builder/libraries.go | cut -d' ' -f1 | head -c 8)" >> $GITHUB_OUTPUT
78+
echo "buildsystems-hash=$(sha256sum internal/builder/buildsystems.go | cut -d' ' -f1 | head -c 8)" >> $GITHUB_OUTPUT
79+
9380
- name: Cache FFmpeg source downloads
9481
uses: actions/cache@v4
9582
with:
9683
path: .build/downloads
97-
key: ${{ runner.os }}-${{ runner.arch }}-ffmpeg-downloads-${{ hashFiles('internal/builder/libraries.go') }}
84+
# Workaround for GitHub Actions bug: https://github.com/actions/runner-images/issues/13341
85+
# hashFiles() broken on macOS runners as of 2024-11-23, using calculated hash instead
86+
key: ${{ runner.os }}-${{ runner.arch }}-ffmpeg-downloads-${{ matrix.os == 'darwin' && steps.file-hashes.outputs.libraries-hash || hashFiles('internal/builder/libraries.go') }}
9887
restore-keys: |
9988
${{ runner.os }}-${{ runner.arch }}-ffmpeg-downloads-
10089
@@ -104,7 +93,9 @@ jobs:
10493
path: |
10594
.build/staging
10695
.build/build
107-
key: ${{ runner.os }}-${{ runner.arch }}-ffmpeg-deps-${{ hashFiles('internal/builder/libraries.go', 'internal/builder/buildsystems.go') }}
96+
# Workaround for GitHub Actions bug: https://github.com/actions/runner-images/issues/13341
97+
# hashFiles() broken on macOS runners as of 2024-11-23, using calculated hash instead
98+
key: ${{ runner.os }}-${{ runner.arch }}-ffmpeg-deps-${{ matrix.os == 'darwin' && format('{0}-{1}', steps.file-hashes.outputs.libraries-hash, steps.file-hashes.outputs.buildsystems-hash) || hashFiles('internal/builder/libraries.go', 'internal/builder/buildsystems.go') }}
10899
restore-keys: |
109100
${{ runner.os }}-${{ runner.arch }}-ffmpeg-deps-
110101

.github/workflows/ffmpeg-test.yml

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,43 +35,24 @@ jobs:
3535
fail-fast: false
3636

3737
steps:
38-
- name: Checkout code
39-
uses: actions/checkout@v6
38+
- uses: actions/checkout@v6
4039

41-
- name: Set up Go
42-
uses: actions/setup-go@v6
40+
- uses: actions/setup-go@v6
4341
with:
4442
go-version: '1.24'
43+
cache: true
4544

46-
- name: Cache Go modules and build cache
47-
uses: actions/cache@v4
48-
with:
49-
path: |
50-
~/go/pkg/mod
51-
~/.cache/go-build
52-
key: ${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('go.sum', 'go.mod') }}
53-
restore-keys: |
54-
${{ runner.os }}-${{ runner.arch }}-go-
55-
56-
- name: Install Rust toolchain
57-
uses: dtolnay/rust-toolchain@stable
45+
- uses: dtolnay/rust-toolchain@stable
5846
with:
5947
toolchain: stable
6048

61-
- name: Cache Rust cargo
62-
uses: actions/cache@v4
49+
- uses: Swatinem/rust-cache@v2
6350
with:
64-
path: |
65-
~/.cargo/bin/
66-
~/.cargo/registry/index/
67-
~/.cargo/registry/cache/
68-
~/.cargo/git/db/
69-
key: ${{ runner.os }}-${{ runner.arch }}-cargo-stable
70-
restore-keys: |
71-
${{ runner.os }}-${{ runner.arch }}-cargo-
51+
cache-bin: false
7252

73-
- name: Install cargo-c
74-
run: cargo install cargo-c
53+
- uses: taiki-e/cache-cargo-install-action@v2
54+
with:
55+
tool: cargo-c
7556

7657
- name: Install Linux dependencies
7758
if: matrix.os == 'linux'
@@ -81,11 +62,19 @@ jobs:
8162
if: matrix.os == 'darwin'
8263
run: brew update && brew install yasm autoconf ragel meson nasm automake libtool python3
8364

65+
- name: Calculate file hashes
66+
id: file-hashes
67+
run: |
68+
echo "libraries-hash=$(sha256sum internal/builder/libraries.go | cut -d' ' -f1 | head -c 8)" >> $GITHUB_OUTPUT
69+
echo "buildsystems-hash=$(sha256sum internal/builder/buildsystems.go | cut -d' ' -f1 | head -c 8)" >> $GITHUB_OUTPUT
70+
8471
- name: Cache FFmpeg source downloads
8572
uses: actions/cache@v4
8673
with:
8774
path: .build/downloads
88-
key: ${{ runner.os }}-${{ runner.arch }}-ffmpeg-downloads-${{ hashFiles('internal/builder/libraries.go') }}
75+
# Workaround for GitHub Actions bug: https://github.com/actions/runner-images/issues/13341
76+
# hashFiles() broken on macOS runners as of 2024-11-23, using calculated hash instead
77+
key: ${{ runner.os }}-${{ runner.arch }}-ffmpeg-downloads-${{ matrix.os == 'darwin' && steps.file-hashes.outputs.libraries-hash || hashFiles('internal/builder/libraries.go') }}
8978
restore-keys: |
9079
${{ runner.os }}-${{ runner.arch }}-ffmpeg-downloads-
9180
@@ -95,7 +84,9 @@ jobs:
9584
path: |
9685
.build/staging
9786
.build/build
98-
key: ${{ runner.os }}-${{ runner.arch }}-ffmpeg-deps-${{ hashFiles('internal/builder/libraries.go', 'internal/builder/buildsystems.go') }}
87+
# Workaround for GitHub Actions bug: https://github.com/actions/runner-images/issues/13341
88+
# hashFiles() broken on macOS runners as of 2024-11-23, using calculated hash instead
89+
key: ${{ runner.os }}-${{ runner.arch }}-ffmpeg-deps-${{ matrix.os == 'darwin' && format('{0}-{1}', steps.file-hashes.outputs.libraries-hash, steps.file-hashes.outputs.buildsystems-hash) || hashFiles('internal/builder/libraries.go', 'internal/builder/buildsystems.go') }}
9990
restore-keys: |
10091
${{ runner.os }}-${{ runner.arch }}-ffmpeg-deps-
10192

0 commit comments

Comments
 (0)