skip repacking if snap content not changed - #6342
Conversation
Mediate creation of metadata and asset files to allow recreation of artifacts only if prime or post-prime content has changed. Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
049b0b5 to
9993fb3
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates Snapcraft’s packaging flow to avoid repacking artifacts when primed/post-prime contents haven’t meaningfully changed, by mediating generation of metadata and asset files (snap.yaml, component.yaml, manifest, hooks, GUI assets, desktop/icon handling) and relying on craft-application’s conditional repack support.
Changes:
- Upgrades craft-application/craft-providers and sets
always_repack=Falseto enable conditional repack behavior. - Refactors
snapcraft.services.package.Packageto generate package files/assets via mediated writers and change-detection (including manifest comparison that ignoressnapcraft-started-at). - Adds extensive unit tests plus a new spread test to validate “skip repack” behavior and asset/hook handling (including executability).
Reviewed changes
Copilot reviewed 11 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Locks upgraded craft-application/craft-providers versions used by the new packaging behavior. |
| pyproject.toml | Bumps craft-application dependency to enable conditional repack support. |
| snapcraft/application.py | Disables unconditional repacking via always_repack=False. |
| snapcraft/services/package.py | Core implementation of mediated metadata/assets and conditional repack change detection. |
| snapcraft/parts/setup_assets.py | Exposes asset helper functions for reuse by the package service. |
| snapcraft/parts/desktop_file.py | Adds render() to allow desktop file rewriting without immediate filesystem writes. |
| snapcraft/meta/component_yaml.py | Adds get_metadata() helper to support mediated component.yaml generation. |
| tests/unit/services/test_package.py | Adds unit coverage for mediated snap metadata/assets, manifest drift handling, and change detection. |
| tests/unit/services/test_package_components.py | Extends component packaging tests for mediated assets and hook executability. |
| tests/unit/parts/test_setup_assets.py | Updates tests to match newly exported setup-assets helper functions. |
| tests/spread/general/skip-repack/task.yaml | New spread test validating that repacking is skipped when nothing changes. |
| tests/spread/general/skip-repack/snap/snapcraft.yaml | Spread test snapcraft.yaml fixture for skip-repack scenario. |
| tests/spread/general/skip-repack/snap/icon.svg | Spread test icon fixture to trigger repacks when modified. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
…ct-contents-are-unchanged
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
…ct-contents-are-unchanged
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
There was a problem hiding this comment.
It's fairly hard to follow the changes in this file. Perhaps this is worth a live review.
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
| ) | ||
|
|
||
| @override | ||
| def pack(self, prime_dir: pathlib.Path, dest: pathlib.Path) -> list[pathlib.Path]: |
There was a problem hiding this comment.
Can we remove this old pack command now that it's been superseded by _pack()?
There was a problem hiding this comment.
Also _pack_components() is dead code too now
| for hook in hooks_project_dir.iterdir(): | ||
| meta_dir_hook = hooks_meta_dir / hook.name | ||
|
|
||
| _hardlink_or_copy(hook, meta_dir_hook) |
There was a problem hiding this comment.
This function is no longer referenced, can you drop it too?
|
|
||
| return assets | ||
|
|
||
| def _resolve_icon_asset( # noqa: PLR0911 |
There was a problem hiding this comment.
This function is a near-verbatim copy of finalize_icon() in setup_assets.py, which will be tough to keep the 2 copies in-sync. Can we extract all of resolution logic from finalize_icon into another function to cut down on the duplication?
|
|
||
| return assets | ||
|
|
||
| def _get_hook_assets( |
There was a problem hiding this comment.
I have a similar concern about maintaining duplicated code for this, _get_declared_hooks, and _validate_declared_hook_command_chains. My main concern with duplicated code is that core22 would diverge from core24+.
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
|
I think this change is too complex. I'm considering treating it as a spike and propose new PRs for each type of mediated metadata or asset file. |
…ct-contents-are-unchanged
|
Split snap.yaml creation as #6349 |
Mediate creation of metadata and asset files to only repack artifacts
if prime or post-prime contents have been changed. This includes
project or part definitions, snap metadata, manifests, hooks, and icon
and desktop files.
make lint && make test.