Skip to content

Cache .build directory for faster runtimes #13

@MahdiBM

Description

@MahdiBM

Right now Android CI is my slowest CI aside from benchmarks.

Something like this, for example, could makes things faster:

      - name: Restore .build
        if: ${{ runner.debug != '1' }}
        id: "restore-cache"
        uses: actions/cache/restore@v4
        with:
          path: .build
          key: "${{ github.event.repository.name }}-unit-tests-${{ matrix.config.mode }}-build-${{ matrix.swift.version }}-${{ matrix.macos.version }}-${{ hashFiles('./Package.resolved') }}"
          restore-keys: "${{ github.event.repository.name }}-unit-tests-${{ matrix.config.mode }}-build-${{ matrix.swift.version }}-${{ matrix.macos.version }}-"

      - name: Build ${{ github.event.repository.name }}
        run: |
          swift build \
            --build-tests \
            --enable-code-coverage \
            --explicit-target-dependency-import-check error \
            -Xswiftc -require-explicit-sendable \
            -c ${{ matrix.config.mode }}

      - name: Cache .build
        if: steps.restore-cache.outputs.cache-hit != 'true'
        uses: actions/cache/save@v4
        with:
          path: .build
          key: "${{ github.event.repository.name }}-unit-tests-${{ matrix.config.mode }}-build-${{ matrix.swift.version }}-${{ matrix.macos.version }}-${{ hashFiles('./Package.resolved') }}"

Make sure to install zstd before calling any actions/cache so the cache action automatically uses zstd instead of gzip and becomes way faster.

See my article for full info: https://swiftonserver.com/faster-github-actions-ci-for-swift-projects/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions