Skip to content

Commit

Permalink
Add start of check releases script
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleHuisman committed Apr 27, 2024
1 parent 2dbc8a8 commit ba9ffe6
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["packages/*", "packages/*/example", "packages/*/tests/*"]
members = ["packages/*", "packages/*/example", "packages/*/tests/*", "scripts"]
resolver = "2"

[workspace.package]
Expand Down
16 changes: 16 additions & 0 deletions scripts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "scripts"
description = "Scripts for Rust Floating UI."
publish = false

authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true

[dependencies]
octocrab = "0.38.0"
serde.workspace = true
tokio = { version = "1.37.0", features = ["full"] }
toml = "0.8.12"
104 changes: 104 additions & 0 deletions scripts/src/bin/check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use std::{collections::HashMap, error::Error, fs};

use octocrab::models::repos::Release;
use serde::{Deserialize, Serialize};

// #[derive(Clone, Copy, Debug, PartialEq, Eq)]
// enum Package {
// Core,
// Dom,
// Leptos,
// Utils,
// }

// impl Package {
// fn upstream(&self) -> UpstreamPackage {
// match self {
// Package::Core => UpstreamPackage::Core,
// Package::Dom => UpstreamPackage::Dom,
// Package::Leptos => UpstreamPackage::Vue,
// Package::Utils => UpstreamPackage::Utils,
// }
// }
// }

#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
enum UpstreamPackage {
Core,
Dom,
Utils,
Vue,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
struct UpstreamConfig {
releases: HashMap<UpstreamPackage, String>,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let current_releases = read_current_releases()?;

println!("{:#?}", current_releases);

let new_releases = fetch_new_releases(current_releases).await?;

println!("{:#?}", new_releases);

Ok(())
}

fn read_current_releases() -> Result<HashMap<UpstreamPackage, String>, Box<dyn Error>> {
let upstream_config: UpstreamConfig = toml::from_str(&fs::read_to_string("upstream.toml")?)?;

Ok(upstream_config.releases)
}

async fn fetch_new_releases(
current_releases: HashMap<UpstreamPackage, String>,
) -> Result<HashMap<UpstreamPackage, Vec<Release>>, octocrab::Error> {
let octocrab = octocrab::instance();

let repo = octocrab.repos("floating-ui", "floating-ui");

let releases_by_package: HashMap<UpstreamPackage, Vec<Release>> = HashMap::new();
let mut releases_to_find_count = current_releases.len();

while releases_to_find_count > 0 {
let releases = repo
.releases()
.list()
.per_page(10)
.page(1u32)
.send()
.await?;

for release in releases {
if !release.tag_name.starts_with("@floating-ui/") {
continue;
}

let tag_name = &release.tag_name["@floating-ui/".len()..];
let (package_name, package_version) =
tag_name.split_at(tag_name.rfind('@').unwrap_or(tag_name.len()));

let upstream_package: Option<UpstreamPackage> = toml::from_str(package_name).ok();
if let Some(upstream_package) = upstream_package {
if current_releases
.get(&upstream_package)
.expect("Upstream package version should exist.")
== package_version
{
releases_to_find_count -= 1;
continue;
}

// TODO
// let package_releases = releases_by_package.get_mut(&upstream_package);
}
}
}

Ok(releases_by_package)
}
1 change: 1 addition & 0 deletions scripts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

5 changes: 5 additions & 0 deletions upstream.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[releases]
core = "1.5.2"
dom = "1.6.2"
utils = "0.2.0"
vue = "1.0.5"

0 comments on commit ba9ffe6

Please sign in to comment.