You are reading documentation for 0.2.0. The latest release in the 0.2 line is 0.2.2.
The latest stable release is 0.8.4.
Distributed Multi-Job Builds
Why distributed mode exists
When multiple build jobs run in parallel and each publishes an independent full-cache generation, those generations diverge. Restoring only the newest one loses dependency downloads and other cache changes that exist solely in the other workers’ generations.
Distributed mode solves this with delta exchange:
- Each worker job uploads assumed changed files and path-only activity observations for aggregate partitions, plus complete snapshots for any single-writer partitions it owns. It does not write the base cache directly.
- An aggregator job, which waits for all workers to complete, downloads every delta, merges them, and saves the merged result as the new base cache entry.
Observed parallel changes in aggregate partitions are combined. Single-writer partitions use only their designated writer’s complete snapshot. On the next run, all workers start from a cache that reflects the combined output of every job from the previous run.
sequenceDiagram
participant BC as Base cache
participant WA as Worker A
participant WB as Worker B
participant AG as Aggregator
BC-->>WA: restore
BC-->>WB: restore
WA->>WA: build + compute delta
WB->>WB: build + compute delta
WA-->>AG: upload Δ-A artifact
WB-->>AG: upload Δ-B artifact
AG->>AG: download Δ-A + Δ-B
AG->>AG: merge deltas
AG->>BC: save merged cache entry
How delta exchange works
- Worker prepare restores the base and records a cutoff after its own reads/writes.
- The build runs normally.
- Worker finalize scans metadata before its own content reads and uploads selected upserts/usage. Empty observation sets still produce completion envelopes. Workers never save the base.
- Aggregate prepare validates/applies selected envelopes and retains upstream activity before C. Used-only paths do not recreate absent files.
- Aggregate finalize performs eligible GC and requires successful publication for upserts, GC removal or a nonempty miss. Usage alone does not require a generation. Fresh replay may still upload identical material again. Aggregate partitions exchange no deletion tombstones. A single-writer snapshot replaces its complete configured membership, including removals, and metadata-only changes independently require publication.
On pull-request events, read-only mode performs no exchange: workers upload nothing, and an
aggregator returns skipped-read-only without listing, downloading, validating, applying, or
deleting artifacts. This makes a static topology safe, but a workflow should avoid allocating the
aggregator runner when it can express the writable-event condition directly.
Gradle metadata writer
Gradle’s dependency-metadata partition is enabled by default and uses single-writer
publication. Choose one existing worker as its metadata writer and pass the same partition
configuration to every worker and the aggregator. The writer is identified by Mammoth’s producer
job identity, which defaults to the workflow job ID. If you set github-job-name for a matrix or
reusable workflow, use that exact identity for writer and dependent-jobs too. Matrix producers
must have distinct identities; a writer designates one producer, not the entire matrix.
Only that job’s complete configured metadata set replaces the previous snapshot. Other workers' artifact downloads still aggregate normally; their local dependency-metadata updates do not. Choose a writer whose build resolves the dependencies you want covered. Metadata learned only by other jobs may need resolution again later. A validated snapshot qualifies even if its build failed.
An aggregator can instead name itself as writer. In that case its own post-build metadata wins;
without explicitly naming it, running Gradle in the aggregator does not grant metadata ownership.
Complete workflow with an existing worker as writer
The following workflow is also available in the repository as
examples/gradle-distributed.yml. Adapt the module tasks and replace <commit-sha> with the
Mammoth version you deploy.
1name: Gradle distributed cache
2on: [push, pull_request, workflow_dispatch]
3
4permissions:
5 contents: read
6
7env:
8 MAMMOTH_CACHE_PARTITIONS: '[{"id":"dependency-metadata","writer":"worker-a"}]'
9
10jobs:
11 worker-a:
12 runs-on: ubuntu-latest
13 steps:
14 - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
15 - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
16 with:
17 distribution: temurin
18 java-version: '21'
19 - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@<commit-sha>
20 with:
21 job-mode: distributed-worker
22 cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
23 - run: ./gradlew :module-a:build
24
25 worker-b:
26 runs-on: ubuntu-latest
27 steps:
28 - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
29 - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
30 with:
31 distribution: temurin
32 java-version: '21'
33 - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@<commit-sha>
34 with:
35 job-mode: distributed-worker
36 cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
37 - run: ./gradlew :module-b:build
38
39 aggregator:
40 needs: [worker-a, worker-b]
41 if: ${{ always() && github.event_name != 'pull_request' && github.event_name != 'pull_request_target' }}
42 runs-on: ubuntu-latest
43 steps:
44 - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
45 - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
46 with:
47 distribution: temurin
48 java-version: '21'
49 - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@<commit-sha>
50 with:
51 job-mode: distributed-aggregator
52 cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
53 dependent-jobs: worker-a, worker-b
This chooses worker-a without an extra job. Because both workers are also listed in
dependent-jobs, both ordinary completion envelopes remain required. needs ensures their
post actions finish before aggregate prepare performs artifact discovery.
Optional metadata writer that can be skipped
A writer reference is optional snapshot discovery. To permit a metadata-only job to be skipped,
include it in needs for ordering, but omit it from dependent-jobs. The ordinary build worker
remains required. This example is available as examples/gradle-optional-metadata-writer.yml.
It runs a second build to populate the writer’s metadata; use an existing suitable worker when
that extra work is unnecessary.
1name: Gradle cache with optional metadata writer
2on:
3 push:
4 pull_request:
5 workflow_dispatch:
6 inputs:
7 run_metadata:
8 description: Run the metadata writer
9 type: boolean
10 default: true
11
12permissions:
13 contents: read
14
15env:
16 MAMMOTH_CACHE_PARTITIONS: '[{"id":"dependency-metadata","writer":"metadata"}]'
17
18jobs:
19 build:
20 runs-on: ubuntu-latest
21 steps:
22 - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
23 - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
24 with:
25 distribution: temurin
26 java-version: '21'
27 - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@<commit-sha>
28 with:
29 job-mode: distributed-worker
30 cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
31 - run: ./gradlew build
32
33 metadata:
34 if: ${{ github.event_name != 'pull_request' && github.event_name != 'pull_request_target' && (github.event_name != 'workflow_dispatch' || inputs.run_metadata) }}
35 runs-on: ubuntu-latest
36 steps:
37 - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
38 - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
39 with:
40 distribution: temurin
41 java-version: '21'
42 - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@<commit-sha>
43 with:
44 job-mode: distributed-worker
45 cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
46 - run: ./gradlew build
47
48 optional-aggregator:
49 needs: [build, metadata]
50 if: ${{ always() && github.event_name != 'pull_request' && github.event_name != 'pull_request_target' }}
51 runs-on: ubuntu-latest
52 steps:
53 - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
54 - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
55 with:
56 distribution: temurin
57 java-version: '21'
58 - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@<commit-sha>
59 with:
60 job-mode: distributed-aggregator
61 cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
62 dependent-jobs: build
On a manual run with run_metadata: false, the aggregator still runs and imports the required
build envelope. The missing metadata contribution leaves the previous snapshot unchanged and
produces a warning and GitHub summary entry. If no previous snapshot exists, metadata remains
absent. If the metadata job does run, only its metadata snapshot is imported; its ordinary artifact
updates are ignored because it is not in dependent-jobs.
If that job is also required for ordinary cached files, list it in dependent-jobs; skipping it
will then fail aggregation as a missing required worker. A malformed, ambiguous, corrupt, or
incompatible writer contribution fails validation rather than silently falling back. An explicit
empty snapshot is valid and clears the configured partition; it differs from an absent snapshot.
Defaults and operational behavior
With no writer configured, distributed mode preserves the previous metadata, warns, and explains how to select a writer in the GitHub summary. Configure the same writer everywhere: writer and publication policy affect the cache family, so changing them starts a cold cache. Existing cache families are cold misses after this protocol update too.
Before restore, Mammoth removes preexisting managed snapshot files, warning and recording the replacement in the summary. A miss starts those partitions empty, including on self-hosted runners and with ordinary cleanup disabled. User-excluded files survive. Explicit include/exclude overrides are allowed; their effect on Gradle’s internal metadata relationships is the user’s responsibility.
Mammoth retains authoritative snapshot bytes separately from each job’s mutable local Gradle data. Snapshot staging copies/hashes the full configured file set in standalone mode as well; distributed writers also upload complete payloads. Snapshot partitions skip Mammoth’s per-file GC. Artifact GC continues independently, so metadata can refer to evicted artifacts and offline completeness is not guaranteed. See Cache partitions and Gradle cache internals.
Maven workflow example
1jobs:
2 worker-a:
3 runs-on: ubuntu-latest
4 permissions:
5 contents: read
6 steps:
7 - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
8 - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
9 with:
10 distribution: temurin
11 java-version: '21'
12 - uses: buildish-tooling/buildish-mammoth-cache/actions/github/maven@<commit-sha>
13 with:
14 job-mode: distributed-worker
15 - run: mvn -pl module-a verify
16
17 worker-b:
18 runs-on: ubuntu-latest
19 permissions:
20 contents: read
21 steps:
22 - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
23 - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
24 with:
25 distribution: temurin
26 java-version: '21'
27 - uses: buildish-tooling/buildish-mammoth-cache/actions/github/maven@<commit-sha>
28 with:
29 job-mode: distributed-worker
30 - run: mvn -pl module-b verify
31
32 aggregator:
33 needs: [worker-a, worker-b]
34 if: ${{ always() && github.event_name != 'pull_request' && github.event_name != 'pull_request_target' }}
35 runs-on: ubuntu-latest
36 permissions:
37 contents: read
38 steps:
39 - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
40 - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
41 with:
42 distribution: temurin
43 java-version: '21'
44 - uses: buildish-tooling/buildish-mammoth-cache/actions/github/maven@<commit-sha>
45 with:
46 job-mode: distributed-aggregator
47 dependent-jobs: worker-a, worker-b
Requirements and constraints
Job names must be unique within the workflow run. Delta artifacts are identified by job name. Two worker jobs with the same name would produce the same artifact name and the aggregator would only see one of them.
The aggregator must declare needs for every consumed worker and optional metadata writer. This ensures all deltas are uploaded
before the aggregator starts and consumes them during prepare.
Choose whether aggregation should run after worker failures. Use if: always() together with
trusted event/ref conditions when you want to consume valid envelopes from failed builds or report
missing envelopes. A skipped worker or a missing post upload, including after cancellation, leaves
a required envelope absent. Pull-request aggregators may be omitted entirely; if they do run, their
read-only result is the explicit no-op described above.
Workers do not need the aggregator in their needs. Workers are independent of each other;
only the aggregator depends on all workers.
Re-runs reuse retained worker envelopes. For each worker, the aggregator selects the highest available producer attempt that is not newer than its own attempt. A full rerun uses every new worker envelope; a failed-job rerun safely mixes rerun workers with retained earlier attempts; and an aggregator-only rerun reuses retained worker envelopes. Selection never crosses workflow run IDs.
Mammoth retains worker envelopes after failed and successful aggregation, including when no new
cache generation is needed. Workers request seven days of artifact retention by default. Set
worker-artifact-retention-days on either action to request a shorter period, for example one day
to reduce artifact residence:
1- uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@<commit-sha>
2 with:
3 job-mode: distributed-worker
4 worker-artifact-retention-days: 1
Shorter retention narrows the selective or aggregator-only retry window and can require rerunning expired workers. Base cache expiry and timestamp GC are independent. Retry availability ends when the backend expires or removes the artifacts, the workflow run is deleted, or a user or administrator removes them. Repository, organization, and backend limits can shorten the requested period; availability for the full period is not guaranteed. Retention uses temporary artifact storage until removal. Temporary upload/download staging is cleaned after use. Authoritative partition snapshot transport is retained locally for publication and retries and is reset at the next prepare.
If a required envelope is missing or expired, aggregation fails with the worker name even if a base cache was restored. Rerun the affected worker and then the aggregator within the same workflow run. A fresh retry can rewrite matching worker upserts and publish another complete generation, even when resulting bytes match an earlier successful aggregate. Existing targets are not hashed to prove a no-op; remote worker envelopes remain available for recovery.
A successful writable worker always uploads one envelope. This includes workers that changed no managed cache files: their explicit empty envelope is proof of participation and is distinct from a missing or failed worker.
Sharing across Java versions, operating systems and architectures
Gradle and Maven workers can share with an aggregator using another Java version, OS or architecture when their family inputs match. Platform information remains in producer diagnostics. Same-path different contents still conflict, including Maven directory inconsistencies; equal bytes with incidental permission differences coalesce and retain executable bits from either producer.
Use a workflow input such as cache-key-prefix: project-${{ runner.os }}-${{ runner.arch }}- to
isolate platforms, or include ${{ matrix.java }} for explicit Java separation. All jobs in a sharing
group must resolve the same prefix. Gradle task inputs
must account for platform-sensitive outputs; Maven platform artifacts and environment-dependent
local installs need distinct coordinates/classifiers or explicit namespace isolation.
Using a config file
Repeat inputs can be moved to a shared config file. The file format is identical for both build tools — use the config keys matching your tool’s action.
1# .github/buildish-mammoth-gradle.yml (Gradle example)
2cache-key-prefix: my-project-gradle-
3wrapper-properties-files: gradle/wrapper/gradle-wrapper.properties
4cache-partitions:
5 - id: dependency-metadata
6 writer: worker-a
1# Each worker job
2- uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@<commit-sha>
3 with:
4 job-mode: distributed-worker
5 config-file: .github/buildish-mammoth-gradle.yml
6
7# Aggregator job
8- uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@<commit-sha>
9 with:
10 job-mode: distributed-aggregator
11 dependent-jobs: worker-a, worker-b
12 config-file: .github/buildish-mammoth-gradle.yml