diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index c426254585..99e5c571d5 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -42,6 +42,7 @@ jobs: tests: ${{ steps.select.outputs.tests }} filter: ${{ steps.select.outputs.filter }} profile: ${{ steps.profile.outputs.profile }} + deps-profile: ${{ steps.profile.outputs.deps-profile }} steps: - name: Harden runner uses: step-security/harden-runner@v2.22.4 @@ -70,8 +71,25 @@ jobs: persist-credentials: false sparse-checkout: .config/cargo-*.toml sparse-checkout-cone-mode: false + # The macOS and Windows legs cache dependencies only, so `deps-profile` hashes only the + # settings that reach a dependency: `[profile.dev]` and `[profile.dev.package."*"]`. Every + # other override names a workspace crate (scripts/test-workspace-tests.py), so changing one + # keeps those entries, and next's runs restore main's. - id: profile - run: echo "profile=$(cat .config/cargo-dev.toml .config/cargo-ci.toml | sha256sum | cut -c1-12)" >> "$GITHUB_OUTPUT" + run: | + echo "profile=$(cat .config/cargo-dev.toml .config/cargo-ci.toml | sha256sum | cut -c1-12)" >> "$GITHUB_OUTPUT" + # An assignment, so a failure stops the step (`bash -e`) instead of naming every entry `v2-`. + deps=$(python3 -I - <<'PY' + import hashlib, json, tomllib + kept = [] + for path in (".config/cargo-dev.toml", ".config/cargo-ci.toml"): + with open(path, "rb") as file: + dev = tomllib.load(file)["profile"]["dev"] + kept.append([dev, dev.pop("package", {}).get("*", {})]) + print(hashlib.sha256(json.dumps(kept, sort_keys=True).encode()).hexdigest()[:12]) + PY + ) + echo "deps-profile=$deps" >> "$GITHUB_OUTPUT" # The Linux leg keeps the compiled workspace crates between runs (`cache-workspace-crates`): each # main run saves a rolling cache entry of its own, every run restores the newest one, and Cargo @@ -153,7 +171,8 @@ jobs: with: os: '["windows-latest","macos-latest"]' lint-cache: false - cache-version: *cache-version + # Named by the dependency settings alone (`deps-profile`), so next restores main's entries. + cache-version: v2-${{ needs.platforms.outputs.deps-profile }} timeout-minutes: *timeout tools: *tools craft-fonts-ref: *craft-fonts diff --git a/scripts/test-workspace-tests.py b/scripts/test-workspace-tests.py index 3aced9c5ca..6485e2a98a 100644 --- a/scripts/test-workspace-tests.py +++ b/scripts/test-workspace-tests.py @@ -305,9 +305,13 @@ class WorkspaceTests(unittest.TestCase): self.assertIn(" lint-command: *lint\n", source) self.assertIn(" command: *command\n", source) self.assertNotIn("windows-command", source) - # Every Workspace leg's cache entry is named after the profile overrides it was built with. + # The Linux leg's entry, which keeps workspace crates, is named after every profile override; + # the macOS and Windows legs' dependency-only entries after the settings that reach a + # dependency, so next restores main's (test_profile_overrides_name_only_workspace_members). self.assertIn("cache-version: &cache-version v2-${{ needs.platforms.outputs.profile }}\n", source) - self.assertIn(" cache-version: *cache-version\n", source) + self.assertIn(" cache-version: v2-${{ needs.platforms.outputs.deps-profile }}\n", source) + self.assertIn(" deps-profile: ${{ steps.profile.outputs.deps-profile }}\n", source) + self.assertNotIn(" cache-version: *cache-version\n", source) # Only the Linux leg keeps workspace crates; the cache budget has no room for the others. self.assertEqual(source.count("cache-workspace-crates: true"), 1) self.assertIn(" msrv:", source)