Skip to content

Commit

Permalink
Fix prereleases not being installable and support .NET v1 SDKs
Browse files Browse the repository at this point in the history
  • Loading branch information
Phault committed Mar 16, 2024
1 parent 75090ca commit 9aa83c3
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 29 deletions.
95 changes: 95 additions & 0 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,98 @@ pub fn get_dotnet_root(env: &HostEnvironment) -> Result<PathBuf, Error> {
// So we need our fallback to also be a real path
.unwrap_or_else(|| env.home_dir.real_path().unwrap().join(".dotnet")))
}

/// Ancient SDK versions not available through git tags.
pub const ANCIENT_VERSIONS: &[&str] = &[
"1.0.0-preview2-003121",
"1.0.0-preview2-003131",
"1.0.0-preview2-003148",
"1.0.0-preview2-003156",
"1.0.0-preview2.1-003177",
"1.0.1",
"1.0.4",
"1.1.10",
"1.1.11",
"1.1.12",
"1.1.13",
"1.1.14",
"1.1.4",
"1.1.5",
"1.1.7",
"1.1.8",
"1.1.9",
"2.0.0",
"2.0.0-preview1-005977",
"2.0.0-preview2-006497",
"2.0.3",
"2.1.100",
"2.1.101",
"2.1.102",
"2.1.103",
"2.1.104",
"2.1.105",
"2.1.200",
"2.1.201",
"2.1.202",
"2.1.3",
"2.1.300",
"2.1.300-preview1-008174",
"2.1.300-preview2-008533",
"2.1.300-rc1-008673",
"2.1.301",
"2.1.302",
"2.1.4",
"2.1.401",
"2.1.402",
"2.1.403",
"2.1.500",
"2.1.502",
"2.1.503",
"2.1.504",
"2.1.505",
"2.1.506",
"2.1.507",
"2.1.600-preview-009426",
"2.1.602",
"2.1.603",
"2.1.604",
"2.1.607",
"2.1.700",
"2.1.701",
"2.1.801",
"2.1.802",
"2.1.803",
"2.1.804",
"2.1.805",
"2.1.806",
"2.1.807",
"2.1.808",
"2.1.809",
"2.1.810",
"2.1.811",
"2.1.812",
"2.1.813",
"2.1.814",
"2.1.815",
"2.1.816",
"2.1.818",
"2.2.100",
"2.2.100-preview1-009349",
"2.2.100-preview2-009404",
"2.2.100-preview3-009430",
"2.2.101",
"2.2.102",
"2.2.103",
"2.2.104",
"2.2.105",
"2.2.106",
"2.2.107",
"2.2.200-preview-009648",
"2.2.202",
"2.2.203",
"2.2.204",
"2.2.207",
"2.2.300",
"2.2.401",
"2.2.402",
];
45 changes: 16 additions & 29 deletions src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use extism_pdk::*;
use proto_pdk::*;

use crate::{
global_json::GlobalJson, helpers::get_dotnet_root, release_index::fetch_release_index,
global_json::GlobalJson,
helpers::{get_dotnet_root, ANCIENT_VERSIONS},
release_index::fetch_release_index,
};

#[host_fn]
Expand Down Expand Up @@ -39,39 +41,24 @@ pub fn register_tool(Json(_): Json<ToolMetadataInput>) -> FnResult<Json<ToolMeta
/// we're in wasm-land where multithreading isn't supported yet that would be very slow.
///
/// So we rely on the published git tags instead which seem to correspond very well to the `sdk.version`
/// field from the release index. A caveat being that this only covers v2+ and has some extra noise to
/// filter out.
///
/// Alternatively we could add an option to rely on the slow but reliable method.
/// field from the release index. A caveat being that this only covers v3+ and has some extra noise to
/// filter out. Versions v1-2 are therefore embedded in the source code.
#[plugin_fn]
pub fn load_versions(Json(_): Json<LoadVersionsInput>) -> FnResult<Json<LoadVersionsOutput>> {
let tags = load_git_tags("https://github.com/dotnet/sdk")?
// we previously used the dotnet/sdk repo here as it included v2, but all prerelease versions were slightly off
let versions = load_git_tags("https://github.com/dotnet/installer")?
.iter()
.filter_map(|tag| tag.strip_prefix("v"))
.filter(|tag| !tag.is_empty())
.map(|tag| tag.to_owned())
.collect::<Vec<_>>();

let mut versions = vec![];

for tag in tags {
let version = Version::parse(&tag);

match version {
Ok(v) => {
// there's a bunch of prereleases which aren't mentioned in the release index, so we filter them out
if v.pre.is_empty()
|| (v.pre.starts_with("preview") && !v.pre.ends_with("sdk"))
|| v.pre.starts_with("rc")
{
versions.push(v);
}
}
_ => {
debug!("Unable to parse tag '{tag}' as a version");
}
}
}
.chain(ANCIENT_VERSIONS.iter().copied())
.filter_map(|tag| Version::parse(&tag).ok())
.filter(|version| match &version.pre {
pre if pre.is_empty() => true,
pre if pre.starts_with("preview") && !pre.ends_with("sdk") => true,
pre if pre.starts_with("rc") => true,
_ => false,
})
.collect();

Ok(Json(LoadVersionsOutput::from_versions(versions)))
}
Expand Down

0 comments on commit 9aa83c3

Please sign in to comment.