mirror of
https://github.com/CompeyDev/lune-packaging.git
synced 2025-01-09 04:09:09 +00:00
chore: setup tooling & lint codebase
This commit is contained in:
parent
1438be4231
commit
d3e948ee00
9 changed files with 312 additions and 328 deletions
11
package/action/.editorconfig
Normal file
11
package/action/.editorconfig
Normal file
|
@ -0,0 +1,11 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
indent_style = tab
|
||||
|
||||
[{*.yaml,*.yml, *.md}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
3
package/action/.vscode/extensions.json
vendored
Normal file
3
package/action/.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"recommendations": ["rust-lang.rust-analyzer", "esbenp.prettier-vscode"]
|
||||
}
|
13
package/action/.vscode/settings.json
vendored
13
package/action/.vscode/settings.json
vendored
|
@ -1,5 +1,12 @@
|
|||
{
|
||||
"rust-analyzer.linkedProjects": [
|
||||
"./Cargo.toml"
|
||||
]
|
||||
"rust-analyzer.check.command": "clippy",
|
||||
"rust-analyzer.linkedProjects": ["./Cargo.toml"],
|
||||
"editor.formatOnSave": true,
|
||||
"prettier.tabWidth": 2,
|
||||
"[json][jsonc][markdown][yaml]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[rust]": {
|
||||
"editor.defaultFormatter": "rust-lang.rust-analyzer"
|
||||
}
|
||||
}
|
5
package/action/rustfmt.toml
Normal file
5
package/action/rustfmt.toml
Normal file
|
@ -0,0 +1,5 @@
|
|||
max_width = 150
|
||||
hard_tabs = true
|
||||
#normalize_comments = false
|
||||
#match_block_trailing_comma = true
|
||||
#closure_block_indent_threshold = 1
|
|
@ -33,11 +33,7 @@ fn parse_release_data(data: &LuneReleaseData) -> LuneReleaseFetched {
|
|||
);
|
||||
|
||||
for asset in &data.assets {
|
||||
let parts = asset
|
||||
.name
|
||||
.split("-")
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<String>>();
|
||||
let parts = asset.name.split('-').map(|s| s.to_string()).collect::<Vec<String>>();
|
||||
|
||||
// [0] => always "lune"
|
||||
// [1] => version
|
||||
|
@ -50,9 +46,9 @@ fn parse_release_data(data: &LuneReleaseData) -> LuneReleaseFetched {
|
|||
"Supported platform found, overwriting `unknown` values"
|
||||
);
|
||||
|
||||
version = (&parts[1]).to_owned();
|
||||
download = (&asset.browser_download_url).to_owned();
|
||||
artifact_name = (&asset.name).to_owned();
|
||||
version = (parts[1]).to_owned();
|
||||
download = (asset.browser_download_url).to_owned();
|
||||
artifact_name = (asset.name).to_owned();
|
||||
} else {
|
||||
tracing::warn!(
|
||||
target: TARGET,
|
||||
|
@ -84,15 +80,12 @@ pub fn download_release(version: Option<String>) -> Result<(PathBuf, LuneRelease
|
|||
|
||||
parsed_release_data = LuneReleaseFetched {
|
||||
version: ver.to_string(),
|
||||
download: format!(
|
||||
"https://github.com/filiptibell/lune/releases/download/v{ver}/{artifact_name}"
|
||||
),
|
||||
download: format!("https://github.com/filiptibell/lune/releases/download/v{ver}/{artifact_name}"),
|
||||
artifact_name,
|
||||
raw: None,
|
||||
}
|
||||
} else {
|
||||
parsed_release_data =
|
||||
parse_release_data(&GitHub::new(("filiptibell", "lune")).fetch_releases()?);
|
||||
parsed_release_data = parse_release_data(&GitHub::new(("filiptibell", "lune")).fetch_releases()?);
|
||||
|
||||
tracing::info!(target: TARGET, "Received API resp and parsed release data");
|
||||
}
|
||||
|
@ -107,11 +100,7 @@ pub fn download_release(version: Option<String>) -> Result<(PathBuf, LuneRelease
|
|||
&parsed_release_data.download
|
||||
);
|
||||
|
||||
let resp = fetcher.fetch::<_, ()>(
|
||||
Method::Get,
|
||||
Url::from_str(&parsed_release_data.download.as_str())?,
|
||||
false,
|
||||
)?;
|
||||
let resp = fetcher.fetch::<_, ()>(Method::Get, Url::from_str(parsed_release_data.download.as_str())?, false)?;
|
||||
|
||||
match resp {
|
||||
FetchResult::Response(res) => {
|
||||
|
@ -123,23 +112,16 @@ pub fn download_release(version: Option<String>) -> Result<(PathBuf, LuneRelease
|
|||
|
||||
let mut zip_archive = File::create(&parsed_release_data.artifact_name)?;
|
||||
|
||||
let mut bytes = res
|
||||
.into_reader()
|
||||
.bytes()
|
||||
.map(|elem| elem.unwrap())
|
||||
.collect::<Vec<u8>>();
|
||||
let bytes = res.into_reader().bytes().map(|elem| elem.unwrap()).collect::<Vec<u8>>();
|
||||
|
||||
zip_archive.write_all(&mut bytes)?;
|
||||
zip_archive.write_all(&bytes)?;
|
||||
|
||||
tracing::info!(target: TARGET, "Successfully downloaded release");
|
||||
}
|
||||
FetchResult::Result(_) => unreachable!("Fetcher returned Result instead of Response"),
|
||||
};
|
||||
|
||||
Ok((
|
||||
PathBuf::from(&parsed_release_data.artifact_name),
|
||||
parsed_release_data,
|
||||
))
|
||||
Ok((PathBuf::from(&parsed_release_data.artifact_name), parsed_release_data))
|
||||
}
|
||||
|
||||
pub fn install_lune(lune_archive_reader: impl Read + Seek, meta: LuneReleaseFetched) -> Result<()> {
|
||||
|
@ -163,10 +145,7 @@ pub fn install_lune(lune_archive_reader: impl Read + Seek, meta: LuneReleaseFetc
|
|||
};
|
||||
|
||||
let bin_base_dir = BaseDirs::new()
|
||||
.ok_or(Error::new(
|
||||
ErrorKind::NotFound,
|
||||
"failed to create BaseDirs instance",
|
||||
))?
|
||||
.ok_or(Error::new(ErrorKind::NotFound, "failed to create BaseDirs instance"))?
|
||||
.home_dir()
|
||||
.join("bin");
|
||||
|
||||
|
|
|
@ -14,20 +14,15 @@ where
|
|||
S: Subscriber + for<'a> LookupSpan<'a>,
|
||||
N: for<'a> FormatFields<'a> + 'static,
|
||||
{
|
||||
fn format_event(
|
||||
&self,
|
||||
ctx: &FmtContext<'_, S, N>,
|
||||
mut writer: format::Writer<'_>,
|
||||
event: &Event<'_>,
|
||||
) -> fmt::Result {
|
||||
fn format_event(&self, ctx: &FmtContext<'_, S, N>, mut writer: format::Writer<'_>, event: &Event<'_>) -> fmt::Result {
|
||||
let meta = event.metadata();
|
||||
|
||||
let scope = match meta.level() {
|
||||
&Level::DEBUG => "?".purple().bold(),
|
||||
&Level::ERROR => "!".red().bold(),
|
||||
&Level::INFO => "*".green().bold(),
|
||||
&Level::TRACE => ".".white().bold(),
|
||||
&Level::WARN => "#".yellow().bold(),
|
||||
let scope = match *meta.level() {
|
||||
Level::DEBUG => "?".purple().bold(),
|
||||
Level::ERROR => "!".red().bold(),
|
||||
Level::INFO => "*".green().bold(),
|
||||
Level::TRACE => ".".white().bold(),
|
||||
Level::WARN => "#".yellow().bold(),
|
||||
};
|
||||
|
||||
let target = if meta.level() != &Level::INFO {
|
||||
|
|
|
@ -7,6 +7,7 @@ use url::Url;
|
|||
|
||||
use crate::types::LuneReleaseData;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct GitHub {
|
||||
fetcher: Fetcher,
|
||||
repository: Repository,
|
||||
|
@ -17,30 +18,24 @@ impl GitHub {
|
|||
let fetcher = Fetcher::new();
|
||||
|
||||
Self {
|
||||
fetcher: (&fetcher).to_owned(),
|
||||
fetcher: fetcher.to_owned(),
|
||||
repository: Repository::new(repo.0, repo.1, fetcher),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fetch_releases(&self) -> Result<LuneReleaseData> {
|
||||
let api_uri = Url::from_str(self.repository.api_url().as_str())?
|
||||
.join("releases/")?
|
||||
.join("latest")?;
|
||||
let api_uri = Url::from_str(self.repository.api_url().as_str())?.join("releases/")?.join("latest")?;
|
||||
|
||||
Ok(
|
||||
match self
|
||||
.fetcher
|
||||
.fetch::<_, LuneReleaseData>(Method::Get, api_uri, true)?
|
||||
{
|
||||
Ok(match self.fetcher.fetch::<_, LuneReleaseData>(Method::Get, api_uri, true)? {
|
||||
FetchResult::Result(res) => res,
|
||||
FetchResult::Response(_) => {
|
||||
unreachable!("Fetcher returned Response instead of Result")
|
||||
}
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Repository {
|
||||
fetcher: Fetcher,
|
||||
scope: String,
|
||||
|
@ -72,24 +67,23 @@ impl Repository {
|
|||
}
|
||||
|
||||
pub fn scope(&self) -> &String {
|
||||
return &self.scope;
|
||||
&self.scope
|
||||
}
|
||||
|
||||
pub fn repo(&self) -> &String {
|
||||
return &self.repo;
|
||||
&self.repo
|
||||
}
|
||||
|
||||
pub fn api_url(&self) -> String {
|
||||
return format!("https://api.github.com/repos/{}/{}/", self.scope, self.repo);
|
||||
format!("https://api.github.com/repos/{}/{}/", self.scope, self.repo)
|
||||
}
|
||||
|
||||
pub fn fetch_meta(&self) -> Result<RepositoryMeta> {
|
||||
Ok(
|
||||
match self.fetcher.fetch::<_, RepositoryMeta>(
|
||||
Method::Get,
|
||||
Url::from_str(self.api_url().as_str())?,
|
||||
true,
|
||||
)? {
|
||||
match self
|
||||
.fetcher
|
||||
.fetch::<_, RepositoryMeta>(Method::Get, Url::from_str(self.api_url().as_str())?, true)?
|
||||
{
|
||||
FetchResult::Result(deserialized) => deserialized,
|
||||
FetchResult::Response(_) => {
|
||||
unreachable!("Fetcher returned Response instead of Result")
|
||||
|
@ -111,7 +105,13 @@ pub enum Method {
|
|||
|
||||
pub enum FetchResult<D> {
|
||||
Result(D),
|
||||
Response(Response),
|
||||
Response(Box<Response>),
|
||||
}
|
||||
|
||||
impl Default for Fetcher {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Fetcher {
|
||||
|
@ -126,12 +126,7 @@ impl Fetcher {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fetch<U, D>(
|
||||
&self,
|
||||
method: Method,
|
||||
uri: U,
|
||||
to_deserialize: bool,
|
||||
) -> Result<FetchResult<D>>
|
||||
pub fn fetch<U, D>(&self, method: Method, uri: U, to_deserialize: bool) -> Result<FetchResult<D>>
|
||||
where
|
||||
U: Into<url::Url>,
|
||||
D: DeserializeOwned,
|
||||
|
@ -144,10 +139,8 @@ impl Fetcher {
|
|||
let req = self.client.request_url(method, &uri.into());
|
||||
|
||||
Ok(match to_deserialize {
|
||||
true => {
|
||||
FetchResult::Result(serde_json::from_reader::<_, D>(req.call()?.into_reader())?)
|
||||
}
|
||||
false => FetchResult::Response(req.call()?),
|
||||
true => FetchResult::Result(serde_json::from_reader::<_, D>(req.call()?.into_reader())?),
|
||||
false => FetchResult::Response(Box::new(req.call()?)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,20 +26,11 @@ fn main() {
|
|||
.event_format(LogFormatter)
|
||||
.init();
|
||||
|
||||
let (zip_path, meta) =
|
||||
download_release(version).expect_or_log("failed to download latest lune release");
|
||||
let (zip_path, meta) = download_release(version).expect_or_log("failed to download latest lune release");
|
||||
|
||||
install_lune(
|
||||
File::open(&zip_path).expect(
|
||||
format!(
|
||||
"failed to open downloaded lune release zip file @ {}",
|
||||
zip_path.to_string_lossy().to_string()
|
||||
)
|
||||
.as_str(),
|
||||
),
|
||||
File::open(&zip_path).unwrap_or_else(|_| panic!("failed to open downloaded lune release zip file @ {}", zip_path.to_string_lossy())),
|
||||
meta,
|
||||
)
|
||||
.expect_or_log(
|
||||
"failed to install lune. did we not have perms to write to the required directories?",
|
||||
);
|
||||
.expect_or_log("failed to install lune. did we not have perms to write to the required directories?");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue