Skip to content

Commit

Permalink
Implement caching for unit tests .build
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM committed Sep 11, 2024
1 parent a26c6dc commit bed1899
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/swift_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
type: string
description: "The name of the workflow used for the concurrency group."
required: true
cache_key_prefix:
type: string
description: "The prefix for the cache key. If empty, caching is disabled"
default: ''
matrix_linux_command:
type: string
description: "The command of the current Swift version linux matrix job to execute."
Expand Down Expand Up @@ -71,7 +75,7 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.name }}
cancel-in-progress: true

jobs:
linux:
name: Linux (${{ matrix.swift.swift_version }})
Expand Down Expand Up @@ -108,6 +112,16 @@ jobs:
if: ${{ matrix.swift.enabled }}
# https://github.com/actions/checkout/issues/766
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}

- name: Restore .build
if: ${{ matrix.swift.enabled && (inputs.cache_key_prefix != '') }}
id: "restore-cache"
uses: actions/cache/restore@v4
with:
path: .build
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.after }}"
restore-keys: "${{ inputs.cache_key_prefix }}${{ github.event.repository.name }}-build-${{ matrix.swift.swift_version }}-${{ runner.os }}"

- name: Run matrix job
if: ${{ matrix.swift.enabled }}
env:
Expand All @@ -121,3 +135,10 @@ jobs:
run: |
apt-get -qq update && apt-get -qq -y install curl
curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-matrix-job.sh | bash
- name: Cache .build
if: ${{ matrix.swift.enabled && (inputs.cache_key_prefix != '') && (steps.restore-cache.outputs.cache-hit != 'true') }}
uses: actions/cache/save@v4
with:
path: .build
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.after }}"
3 changes: 2 additions & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ on:
type: string
description: "The arguments passed to swift test in the Linux nightly main Swift version matrix job."
default: ""

jobs:
unit-tests:
name: Unit tests
uses: ./.github/workflows/swift_matrix.yml
with:
name: "Unit tests"
cache_key_prefix: "unit-tests-"
matrix_linux_command: "swift test"
matrix_linux_5_8_enabled: ${{ inputs.linux_5_8_enabled }}
matrix_linux_5_8_command_override: "swift test ${{ inputs.linux_5_8_arguments_override }}"
Expand Down

0 comments on commit bed1899

Please sign in to comment.