|
| 1 | +# Self-cached |
| 2 | + |
| 3 | +Local file caching for self-hosted GitHub Actions runners. Made specifically for macOS runners using native virtual machines with attached host volumes. |
| 4 | + |
| 5 | +- [x] Relative, absolute, and tilde path support. |
| 6 | +- [x] Multiple path caching support – cache several related paths in one step. |
| 7 | +- [x] Default cache location via `SELF_CACHED_DIR` environment variable. |
| 8 | +- [ ] Configurable cache compression for fine-tuning the performance. |
| 9 | +- [ ] Glob support – not sure how it would work, but sounds useful… |
| 10 | + |
| 11 | +## 💡 Usage |
| 12 | +This is mostly inspired by the old-good [actions/cache](https://github.com/actions/cache) action – check it out first if you're not familiar with the concepts. |
| 13 | + |
| 14 | +Here's an example of `.github/workflows/main.yml` using this action to cache different dependencies: |
| 15 | + |
| 16 | +```yaml |
| 17 | +# Can be set up globally for all jobs… |
| 18 | +# env: |
| 19 | +# SELF_CACHED_DIR: /Volumes/My Shared Files/cache |
| 20 | + |
| 21 | +jobs: |
| 22 | + main: |
| 23 | + env: |
| 24 | + # Optional cache dir to use by all steps in this job. |
| 25 | + SELF_CACHED_DIR: /Volumes/My Shared Files/cache |
| 26 | + |
| 27 | + steps: |
| 28 | + |
| 29 | + # 📦 Cache steps |
| 30 | + |
| 31 | + # Both relative and absolute paths are supported. |
| 32 | + - name: SPM cache |
| 33 | + uses: iby/self-cached@v1 |
| 34 | + id: cache-spm |
| 35 | + with: |
| 36 | + key: spm-${{ hashFiles('App.xcworkspace/xcshareddata/swiftpm/Package.resolved') }} |
| 37 | + path: deps/SPM |
| 38 | + |
| 39 | + # Multiple paths can be cached in one step. |
| 40 | + - name: FFmpeg cache |
| 41 | + uses: iby/self-cached@v1 |
| 42 | + id: cache-ffmpeg |
| 43 | + with: |
| 44 | + key: ffmpeg-${{ hashFiles('deps/FFmpeg/build.sh') }} |
| 45 | + path: | |
| 46 | + deps/FFmpeg/include |
| 47 | + deps/FFmpeg/lib |
| 48 | +
|
| 49 | + # Tilde-path expansion is supported. |
| 50 | + - name: Mint cache |
| 51 | + uses: iby/self-cached@v1 |
| 52 | + id: cache-mint |
| 53 | + with: |
| 54 | + key: mint-${{ hashFiles('Mintfile') }} |
| 55 | + path: ~/.mint |
| 56 | + |
| 57 | + # 🧩 Dependency steps – run only when no cache was restored… |
| 58 | + |
| 59 | + - name: Set up SPM |
| 60 | + if: steps.cache-spm.outputs.cache-hit != 'true' |
| 61 | + run: xcodebuild -workspace App.xcworkspace -scheme App -resolvePackageDependencies -clonedSourcePackagesDirPath deps/SPM |
| 62 | + |
| 63 | + - name: Set up FFmpeg |
| 64 | + if: steps.cache-ffmpeg.outputs.cache-hit != 'true' |
| 65 | + run: deps/FFmpeg/build.sh |
| 66 | + |
| 67 | + - name: Set up Mint |
| 68 | + if: steps.cache-mint.outputs.cache-hit != 'true' |
| 69 | + run: mint bootstrap |
| 70 | +``` |
| 71 | +
|
| 72 | +## 📥 Inputs |
| 73 | +- **`path` (required)**: Paths to cache, one per line. |
| 74 | +- **`key` (required)**: Cache key identifier. |
| 75 | +- **`dir` (optional)**: Cache directory. Defaults to `$SELF_CACHED_DIR` or `~/.self-cached`. |
| 76 | + |
| 77 | +## 📤 Outputs |
| 78 | +- **`cache-hit`:** `true` if cache was restored, `false` otherwise. |
| 79 | + |
| 80 | +## 🤔 Why another cache action? |
| 81 | +Fair question. I went through all the existing options, and they all fell short of what I wanted: |
| 82 | +- No way to toggle compression — archiving huge file sets often slows down local caching. |
| 83 | +- No tilde expansion support. |
| 84 | +- Some don't handle multiple paths. |
| 85 | +- Some silently skip restoring if the destination already exists. |
| 86 | +- Most come with cluttered, overengineered configs. |
| 87 | +- Many are just fork-copies with no meaningful differences. |
| 88 | +- And plenty are classic vibe-coded “pearls” where the author forgot to check the code… |
0 commit comments