[PR #2265] [MERGED] Support overwriting caches #2356

Closed
opened 2026-03-01 21:55:05 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/nektos/act/pull/2265
Author: @wolfogre
Created: 3/28/2024
Status: Merged
Merged: 3/28/2024
Merged by: @mergify[bot]

Base: masterHead: feature/flush_cache


📝 Commits (10+)

📊 Changes

3 files changed (+239 additions, -118 deletions)

View changed files

📝 pkg/artifactcache/handler.go (+80 -71)
📝 pkg/artifactcache/handler_test.go (+152 -30)
📝 pkg/artifactcache/model.go (+7 -17)

📄 Description

In the old implementation, it assumes that there will be no duplicate uploads of caches with the same key.

But in fact, some actions like actions/setup-go will do something like:

  1. Download the cache with the generated key.
  2. Add more contents to the cache dir by downloading and building.
  3. Upload the cache dir with the same key to replace the old cache.

It will result in a failure (though it will actually be ignored) with the following log:

/root/go/pkg/mod
/root/.cache/go-build
[command]/bin/tar --posix -cf cache.tgz --exclude cache.tgz -P -C /workspace/gitea/act_runner --files-from manifest.txt -z
::warning::Failed to save: {"error":"already exist"}

To support it, this PR introduces some changes.

  • Uploading caches with same key (and the version which indicates the env) will be allowed.
  • Return the latest completed one when retrieving a cache with a key.
  • The old caches with the same key will be deleted regularly, keep the latest only.

I have tested the code with a custom act_runner. It works well and is compatible with old data.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/nektos/act/pull/2265 **Author:** [@wolfogre](https://github.com/wolfogre) **Created:** 3/28/2024 **Status:** ✅ Merged **Merged:** 3/28/2024 **Merged by:** [@mergify[bot]](https://github.com/apps/mergify) **Base:** `master` ← **Head:** `feature/flush_cache` --- ### 📝 Commits (10+) - [`dc73717`](https://github.com/nektos/act/commit/dc73717294c66f1763c5ee3ab362663fc760340e) feat: support overwrite caches - [`dd3e426`](https://github.com/nektos/act/commit/dd3e426ec1c553a1b74def782bb16a57c548586e) test: fix case - [`7a70957`](https://github.com/nektos/act/commit/7a70957ba4bf22dcfd9471e15c48c5047242c145) test: fix get_with_multiple_keys - [`602323c`](https://github.com/nektos/act/commit/602323c65f1b9a2b26c7d92b7566c0170057f071) chore: use atomic.Bool - [`ec3645b`](https://github.com/nektos/act/commit/ec3645b6cea0b6863c707ca216fae7f77eb2801e) test: improve get_with_multiple_keys - [`d0b261c`](https://github.com/nektos/act/commit/d0b261ca16c4b548759dbb4d03fa5edee20046b1) chore: use ping to improve path - [`61304bf`](https://github.com/nektos/act/commit/61304bf135bce9b928675733cfb516e40ab8b743) fix: wrong CompareAndSwap - [`b29df93`](https://github.com/nektos/act/commit/b29df93d0f681ea79638f468150147582c65d937) test: TestHandler_gcCache - [`18f4ee3`](https://github.com/nektos/act/commit/18f4ee3adeaebb9b716a5f47f3e415a30c5d5395) chore: lint code - [`556fff3`](https://github.com/nektos/act/commit/556fff3b5f3b90d79f2919f8dbf7e5076db89311) chore: lint code ### 📊 Changes **3 files changed** (+239 additions, -118 deletions) <details> <summary>View changed files</summary> 📝 `pkg/artifactcache/handler.go` (+80 -71) 📝 `pkg/artifactcache/handler_test.go` (+152 -30) 📝 `pkg/artifactcache/model.go` (+7 -17) </details> ### 📄 Description In the old implementation, it assumes that there will be no duplicate uploads of caches with the same key. But in fact, some actions like `actions/setup-go` will do something like: 1. Download the cache with the generated key. 2. Add more contents to the cache dir by downloading and building. 3. Upload the cache dir with the same key to replace the old cache. It will result in a failure (though it will actually be ignored) with the following log: ``` /root/go/pkg/mod /root/.cache/go-build [command]/bin/tar --posix -cf cache.tgz --exclude cache.tgz -P -C /workspace/gitea/act_runner --files-from manifest.txt -z ::warning::Failed to save: {"error":"already exist"} ``` To support it, this PR introduces some changes. - Uploading caches with same key (and the version which indicates the env) will be allowed. - Return the latest completed one when retrieving a cache with a key. - The old caches with the same key will be deleted regularly, keep the latest only. I have tested the code with a custom act_runner. It works well and is compatible with old data. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-01 21:55:05 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#2356
No description provided.