Add cache for tblib compilation in release workflow#86
Conversation
Co-authored-by: hugefiver <18693500+hugefiver@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds persistent caching for Docker BuildKit cache mounts to speed up compilation of the telegram-bot-api library (tblib) and Rust cargo builds in GitHub Actions. Previously, BuildKit cache mounts were not persisted across workflow runs. The change introduces the buildkit-cache-dance action to save and restore mount cache contents to GitHub Actions cache.
Key changes:
- Added cache mount IDs (
tblib-build,cargo-cache) in Dockerfile for BuildKit cache identification - Integrated
reproducible-containers/buildkit-cache-dance@v3.2.0in both release and pull-request workflows to persist cache mounts - Updated BuildKit cache scopes to be platform-specific in release workflow (
tblib-linux/amd64,tblib-linux/arm64)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Dockerfile | Added cache mount IDs to enable cache persistence for tblib build and cargo compilation stages |
| .github/workflows/release.yml | Integrated buildkit-cache-dance action to persist cache mounts with platform-specific BuildKit cache scopes |
| .github/workflows/pull-request.yml | Added buildkit-cache-dance with skip-extraction: true to read cache without writing, using hardcoded linux/amd64 scope |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| "tblib-build": "/src/build", | ||
| "cargo-cache": "/src/target" | ||
| } |
There was a problem hiding this comment.
The buildkit-cache-dance action may not automatically scope its GitHub Actions cache by platform. Since the release workflow can build for multiple platforms (linux/amd64 and linux/arm64 via workflow_dispatch), but the action configuration doesn't include platform information, there's a risk that:
- Builds for different platforms will share the same cache key
- The cache for one platform could overwrite the cache for another
- This could lead to build failures or incorrect binaries when switching platforms
Verify whether the action supports a platform-specific cache key parameter (such as cache-key, cache-source, or similar). If supported, consider adding platform scoping:
with:
cache-map: |
{
"tblib-build": "/src/build",
"cargo-cache": "/src/target"
}
cache-key: ${{ steps.meta.outputs.platform }}Alternatively, if the action doesn't support this, you may need to include the platform in the cache mount IDs themselves or verify that the action's default behavior already handles this correctly.
| } | |
| } | |
| cache-key: ${{ steps.meta.outputs.platform }} |
| cache-from: type=gha,scope=tblib-linux/amd64 | ||
| cache-to: type=gha,mode=max,scope=tblib-linux/amd64 |
There was a problem hiding this comment.
The cache scope is hardcoded to tblib-linux/amd64 but the pull-request workflow doesn't specify a platform for the build. This means:
- If no platform is specified in the build action, it will default to the runner's platform (linux/amd64 on ubuntu-latest)
- However, this is inconsistent with the release workflow which uses dynamic platform scopes based on
steps.meta.outputs.platform
While this works for the current setup, it creates a maintenance burden. If someone later decides to test multi-platform builds in PRs or if the default runner platform changes, the hardcoded scope will cause cache misses or incorrect cache usage. Consider using a dynamic approach similar to the release workflow, or add a comment explaining why this is intentionally hardcoded to linux/amd64.
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: hugefiver <18693500+hugefiver@users.noreply.github.com>
Applied the review feedback in commit 6e858e7:
|
|
@codex 仔细review这个pr |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6e858e7857
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| - name: Inject tblib cache into Docker | ||
| uses: reproducible-containers/buildkit-cache-dance@v3.2.0 | ||
| with: | ||
| cache-dir: cache-mount |
There was a problem hiding this comment.
Use the required cache-source input
Every release and PR build reaches this step, but v3.2.0's action metadata defines the required input as cache-source; cache-dir is not a supported input. Consequently GitHub Actions reports the unexpected input and cannot supply the restored cache-mount directory to the action, so the cache-dance step fails before the Docker build. Replace cache-dir with cache-source here and in pull-request.yml.
Useful? React with 👍 / 👎.
| id: cache | ||
| with: | ||
| path: cache-mount | ||
| key: buildkit-cache-${{ steps.meta.outputs.platform }}-${{ hashFiles('Dockerfile') }} |
There was a problem hiding this comment.
Invalidate the Cargo cache when dependencies change
When Cargo.lock changes without a Dockerfile edit, this key remains an exact hit; the later skip-extraction expression therefore evaluates to true, and the newly compiled /src/target contents are never saved. Because GitHub Actions caches are immutable, every subsequent release keeps restoring the pre-update target and recompiling the changed dependencies. Include hashFiles('Cargo.lock') in the primary key while retaining the existing restore prefix.
Useful? React with 👍 / 👎.
reproducible-containers/buildkit-cache-danceaction to release.yml for BuildKit cache persistenceactions/cache@v4step with platform-specific cache keys in release.ymlcache-dirparameter tobuildkit-cache-danceactionskip-extractionbased on cache hit status in release.ymlOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.