Skip to content

Commit e4eca65

Browse files
committed
Implement caching for unit tests .build
1 parent a26c6dc commit e4eca65

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

.github/workflows/swift_matrix.yml

+22-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
type: string
88
description: "The name of the workflow used for the concurrency group."
99
required: true
10+
cache_key_prefix:
11+
type: string
12+
description: "The prefix for the cache key. If empty, caching is disabled"
13+
default: ''
1014
matrix_linux_command:
1115
type: string
1216
description: "The command of the current Swift version linux matrix job to execute."
@@ -71,7 +75,7 @@ on:
7175
concurrency:
7276
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.name }}
7377
cancel-in-progress: true
74-
78+
7579
jobs:
7680
linux:
7781
name: Linux (${{ matrix.swift.swift_version }})
@@ -108,6 +112,16 @@ jobs:
108112
if: ${{ matrix.swift.enabled }}
109113
# https://github.com/actions/checkout/issues/766
110114
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
115+
116+
- name: Restore .build
117+
if: ${{ matrix.swift.enabled && (inputs.cache_key_prefix != '') }}
118+
id: "restore-cache"
119+
uses: actions/cache/restore@v4
120+
with:
121+
path: .build
122+
key: "${{ inputs.cache_key_prefix }}${{ github.event.repository.name }}-build-${{ matrix.swift.swift_version }}-${{ runner.os }}-${{ (github.event.pull_request.base.sha != null) && github.event.pull_request.base.sha || github.event.before }}"
123+
restore-keys: "${{ inputs.cache_key_prefix }}${{ github.event.repository.name }}-build-${{ matrix.swift.swift_version }}-${{ runner.os }}"
124+
111125
- name: Run matrix job
112126
if: ${{ matrix.swift.enabled }}
113127
env:
@@ -121,3 +135,10 @@ jobs:
121135
run: |
122136
apt-get -qq update && apt-get -qq -y install curl
123137
curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-matrix-job.sh | bash
138+
139+
- name: Cache .build
140+
if: ${{ matrix.swift.enabled && (inputs.cache_key_prefix != '') && (steps.restore-cache.outputs.cache-hit != 'true') }}
141+
uses: actions/cache/save@v4
142+
with:
143+
path: .build
144+
key: "${{ inputs.cache_key_prefix }}${{ github.event.repository.name }}-build-${{ matrix.swift.swift_version }}-${{ runner.os }}-${{ (github.event.pull_request.base.sha != null) && github.event.pull_request.base.sha || github.event.before }}"

.github/workflows/unit_tests.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ on:
4343
type: string
4444
description: "The arguments passed to swift test in the Linux nightly main Swift version matrix job."
4545
default: ""
46-
46+
4747
jobs:
4848
unit-tests:
4949
name: Unit tests
5050
uses: ./.github/workflows/swift_matrix.yml
5151
with:
5252
name: "Unit tests"
53+
cache_key_prefix: "unit-tests-"
5354
matrix_linux_command: "swift test"
5455
matrix_linux_5_8_enabled: ${{ inputs.linux_5_8_enabled }}
5556
matrix_linux_5_8_command_override: "swift test ${{ inputs.linux_5_8_arguments_override }}"

0 commit comments

Comments
 (0)