-
Notifications
You must be signed in to change notification settings - Fork 788
[snap] GUI-less snap Launchpad integration #4822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
80ca577
[snap] Script generation of gui-less snapcraft
sharder996 ddaf92b
[ci] Check state of gui-less snapcraft.yaml
sharder996 5ac5f3c
[snap] Custom directory for gui-less snap
sharder996 2b7ce8c
[git] Add pre-commit hook to sync mirrored snap
sharder996 d4309f2
[docs] Add precommit install instructions
sharder996 f8d83a8
[snap] Prevent line wrapping
sharder996 41655dd
[snap] Apply code review suggestions
sharder996 4491870
[snap] Turn GUI off via cmake preset
sharder996 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
| # Regenerates packaging/gui-less/snap/snapcraft.yaml when snap/snapcraft.yaml is staged. | ||
| # Install: ln -s ../../git-hooks/pre-commit .git/hooks/pre-commit | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| if git diff --cached --name-only | grep -q "^snap/snapcraft\.yaml$"; then | ||
| REPO_ROOT="$(git rev-parse --show-toplevel)" | ||
| echo "snap/snapcraft.yaml staged — regenerating gui-less variant..." | ||
| python3 "${REPO_ROOT}/packaging/gui-less/generate-snapcraft.py" | ||
| git add "${REPO_ROOT}/packaging/gui-less/snap/snapcraft.yaml" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| pytest | ||
| ruamel.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| #!/usr/bin/env python3 | ||
| """Generates packaging/gui-less/snap/snapcraft.yaml from snap/snapcraft.yaml. | ||
| The transformations here are the authoritative definition of how the gui-less | ||
| variant differs from the main snap. | ||
|
|
||
| Usage: | ||
| ./generate-snapcraft.py # regenerate packaging/gui-less/snap/snapcraft.yaml | ||
| ./generate-snapcraft.py --check # verify it's up to date (for CI) | ||
| """ | ||
|
|
||
| import argparse | ||
| import re | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| from ruamel.yaml import YAML | ||
| from ruamel.yaml.scalarstring import LiteralScalarString | ||
|
|
||
| SCRIPT_DIR = Path(__file__).parent | ||
| INPUT = SCRIPT_DIR / "../../snap/snapcraft.yaml" | ||
| OUTPUT = SCRIPT_DIR / "snap/snapcraft.yaml" | ||
|
|
||
| MULTIPASS_SOURCE = "https://github.com/canonical/multipass.git" | ||
| HEADER = ( | ||
| "Generated by packaging/gui-less/generate-snapcraft.py — do not edit directly.\n" | ||
| "# Edit snap/snapcraft.yaml and re-run the script." | ||
| ) | ||
|
|
||
|
|
||
| def generate(input_path: Path, output_path: Path) -> None: | ||
| yaml = YAML() | ||
| yaml.preserve_quotes = True | ||
| yaml.width = 4096 | ||
|
|
||
| data = yaml.load(input_path) | ||
|
|
||
| # Add architectures for gui-less snap | ||
| data["platforms"]["s390x"] = None | ||
| data["platforms"]["ppc64el"] = None | ||
|
|
||
| # Remove the GUI app | ||
| del data["apps"]["gui"] | ||
|
|
||
| # Change multipass part to use remote git source | ||
| data["parts"]["multipass"]["source"] = MULTIPASS_SOURCE | ||
|
|
||
| # Use a CMake preset to turn off the GUI | ||
| data["parts"]["multipass"]["build-environment"].append( | ||
| {"CMAKE_PRESET": "snap-gui-less"} | ||
| ) | ||
|
|
||
| # Change glue part to clone snap-wrappers from remote git source | ||
| glue = data["parts"]["glue"] | ||
| glue["source"] = MULTIPASS_SOURCE | ||
| glue["source-type"] = "git" | ||
| glue["source-subdir"] = "snap-wrappers" | ||
|
|
||
| data.yaml_set_start_comment(HEADER) | ||
|
|
||
| with output_path.open("w") as f: | ||
| yaml.dump(data, f) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument("--check", action="store_true", help="verify the output is up to date (for CI)") | ||
| args = parser.parse_args() | ||
|
|
||
| if not INPUT.exists(): | ||
| print(f"ERROR: source file not found: {INPUT}", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| generate(INPUT.resolve(), OUTPUT.resolve()) | ||
|
|
||
| if args.check: | ||
| result = subprocess.run( | ||
| ["git", "diff", "--exit-code", "snap/snapcraft.yaml"], | ||
| cwd=SCRIPT_DIR, | ||
| ) | ||
| if result.returncode != 0: | ||
| print( | ||
| "ERROR: packaging/gui-less/snap/snapcraft.yaml is out of date.\n" | ||
| "Run packaging/gui-less/generate-snapcraft.py to update it.", | ||
| file=sys.stderr, | ||
| ) | ||
| sys.exit(1) | ||
| print("packaging/gui-less/snap/snapcraft.yaml is up to date.") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.