mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
Feature/git hash (#1919)
* display git hash in marketplace show and app show. Add additional info to app show * bump marketplace lib version * disbaled links if site not provided, fix bug with license-instructions * fix import * stupid * feat: Add in the packing side git hash * chore: Remove the test that is breaking the build. Co-authored-by: Matt Hill <matthewonthemoon@gmail.com> Co-authored-by: BluJ <mogulslayer@gmail.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use nom::combinator::success;
|
||||
use sha2_old::{Digest, Sha512};
|
||||
use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt, SeekFrom};
|
||||
use tracing::instrument;
|
||||
|
||||
41
backend/src/s9pk/git_hash.rs
Normal file
41
backend/src/s9pk/git_hash.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use std::path::Path;
|
||||
|
||||
use crate::Error;
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub struct GitHash(String);
|
||||
|
||||
impl GitHash {
|
||||
pub async fn from_path(path: impl AsRef<Path>) -> Result<GitHash, Error> {
|
||||
let hash = tokio::process::Command::new("git")
|
||||
.args(["describe", "--always", "--abbrev=40", "--dirty=-modified"])
|
||||
.current_dir(path)
|
||||
.output()
|
||||
.await?;
|
||||
if !hash.status.success() {
|
||||
return Err(Error::new(
|
||||
color_eyre::eyre::eyre!("Could not get hash: {}", String::from_utf8(hash.stderr)?),
|
||||
crate::ErrorKind::Filesystem,
|
||||
));
|
||||
}
|
||||
Ok(GitHash(String::from_utf8(hash.stdout)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for GitHash {
|
||||
fn as_ref(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
// #[tokio::test]
|
||||
// async fn test_githash_for_current() {
|
||||
// let answer: GitHash = GitHash::from_path(std::env::current_dir().unwrap())
|
||||
// .await
|
||||
// .unwrap();
|
||||
// let answer_str: &str = answer.as_ref();
|
||||
// assert!(
|
||||
// !answer_str.is_empty(),
|
||||
// "Should have a hash for this current working"
|
||||
// );
|
||||
// }
|
||||
@@ -20,6 +20,8 @@ use crate::version::{Current, VersionT};
|
||||
use crate::volume::Volumes;
|
||||
use crate::Error;
|
||||
|
||||
use super::git_hash::GitHash;
|
||||
|
||||
fn current_version() -> Version {
|
||||
Current::new().semver().into()
|
||||
}
|
||||
@@ -30,6 +32,8 @@ pub struct Manifest {
|
||||
#[serde(default = "current_version")]
|
||||
pub eos_version: Version,
|
||||
pub id: PackageId,
|
||||
#[serde(default)]
|
||||
pub git_hash: Option<GitHash>,
|
||||
pub title: String,
|
||||
#[model]
|
||||
pub version: Version,
|
||||
@@ -96,6 +100,11 @@ impl Manifest {
|
||||
.chain(migrations)
|
||||
.chain(actions)
|
||||
}
|
||||
|
||||
pub fn with_git_hash(mut self, git_hash: GitHash) -> Self {
|
||||
self.git_hash = Some(git_hash);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
|
||||
@@ -12,6 +12,7 @@ use tracing::instrument;
|
||||
use crate::context::SdkContext;
|
||||
use crate::s9pk::builder::S9pkPacker;
|
||||
use crate::s9pk::docker::DockerMultiArch;
|
||||
use crate::s9pk::git_hash::GitHash;
|
||||
use crate::s9pk::manifest::Manifest;
|
||||
use crate::s9pk::reader::S9pkReader;
|
||||
use crate::util::display_none;
|
||||
@@ -22,6 +23,7 @@ use crate::{Error, ErrorKind, ResultExt};
|
||||
|
||||
pub mod builder;
|
||||
pub mod docker;
|
||||
pub mod git_hash;
|
||||
pub mod header;
|
||||
pub mod manifest;
|
||||
pub mod reader;
|
||||
@@ -56,8 +58,10 @@ pub async fn pack(#[context] ctx: SdkContext, #[arg] path: Option<PathBuf>) -> R
|
||||
crate::ErrorKind::Pack,
|
||||
));
|
||||
};
|
||||
let manifest: Manifest = serde_json::from_value(manifest_value.clone())
|
||||
.with_kind(crate::ErrorKind::Deserialization)?;
|
||||
|
||||
let manifest: Manifest = serde_json::from_value::<Manifest>(manifest_value.clone())
|
||||
.with_kind(crate::ErrorKind::Deserialization)?
|
||||
.with_git_hash(GitHash::from_path(&path).await?);
|
||||
let extra_keys =
|
||||
enumerate_extra_keys(&serde_json::to_value(&manifest).unwrap(), &manifest_value);
|
||||
for k in extra_keys {
|
||||
|
||||
Reference in New Issue
Block a user