-
Notifications
You must be signed in to change notification settings - Fork 44
Generate flatpakref files for addon/plugin refs during publish #161
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
Open
razzeee
wants to merge
3
commits into
flatpak:master
Choose a base branch
from
razzeee:add-flatpakref-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,22 @@ use crate::schema::*; | |
|
|
||
| use super::job_queue::queue_update_job; | ||
|
|
||
| /// We generate flatpakref files for all `app/` refs and for `runtime/` refs that represent | ||
| /// actual runtimes or addons/plugins/extensions. The sub-refs that Flatpak generates | ||
| /// automatically (`.Debug`, `.Locale`, `.Sources`, `.Docs`) are excluded because they are | ||
| /// not directly installable by end-users. | ||
| /// | ||
| /// **Both the commit job and the publish job use this predicate** to decide which refs get a | ||
| /// `.flatpakref` file. | ||
| pub fn should_generate_flatpakref(ref_name: &str) -> bool { | ||
| let unwanted_exts = [".Debug", ".Locale", ".Sources", ".Docs"]; | ||
| let ref_id = ref_name.split('/').nth(1).unwrap_or(""); | ||
|
|
||
| ref_name.starts_with("app/") | ||
| || (ref_name.starts_with("runtime/") | ||
| && !unwanted_exts.iter().any(|&ext| ref_id.ends_with(ext))) | ||
| } | ||
|
|
||
| pub fn generate_flatpakref( | ||
| ref_name: &str, | ||
| maybe_build_id: Option<i32>, | ||
|
|
@@ -23,7 +39,11 @@ pub fn generate_flatpakref( | |
| ) -> (String, String) { | ||
| let parts: Vec<&str> = ref_name.split('/').collect(); | ||
|
|
||
| let filename = format!("{}.flatpakref", parts[1]); | ||
| let filename = if parts[0] == "app" { | ||
| format!("{}.flatpakref", parts[1]) | ||
| } else { | ||
| format!("{}.{}.flatpakref", parts[1], parts[3]) | ||
| }; | ||
| let app_id = &parts[1]; | ||
| let branch = &parts[3]; | ||
|
|
||
|
|
@@ -230,3 +250,243 @@ pub fn load_build_refs(build_id: i32, conn: &mut PgConnection) -> JobResult<Vec< | |
|
|
||
| Ok(refs) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| fn make_config(base_url: &str) -> Config { | ||
| serde_json::from_str(&format!( | ||
| r#"{{ | ||
| "database-url": "postgres://example", | ||
| "secret": "c2VjcmV0", | ||
| "repos": {{}}, | ||
| "build-repo-base": "/tmp/build-repo", | ||
| "base-url": "{base_url}" | ||
| }}"# | ||
| )) | ||
| .unwrap() | ||
| } | ||
|
|
||
| fn make_repoconfig(name: &str, base_url: Option<&str>) -> RepoConfig { | ||
| let base_url_field = match base_url { | ||
| Some(u) => format!(r#""base-url": "{u}","#), | ||
| None => String::new(), | ||
| }; | ||
| let mut repo: RepoConfig = serde_json::from_str(&format!( | ||
| r#"{{ | ||
| "path": "/tmp/repo", | ||
| "subsets": {{}}, | ||
| {base_url_field} | ||
| "runtime-repo-url": null | ||
| }}"# | ||
| )) | ||
| .unwrap(); | ||
| repo.name = name.to_string(); | ||
| repo | ||
| } | ||
|
|
||
| #[test] | ||
| fn app_refs_always_get_a_flatpakref() { | ||
| assert!(should_generate_flatpakref( | ||
| "app/org.gnome.eog/x86_64/stable" | ||
| )); | ||
| assert!(should_generate_flatpakref("app/org.gnome.eog/aarch64/beta")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn plain_runtime_refs_get_a_flatpakref() { | ||
| assert!(should_generate_flatpakref( | ||
| "runtime/org.gnome.Platform/x86_64/46" | ||
| )); | ||
| } | ||
|
|
||
| #[test] | ||
| fn addon_and_plugin_refs_get_a_flatpakref() { | ||
| assert!(should_generate_flatpakref( | ||
| "runtime/org.gnome.eog.Plugin/x86_64/stable" | ||
| )); | ||
| assert!(should_generate_flatpakref( | ||
| "runtime/com.example.App.Addon/x86_64/stable" | ||
| )); | ||
| } | ||
|
|
||
| #[test] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all those tests for should_generate_flatpakref should really be merged |
||
| fn debug_extension_refs_do_not_get_a_flatpakref() { | ||
| assert!(!should_generate_flatpakref( | ||
| "runtime/org.gnome.eog.Debug/x86_64/stable" | ||
| )); | ||
| } | ||
|
|
||
| #[test] | ||
| fn locale_extension_refs_do_not_get_a_flatpakref() { | ||
| assert!(!should_generate_flatpakref( | ||
| "runtime/org.gnome.eog.Locale/x86_64/stable" | ||
| )); | ||
| } | ||
|
|
||
| #[test] | ||
| fn sources_extension_refs_do_not_get_a_flatpakref() { | ||
| assert!(!should_generate_flatpakref( | ||
| "runtime/org.gnome.eog.Sources/x86_64/stable" | ||
| )); | ||
| } | ||
|
|
||
| #[test] | ||
| fn docs_extension_refs_do_not_get_a_flatpakref() { | ||
| assert!(!should_generate_flatpakref( | ||
| "runtime/org.gnome.eog.Docs/x86_64/stable" | ||
| )); | ||
| } | ||
|
|
||
| #[test] | ||
| fn screenshot_and_appstream_refs_do_not_get_a_flatpakref() { | ||
| assert!(!should_generate_flatpakref( | ||
| "screenshots/org.gnome.eog/x86_64/stable" | ||
| )); | ||
| assert!(!should_generate_flatpakref("appstream/x86_64")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn generate_flatpakref_for_app_ref_in_main_repo() { | ||
| let config = make_config("https://dl.example.com"); | ||
| let repoconfig = make_repoconfig("stable", Some("https://dl.example.com/repo/stable")); | ||
|
|
||
| let (filename, contents) = generate_flatpakref( | ||
| "app/org.gnome.eog/x86_64/stable", | ||
| None, | ||
| &config, | ||
| &repoconfig, | ||
| ); | ||
|
|
||
| assert_eq!(filename, "org.gnome.eog.flatpakref"); | ||
| assert!(contents.contains("Name=org.gnome.eog")); | ||
| assert!(contents.contains("Branch=stable")); | ||
| assert!(contents.contains("IsRuntime=false")); | ||
| assert!(contents.contains("Url=https://dl.example.com/repo/stable")); | ||
| assert!(contents.contains("org.gnome.eog from")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn generate_flatpakref_for_app_ref_in_build_repo() { | ||
| let config = make_config("https://dl.example.com"); | ||
| let repoconfig = make_repoconfig("stable", None); | ||
|
|
||
| let (filename, contents) = generate_flatpakref( | ||
| "app/org.gnome.eog/x86_64/stable", | ||
| Some(42), | ||
| &config, | ||
| &repoconfig, | ||
| ); | ||
|
|
||
| assert_eq!(filename, "org.gnome.eog.flatpakref"); | ||
| assert!(contents.contains("IsRuntime=false")); | ||
| assert!(contents.contains("Url=https://dl.example.com/build-repo/42")); | ||
| assert!(contents.contains("Title=org.gnome.eog build nr 42")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn generate_flatpakref_for_runtime_ref_sets_is_runtime_true() { | ||
| let config = make_config("https://dl.example.com"); | ||
| let repoconfig = make_repoconfig("stable", None); | ||
|
|
||
| let (_filename, contents) = generate_flatpakref( | ||
| "runtime/org.gnome.Platform/x86_64/46", | ||
| None, | ||
| &config, | ||
| &repoconfig, | ||
| ); | ||
|
|
||
| assert!(contents.contains("IsRuntime=true")); | ||
| assert!(contents.contains("Name=org.gnome.Platform")); | ||
| assert!(contents.contains("Branch=46")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn generate_flatpakref_for_addon_ref_sets_is_runtime_true() { | ||
| let config = make_config("https://dl.example.com"); | ||
| let repoconfig = make_repoconfig("stable", None); | ||
|
|
||
| let (filename, contents) = generate_flatpakref( | ||
| "runtime/org.gnome.eog.Plugin/x86_64/stable", | ||
| None, | ||
| &config, | ||
| &repoconfig, | ||
| ); | ||
|
|
||
| assert_eq!(filename, "org.gnome.eog.Plugin.stable.flatpakref"); | ||
| assert!(contents.contains("IsRuntime=true")); | ||
| assert!(contents.contains("Name=org.gnome.eog.Plugin")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn generate_flatpakref_includes_deploy_collection_id_for_main_repo_only() { | ||
| let config = make_config("https://dl.example.com"); | ||
| let mut repoconfig = make_repoconfig("stable", None); | ||
| repoconfig.collection_id = Some("org.example.Repo".to_string()); | ||
| repoconfig.deploy_collection_id = true; | ||
|
|
||
| let (_filename, contents) = generate_flatpakref( | ||
| "app/org.gnome.eog/x86_64/stable", | ||
| None, | ||
| &config, | ||
| &repoconfig, | ||
| ); | ||
| assert!(contents.contains("DeployCollectionID=org.example.Repo")); | ||
|
|
||
| let (_filename, contents) = generate_flatpakref( | ||
| "app/org.gnome.eog/x86_64/stable", | ||
| Some(1), | ||
| &config, | ||
| &repoconfig, | ||
| ); | ||
| assert!(!contents.contains("DeployCollectionID")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn generate_flatpakref_includes_suggested_remote_name_for_main_repo_only() { | ||
| let config = make_config("https://dl.example.com"); | ||
| let mut repoconfig = make_repoconfig("stable", None); | ||
| repoconfig.suggested_repo_name = Some("flathub".to_string()); | ||
|
|
||
| let (_filename, contents) = generate_flatpakref( | ||
| "app/org.gnome.eog/x86_64/stable", | ||
| None, | ||
| &config, | ||
| &repoconfig, | ||
| ); | ||
| assert!(contents.contains("SuggestRemoteName=flathub")); | ||
| assert!(contents.contains("org.gnome.eog from flathub")); | ||
|
|
||
| let (_filename, contents) = generate_flatpakref( | ||
| "app/org.gnome.eog/x86_64/stable", | ||
| Some(7), | ||
| &config, | ||
| &repoconfig, | ||
| ); | ||
| assert!(!contents.contains("SuggestRemoteName")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn different_branches_of_same_ref_produce_distinct_filenames() { | ||
| let config = make_config("https://dl.example.com"); | ||
| let repoconfig = make_repoconfig("stable", None); | ||
|
|
||
| let (stable_filename, _) = generate_flatpakref( | ||
| "runtime/org.gnome.eog.Plugin/x86_64/stable", | ||
| None, | ||
| &config, | ||
| &repoconfig, | ||
| ); | ||
| let (beta_filename, _) = generate_flatpakref( | ||
| "runtime/org.gnome.eog.Plugin/x86_64/beta", | ||
| None, | ||
| &config, | ||
| &repoconfig, | ||
| ); | ||
|
|
||
| assert_ne!(stable_filename, beta_filename); | ||
| assert_eq!(stable_filename, "org.gnome.eog.Plugin.stable.flatpakref"); | ||
| assert_eq!(beta_filename, "org.gnome.eog.Plugin.beta.flatpakref"); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be const &[&str; 4] as those never change