-
Notifications
You must be signed in to change notification settings - Fork 303
Plugin manager refactoring #3505
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
itowlson
merged 1 commit into
spinframework:main
from
itowlson:plugin-manager-rework-to-jolly-well-manage
May 12, 2026
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| use crate::{git::GitSource, manifest::PluginManifest}; | ||
| use anyhow::Context; | ||
| use semver::Version; | ||
| use std::path::{Path, PathBuf}; | ||
| use url::Url; | ||
|
|
||
| const SPIN_PLUGINS_REPO: &str = "https://github.com/spinframework/spin-plugins/"; | ||
|
|
||
| pub(crate) fn plugins_repo_url() -> Result<Url, url::ParseError> { | ||
| Url::parse(SPIN_PLUGINS_REPO) | ||
| } | ||
|
|
||
| /// The local clone of the spin-plugins repo. | ||
| pub struct Catalogue { | ||
| git_root: PathBuf, | ||
| manifests_root: PathBuf, | ||
| } | ||
|
|
||
| // Name of directory containing the installed manifests | ||
| const LOCAL_CATALOGUE_MANIFESTS_DIRECTORY: &str = "manifests"; | ||
|
|
||
| impl Catalogue { | ||
| pub fn new(git_root: PathBuf) -> Self { | ||
| let manifests_root = git_root.join(LOCAL_CATALOGUE_MANIFESTS_DIRECTORY); | ||
| Self { | ||
| git_root, | ||
| manifests_root, | ||
| } | ||
| } | ||
|
|
||
| pub fn manifests(&self) -> anyhow::Result<Vec<PluginManifest>> { | ||
| // Structure: | ||
| // CATALOGUE_DIR (spin/plugins/.spin-plugins/manifests) | ||
| // |- foo | ||
| // | |- foo@0.1.2.json | ||
| // | |- foo@1.2.3.json | ||
| // | |- foo.json | ||
| // |- bar | ||
| // |- bar.json | ||
| let catalogue_manifests_dir = &self.manifests_root; | ||
|
|
||
| // Catalogue directory doesn't exist so likely nothing has been installed. | ||
| if !catalogue_manifests_dir.exists() { | ||
| return Ok(Vec::new()); | ||
| } | ||
|
|
||
| let plugin_dirs = catalogue_manifests_dir | ||
| .read_dir() | ||
| .with_context(|| format!("reading manifest catalogue at {catalogue_manifests_dir:?}"))? | ||
| .filter_map(|d| d.ok()) | ||
| .map(|d| d.path()) | ||
| .filter(|p| p.is_dir()); | ||
| let manifest_paths = plugin_dirs.flat_map(|path| crate::util::json_files_in(&path)); | ||
| let manifests: Vec<_> = manifest_paths | ||
| .filter_map(|path| crate::util::try_read_manifest_from(&path)) | ||
| .collect(); | ||
| Ok(manifests) | ||
| } | ||
|
|
||
| /// Get expected path to the manifest of a plugin with a given name | ||
| /// and version within the spin-plugins repository | ||
| pub(crate) fn manifest_path( | ||
| &self, | ||
| plugin_name: &str, | ||
| plugin_version: &Option<Version>, | ||
| ) -> PathBuf { | ||
| self.manifests_root | ||
| .join(plugin_name) | ||
| .join(crate::util::manifest_file_name_version( | ||
| plugin_name, | ||
| plugin_version, | ||
| )) | ||
| } | ||
|
|
||
| /// Clones or pulls the spin-plugins repo as required. THIS IS NOT SYNCHRONISED | ||
| /// and should be used only if you know nothing else is updating the working | ||
| /// copy at the same time: generally, prefer `PluginManager::update()` which | ||
| /// checks for contention. | ||
| pub(crate) async fn fetch_from_remote(&self, repo_url: &Url) -> anyhow::Result<()> { | ||
| let git_root = &self.git_root; | ||
| let git_source = GitSource::new(repo_url, None, git_root); | ||
| if accept_as_repo(git_root) { | ||
| git_source.pull().await?; | ||
| } else { | ||
| git_source.clone_repo().await?; | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub(crate) async fn ensure_inited(&self, repo_url: &Url) -> anyhow::Result<()> { | ||
| let git_root = &self.git_root; | ||
| let git_source = GitSource::new(repo_url, None, git_root); | ||
| if !accept_as_repo(git_root) { | ||
| git_source.clone_repo().await?; | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(not(test))] | ||
| fn accept_as_repo(git_root: &Path) -> bool { | ||
| git_root.join(".git").exists() | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| fn accept_as_repo(git_root: &Path) -> bool { | ||
| git_root.join(".git").exists() || git_root.join("_spin_test_dot_git").exists() | ||
| } | ||
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
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.